Skip to content

Commit ec14017

Browse files
committed
Rename type name getters (#957)
* Rename DiskTypeId.diskType() to type() * Rename MachineTypeId.machineType() to type()
1 parent a71d83b commit ec14017

12 files changed

Lines changed: 75 additions & 76 deletions

File tree

gcloud-java-compute/src/main/java/com/google/gcloud/compute/ComputeImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ public DiskType getDiskType(final DiskTypeId diskTypeId, DiskTypeOption... optio
427427
runWithRetries(new Callable<com.google.api.services.compute.model.DiskType>() {
428428
@Override
429429
public com.google.api.services.compute.model.DiskType call() {
430-
return computeRpc.getDiskType(diskTypeId.zone(), diskTypeId.diskType(), optionsMap);
430+
return computeRpc.getDiskType(diskTypeId.zone(), diskTypeId.type(), optionsMap);
431431
}
432432
}, options().retryParams(), EXCEPTION_HANDLER);
433433
return answer == null ? null : DiskType.fromPb(answer);
@@ -515,8 +515,7 @@ public MachineType getMachineType(final MachineTypeId machineType, MachineTypeOp
515515
runWithRetries(new Callable<com.google.api.services.compute.model.MachineType>() {
516516
@Override
517517
public com.google.api.services.compute.model.MachineType call() {
518-
return computeRpc.getMachineType(machineType.zone(), machineType.machineType(),
519-
optionsMap);
518+
return computeRpc.getMachineType(machineType.zone(), machineType.type(), optionsMap);
520519
}
521520
}, options().retryParams(), EXCEPTION_HANDLER);
522521
return answer == null ? null : MachineType.fromPb(answer);

gcloud-java-compute/src/main/java/com/google/gcloud/compute/DiskTypeId.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ public String apply(DiskTypeId diskTypeId) {
4848
private static final long serialVersionUID = 7337881474103686219L;
4949

5050
private final String zone;
51-
private final String diskType;
51+
private final String type;
5252

53-
private DiskTypeId(String project, String zone, String diskType) {
53+
private DiskTypeId(String project, String zone, String type) {
5454
super(project);
5555
this.zone = checkNotNull(zone);
56-
this.diskType = checkNotNull(diskType);
56+
this.type = checkNotNull(type);
5757
}
5858

5959
/**
6060
* Returns the name of the disk type.
6161
*/
62-
public String diskType() {
63-
return diskType;
62+
public String type() {
63+
return type;
6464
}
6565

6666
/**
@@ -79,17 +79,17 @@ public ZoneId zoneId() {
7979

8080
@Override
8181
public String selfLink() {
82-
return super.selfLink() + "/zones/" + zone + "/diskTypes/" + diskType;
82+
return super.selfLink() + "/zones/" + zone + "/diskTypes/" + type;
8383
}
8484

8585
@Override
8686
MoreObjects.ToStringHelper toStringHelper() {
87-
return super.toStringHelper().add("zone", zone).add("diskType", diskType);
87+
return super.toStringHelper().add("zone", zone).add("type", type);
8888
}
8989

9090
@Override
9191
public int hashCode() {
92-
return Objects.hash(super.baseHashCode(), zone, diskType);
92+
return Objects.hash(super.baseHashCode(), zone, type);
9393
}
9494

9595
@Override
@@ -103,36 +103,36 @@ public boolean equals(Object obj) {
103103
DiskTypeId other = (DiskTypeId) obj;
104104
return baseEquals(other)
105105
&& Objects.equals(zone, other.zone)
106-
&& Objects.equals(diskType, other.diskType);
106+
&& Objects.equals(type, other.type);
107107
}
108108

109109
@Override
110110
DiskTypeId setProjectId(String projectId) {
111111
if (project() != null) {
112112
return this;
113113
}
114-
return DiskTypeId.of(projectId, zone, diskType);
114+
return DiskTypeId.of(projectId, zone, type);
115115
}
116116

117117
/**
118118
* Returns a disk type identity given the zone identity and the disk type name.
119119
*/
120-
public static DiskTypeId of(ZoneId zoneId, String diskType) {
121-
return new DiskTypeId(zoneId.project(), zoneId.zone(), diskType);
120+
public static DiskTypeId of(ZoneId zoneId, String type) {
121+
return new DiskTypeId(zoneId.project(), zoneId.zone(), type);
122122
}
123123

124124
/**
125125
* Returns a disk type identity given the zone and disk type names.
126126
*/
127-
public static DiskTypeId of(String zone, String diskType) {
128-
return of(ZoneId.of(null, zone), diskType);
127+
public static DiskTypeId of(String zone, String type) {
128+
return of(ZoneId.of(null, zone), type);
129129
}
130130

131131
/**
132132
* Returns a disk type identity given project disk, zone and disk type names.
133133
*/
134-
public static DiskTypeId of(String project, String zone, String diskType) {
135-
return of(ZoneId.of(project, zone), diskType);
134+
public static DiskTypeId of(String project, String zone, String type) {
135+
return of(ZoneId.of(project, zone), type);
136136
}
137137

138138
/**

gcloud-java-compute/src/main/java/com/google/gcloud/compute/MachineType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ com.google.api.services.compute.model.MachineType toPb() {
260260
if (creationTimestamp != null) {
261261
machineTypePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
262262
}
263-
machineTypePb.setName(machineTypeId.machineType());
263+
machineTypePb.setName(machineTypeId.type());
264264
machineTypePb.setDescription(description);
265265
machineTypePb.setSelfLink(machineTypeId.selfLink());
266266
machineTypePb.setGuestCpus(cpus);

gcloud-java-compute/src/main/java/com/google/gcloud/compute/MachineTypeId.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ public String apply(MachineTypeId machineTypeId) {
5050
private static final long serialVersionUID = -5819598544478859608L;
5151

5252
private final String zone;
53-
private final String machineType;
53+
private final String type;
5454

55-
private MachineTypeId(String project, String zone, String machineType) {
55+
private MachineTypeId(String project, String zone, String type) {
5656
super(project);
5757
this.zone = checkNotNull(zone);
58-
this.machineType = checkNotNull(machineType);
58+
this.type = checkNotNull(type);
5959
}
6060

6161
/**
6262
* Returns the name of the machine type.
6363
*/
64-
public String machineType() {
65-
return machineType;
64+
public String type() {
65+
return type;
6666
}
6767

6868
/**
@@ -81,17 +81,17 @@ public ZoneId zoneId() {
8181

8282
@Override
8383
public String selfLink() {
84-
return super.selfLink() + "/zones/" + zone + "/machineTypes/" + machineType;
84+
return super.selfLink() + "/zones/" + zone + "/machineTypes/" + type;
8585
}
8686

8787
@Override
8888
MoreObjects.ToStringHelper toStringHelper() {
89-
return super.toStringHelper().add("zone", zone).add("machineType", machineType);
89+
return super.toStringHelper().add("zone", zone).add("type", type);
9090
}
9191

9292
@Override
9393
public int hashCode() {
94-
return Objects.hash(baseHashCode(), zone, machineType);
94+
return Objects.hash(baseHashCode(), zone, type);
9595
}
9696

9797
@Override
@@ -105,29 +105,29 @@ public boolean equals(Object obj) {
105105
MachineTypeId other = (MachineTypeId) obj;
106106
return baseEquals(other)
107107
&& Objects.equals(zone, other.zone)
108-
&& Objects.equals(machineType, other.machineType);
108+
&& Objects.equals(type, other.type);
109109
}
110110

111111
@Override
112112
MachineTypeId setProjectId(String projectId) {
113113
if (project() != null) {
114114
return this;
115115
}
116-
return MachineTypeId.of(projectId, zone, machineType);
116+
return MachineTypeId.of(projectId, zone, type);
117117
}
118118

119119
/**
120120
* Returns a machine type identity given the zone and type names.
121121
*/
122-
public static MachineTypeId of(String zone, String machineType) {
123-
return new MachineTypeId(null, zone, machineType);
122+
public static MachineTypeId of(String zone, String type) {
123+
return new MachineTypeId(null, zone, type);
124124
}
125125

126126
/**
127127
* Returns a machine type identity given project, zone and type names.
128128
*/
129-
public static MachineTypeId of(String project, String zone, String machineType) {
130-
return new MachineTypeId(project, zone, machineType);
129+
public static MachineTypeId of(String project, String zone, String type) {
130+
return new MachineTypeId(project, zone, type);
131131
}
132132

133133
/**

gcloud-java-compute/src/test/java/com/google/gcloud/compute/ComputeImplTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -561,28 +561,28 @@ public void testGetOptions() {
561561
@Test
562562
public void testGetDiskType() {
563563
EasyMock.expect(
564-
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
564+
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
565565
.andReturn(DISK_TYPE.toPb());
566566
EasyMock.replay(computeRpcMock);
567567
compute = options.service();
568-
DiskType diskType = compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType());
568+
DiskType diskType = compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type());
569569
assertEquals(DISK_TYPE, diskType);
570570
}
571571

572572
@Test
573573
public void testGetDiskType_Null() {
574574
EasyMock.expect(
575-
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
575+
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
576576
.andReturn(null);
577577
EasyMock.replay(computeRpcMock);
578578
compute = options.service();
579-
assertNull(compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType()));
579+
assertNull(compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type()));
580580
}
581581

582582
@Test
583583
public void testGetDiskTypeFromDiskTypeId() {
584584
EasyMock.expect(
585-
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
585+
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
586586
.andReturn(DISK_TYPE.toPb());
587587
EasyMock.replay(computeRpcMock);
588588
compute = options.service();
@@ -595,12 +595,12 @@ public void testGetDiskTypeWithSelectedFields() {
595595
Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
596596
EasyMock.expect(
597597
computeRpcMock.getDiskType(
598-
eq(DISK_TYPE_ID.zone()), eq(DISK_TYPE_ID.diskType()), capture(capturedOptions)))
598+
eq(DISK_TYPE_ID.zone()), eq(DISK_TYPE_ID.type()), capture(capturedOptions)))
599599
.andReturn(DISK_TYPE.toPb());
600600
EasyMock.replay(computeRpcMock);
601601
compute = options.service();
602602
DiskType diskType =
603-
compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), DISK_TYPE_OPTION_FIELDS);
603+
compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), DISK_TYPE_OPTION_FIELDS);
604604
String selector = (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.rpcOption());
605605
assertTrue(selector.contains("selfLink"));
606606
assertTrue(selector.contains("id"));
@@ -748,30 +748,30 @@ public void testAggregatedListDiskTypesWithOptions() {
748748
public void testGetMachineType() {
749749
EasyMock.expect(
750750
computeRpcMock.getMachineType(
751-
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
751+
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
752752
.andReturn(MACHINE_TYPE.toPb());
753753
EasyMock.replay(computeRpcMock);
754754
compute = options.service();
755755
MachineType machineType =
756-
compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType());
756+
compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type());
757757
assertEquals(MACHINE_TYPE, machineType);
758758
}
759759

760760
@Test
761761
public void testGetMachineType_Null() {
762762
EasyMock.expect(
763763
computeRpcMock.getMachineType(
764-
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
764+
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
765765
.andReturn(null);
766766
EasyMock.replay(computeRpcMock);
767767
compute = options.service();
768-
assertNull(compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType()));
768+
assertNull(compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type()));
769769
}
770770

771771
@Test
772772
public void testGetMachineTypeFromMachineTypeId() {
773773
EasyMock.expect(computeRpcMock.getMachineType(
774-
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
774+
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
775775
.andReturn(MACHINE_TYPE.toPb());
776776
EasyMock.replay(computeRpcMock);
777777
compute = options.service();
@@ -783,13 +783,13 @@ public void testGetMachineTypeFromMachineTypeId() {
783783
public void testGetMachineTypeWithSelectedFields() {
784784
Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
785785
EasyMock.expect(
786-
computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.zone()), eq(MACHINE_TYPE_ID.machineType()),
786+
computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.zone()), eq(MACHINE_TYPE_ID.type()),
787787
capture(capturedOptions)))
788788
.andReturn(MACHINE_TYPE.toPb());
789789
EasyMock.replay(computeRpcMock);
790790
compute = options.service();
791791
MachineType machineType = compute.getMachineType(MACHINE_TYPE_ID.zone(),
792-
MACHINE_TYPE_ID.machineType(), MACHINE_TYPE_OPTION_FIELDS);
792+
MACHINE_TYPE_ID.type(), MACHINE_TYPE_OPTION_FIELDS);
793793
String selector = (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.rpcOption());
794794
assertTrue(selector.contains("selfLink"));
795795
assertTrue(selector.contains("id"));
@@ -3169,7 +3169,7 @@ public void testCreateNetworkWithOptions() {
31693169
@Test
31703170
public void testRetryableException() {
31713171
EasyMock.expect(
3172-
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
3172+
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
31733173
.andThrow(new ComputeException(500, "InternalError"))
31743174
.andReturn(DISK_TYPE.toPb());
31753175
EasyMock.replay(computeRpcMock);
@@ -3182,7 +3182,7 @@ public void testRetryableException() {
31823182
public void testNonRetryableException() {
31833183
String exceptionMessage = "Not Implemented";
31843184
EasyMock.expect(
3185-
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
3185+
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
31863186
.andThrow(new ComputeException(501, exceptionMessage));
31873187
EasyMock.replay(computeRpcMock);
31883188
compute = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service();
@@ -3195,7 +3195,7 @@ public void testNonRetryableException() {
31953195
public void testRuntimeException() {
31963196
String exceptionMessage = "Artificial runtime exception";
31973197
EasyMock.expect(
3198-
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
3198+
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
31993199
.andThrow(new RuntimeException(exceptionMessage));
32003200
EasyMock.replay(computeRpcMock);
32013201
compute = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service();

gcloud-java-compute/src/test/java/com/google/gcloud/compute/DiskInfoTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ public void testToAndFromPb() {
224224
@Test
225225
public void testSetProjectId() {
226226
StandardDiskConfiguration standardDiskConfiguration = DISK_CONFIGURATION.toBuilder()
227-
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.diskType()))
227+
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.type()))
228228
.build();
229229
DiskInfo diskInfo = DISK_INFO.toBuilder()
230230
.diskId(DiskId.of(DISK_ID.zone(), DISK_ID.disk()))
231231
.configuration(standardDiskConfiguration)
232232
.build();
233233
compareDiskInfo(DISK_INFO, diskInfo.setProjectId("project"));
234234
SnapshotDiskConfiguration snapshotDiskConfiguration = SNAPSHOT_DISK_CONFIGURATION.toBuilder()
235-
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.diskType()))
235+
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.type()))
236236
.sourceSnapshot(SnapshotId.of(SNAPSHOT.snapshot()))
237237
.build();
238238
diskInfo = SNAPSHOT_DISK_INFO.toBuilder()
@@ -241,7 +241,7 @@ public void testSetProjectId() {
241241
.build();
242242
compareDiskInfo(SNAPSHOT_DISK_INFO, diskInfo.setProjectId("project"));
243243
ImageDiskConfiguration imageDiskConfiguration = IMAGE_DISK_CONFIGURATION.toBuilder()
244-
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.diskType()))
244+
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.type()))
245245
.sourceImage(ImageId.of(IMAGE.image()))
246246
.build();
247247
diskInfo = IMAGE_DISK_INFO.toBuilder()

gcloud-java-compute/src/test/java/com/google/gcloud/compute/DiskTypeIdTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public void testOf() {
4242
DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE);
4343
assertEquals(PROJECT, diskTypeId.project());
4444
assertEquals(ZONE, diskTypeId.zone());
45-
assertEquals(DISK_TYPE, diskTypeId.diskType());
45+
assertEquals(DISK_TYPE, diskTypeId.type());
4646
assertEquals(URL, diskTypeId.selfLink());
4747
diskTypeId = DiskTypeId.of(ZONE, DISK_TYPE);
4848
assertNull(diskTypeId.project());
4949
assertEquals(ZONE, diskTypeId.zone());
50-
assertEquals(DISK_TYPE, diskTypeId.diskType());
50+
assertEquals(DISK_TYPE, diskTypeId.type());
5151
}
5252

5353
@Test
@@ -77,7 +77,7 @@ private void compareDiskTypeId(DiskTypeId expected, DiskTypeId value) {
7777
assertEquals(expected, value);
7878
assertEquals(expected.project(), expected.project());
7979
assertEquals(expected.zone(), expected.zone());
80-
assertEquals(expected.diskType(), expected.diskType());
80+
assertEquals(expected.type(), expected.type());
8181
assertEquals(expected.selfLink(), expected.selfLink());
8282
assertEquals(expected.hashCode(), expected.hashCode());
8383
}

gcloud-java-compute/src/test/java/com/google/gcloud/compute/ImageDiskConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testOf() {
9393
@Test
9494
public void testSetProjectId() {
9595
ImageDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder()
96-
.diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.diskType()))
96+
.diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.type()))
9797
.sourceImage(ImageId.of(IMAGE.image()))
9898
.build();
9999
compareImageDiskConfiguration(DISK_CONFIGURATION, diskConfiguration.setProjectId("project"));

0 commit comments

Comments
 (0)