Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename type name getters #957

Merged
merged 2 commits into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public DiskType getDiskType(final DiskTypeId diskTypeId, DiskTypeOption... optio
runWithRetries(new Callable<com.google.api.services.compute.model.DiskType>() {
@Override
public com.google.api.services.compute.model.DiskType call() {
return computeRpc.getDiskType(diskTypeId.zone(), diskTypeId.diskType(), optionsMap);
return computeRpc.getDiskType(diskTypeId.zone(), diskTypeId.type(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : DiskType.fromPb(answer);
Expand Down Expand Up @@ -515,8 +515,7 @@ public MachineType getMachineType(final MachineTypeId machineType, MachineTypeOp
runWithRetries(new Callable<com.google.api.services.compute.model.MachineType>() {
@Override
public com.google.api.services.compute.model.MachineType call() {
return computeRpc.getMachineType(machineType.zone(), machineType.machineType(),
optionsMap);
return computeRpc.getMachineType(machineType.zone(), machineType.type(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : MachineType.fromPb(answer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public String apply(DiskTypeId diskTypeId) {
private static final long serialVersionUID = 7337881474103686219L;

private final String zone;
private final String diskType;
private final String type;

private DiskTypeId(String project, String zone, String diskType) {
private DiskTypeId(String project, String zone, String type) {
super(project);
this.zone = checkNotNull(zone);
this.diskType = checkNotNull(diskType);
this.type = checkNotNull(type);
}

/**
* Returns the name of the disk type.
*/
public String diskType() {
return diskType;
public String type() {
return type;
}

/**
Expand All @@ -79,17 +79,17 @@ public ZoneId zoneId() {

@Override
public String selfLink() {
return super.selfLink() + "/zones/" + zone + "/diskTypes/" + diskType;
return super.selfLink() + "/zones/" + zone + "/diskTypes/" + type;
}

@Override
MoreObjects.ToStringHelper toStringHelper() {
return super.toStringHelper().add("zone", zone).add("diskType", diskType);
return super.toStringHelper().add("zone", zone).add("type", type);
}

@Override
public int hashCode() {
return Objects.hash(super.baseHashCode(), zone, diskType);
return Objects.hash(super.baseHashCode(), zone, type);
}

@Override
Expand All @@ -103,36 +103,36 @@ public boolean equals(Object obj) {
DiskTypeId other = (DiskTypeId) obj;
return baseEquals(other)
&& Objects.equals(zone, other.zone)
&& Objects.equals(diskType, other.diskType);
&& Objects.equals(type, other.type);
}

@Override
DiskTypeId setProjectId(String projectId) {
if (project() != null) {
return this;
}
return DiskTypeId.of(projectId, zone, diskType);
return DiskTypeId.of(projectId, zone, type);
}

/**
* Returns a disk type identity given the zone identity and the disk type name.
*/
public static DiskTypeId of(ZoneId zoneId, String diskType) {
return new DiskTypeId(zoneId.project(), zoneId.zone(), diskType);
public static DiskTypeId of(ZoneId zoneId, String type) {
return new DiskTypeId(zoneId.project(), zoneId.zone(), type);
}

/**
* Returns a disk type identity given the zone and disk type names.
*/
public static DiskTypeId of(String zone, String diskType) {
return of(ZoneId.of(null, zone), diskType);
public static DiskTypeId of(String zone, String type) {
return of(ZoneId.of(null, zone), type);
}

/**
* Returns a disk type identity given project disk, zone and disk type names.
*/
public static DiskTypeId of(String project, String zone, String diskType) {
return of(ZoneId.of(project, zone), diskType);
public static DiskTypeId of(String project, String zone, String type) {
return of(ZoneId.of(project, zone), type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ com.google.api.services.compute.model.MachineType toPb() {
if (creationTimestamp != null) {
machineTypePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
}
machineTypePb.setName(machineTypeId.machineType());
machineTypePb.setName(machineTypeId.type());
machineTypePb.setDescription(description);
machineTypePb.setSelfLink(machineTypeId.selfLink());
machineTypePb.setGuestCpus(cpus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ public String apply(MachineTypeId machineTypeId) {
private static final long serialVersionUID = -5819598544478859608L;

private final String zone;
private final String machineType;
private final String type;

private MachineTypeId(String project, String zone, String machineType) {
private MachineTypeId(String project, String zone, String type) {
super(project);
this.zone = checkNotNull(zone);
this.machineType = checkNotNull(machineType);
this.type = checkNotNull(type);
}

/**
* Returns the name of the machine type.
*/
public String machineType() {
return machineType;
public String type() {
return type;
}

/**
Expand All @@ -81,17 +81,17 @@ public ZoneId zoneId() {

@Override
public String selfLink() {
return super.selfLink() + "/zones/" + zone + "/machineTypes/" + machineType;
return super.selfLink() + "/zones/" + zone + "/machineTypes/" + type;
}

@Override
MoreObjects.ToStringHelper toStringHelper() {
return super.toStringHelper().add("zone", zone).add("machineType", machineType);
return super.toStringHelper().add("zone", zone).add("type", type);
}

@Override
public int hashCode() {
return Objects.hash(baseHashCode(), zone, machineType);
return Objects.hash(baseHashCode(), zone, type);
}

@Override
Expand All @@ -105,29 +105,29 @@ public boolean equals(Object obj) {
MachineTypeId other = (MachineTypeId) obj;
return baseEquals(other)
&& Objects.equals(zone, other.zone)
&& Objects.equals(machineType, other.machineType);
&& Objects.equals(type, other.type);
}

@Override
MachineTypeId setProjectId(String projectId) {
if (project() != null) {
return this;
}
return MachineTypeId.of(projectId, zone, machineType);
return MachineTypeId.of(projectId, zone, type);
}

/**
* Returns a machine type identity given the zone and type names.
*/
public static MachineTypeId of(String zone, String machineType) {
return new MachineTypeId(null, zone, machineType);
public static MachineTypeId of(String zone, String type) {
return new MachineTypeId(null, zone, type);
}

/**
* Returns a machine type identity given project, zone and type names.
*/
public static MachineTypeId of(String project, String zone, String machineType) {
return new MachineTypeId(project, zone, machineType);
public static MachineTypeId of(String project, String zone, String type) {
return new MachineTypeId(project, zone, type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,28 +561,28 @@ public void testGetOptions() {
@Test
public void testGetDiskType() {
EasyMock.expect(
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(DISK_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
DiskType diskType = compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType());
DiskType diskType = compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type());
assertEquals(DISK_TYPE, diskType);
}

@Test
public void testGetDiskType_Null() {
EasyMock.expect(
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(null);
EasyMock.replay(computeRpcMock);
compute = options.service();
assertNull(compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType()));
assertNull(compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type()));
}

@Test
public void testGetDiskTypeFromDiskTypeId() {
EasyMock.expect(
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(DISK_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
Expand All @@ -595,12 +595,12 @@ public void testGetDiskTypeWithSelectedFields() {
Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
EasyMock.expect(
computeRpcMock.getDiskType(
eq(DISK_TYPE_ID.zone()), eq(DISK_TYPE_ID.diskType()), capture(capturedOptions)))
eq(DISK_TYPE_ID.zone()), eq(DISK_TYPE_ID.type()), capture(capturedOptions)))
.andReturn(DISK_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
DiskType diskType =
compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), DISK_TYPE_OPTION_FIELDS);
compute.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), DISK_TYPE_OPTION_FIELDS);
String selector = (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.rpcOption());
assertTrue(selector.contains("selfLink"));
assertTrue(selector.contains("id"));
Expand Down Expand Up @@ -748,30 +748,30 @@ public void testAggregatedListDiskTypesWithOptions() {
public void testGetMachineType() {
EasyMock.expect(
computeRpcMock.getMachineType(
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(MACHINE_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
MachineType machineType =
compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType());
compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type());
assertEquals(MACHINE_TYPE, machineType);
}

@Test
public void testGetMachineType_Null() {
EasyMock.expect(
computeRpcMock.getMachineType(
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(null);
EasyMock.replay(computeRpcMock);
compute = options.service();
assertNull(compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType()));
assertNull(compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type()));
}

@Test
public void testGetMachineTypeFromMachineTypeId() {
EasyMock.expect(computeRpcMock.getMachineType(
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(MACHINE_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
Expand All @@ -783,13 +783,13 @@ public void testGetMachineTypeFromMachineTypeId() {
public void testGetMachineTypeWithSelectedFields() {
Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
EasyMock.expect(
computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.zone()), eq(MACHINE_TYPE_ID.machineType()),
computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.zone()), eq(MACHINE_TYPE_ID.type()),
capture(capturedOptions)))
.andReturn(MACHINE_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
MachineType machineType = compute.getMachineType(MACHINE_TYPE_ID.zone(),
MACHINE_TYPE_ID.machineType(), MACHINE_TYPE_OPTION_FIELDS);
MACHINE_TYPE_ID.type(), MACHINE_TYPE_OPTION_FIELDS);
String selector = (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.rpcOption());
assertTrue(selector.contains("selfLink"));
assertTrue(selector.contains("id"));
Expand Down Expand Up @@ -3169,7 +3169,7 @@ public void testCreateNetworkWithOptions() {
@Test
public void testRetryableException() {
EasyMock.expect(
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andThrow(new ComputeException(500, "InternalError"))
.andReturn(DISK_TYPE.toPb());
EasyMock.replay(computeRpcMock);
Expand All @@ -3182,7 +3182,7 @@ public void testRetryableException() {
public void testNonRetryableException() {
String exceptionMessage = "Not Implemented";
EasyMock.expect(
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andThrow(new ComputeException(501, exceptionMessage));
EasyMock.replay(computeRpcMock);
compute = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service();
Expand All @@ -3195,7 +3195,7 @@ public void testNonRetryableException() {
public void testRuntimeException() {
String exceptionMessage = "Artificial runtime exception";
EasyMock.expect(
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.diskType(), EMPTY_RPC_OPTIONS))
computeRpcMock.getDiskType(DISK_TYPE_ID.zone(), DISK_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andThrow(new RuntimeException(exceptionMessage));
EasyMock.replay(computeRpcMock);
compute = options.toBuilder().retryParams(RetryParams.defaultInstance()).build().service();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ public void testToAndFromPb() {
@Test
public void testSetProjectId() {
StandardDiskConfiguration standardDiskConfiguration = DISK_CONFIGURATION.toBuilder()
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.diskType()))
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.type()))
.build();
DiskInfo diskInfo = DISK_INFO.toBuilder()
.diskId(DiskId.of(DISK_ID.zone(), DISK_ID.disk()))
.configuration(standardDiskConfiguration)
.build();
compareDiskInfo(DISK_INFO, diskInfo.setProjectId("project"));
SnapshotDiskConfiguration snapshotDiskConfiguration = SNAPSHOT_DISK_CONFIGURATION.toBuilder()
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.diskType()))
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.type()))
.sourceSnapshot(SnapshotId.of(SNAPSHOT.snapshot()))
.build();
diskInfo = SNAPSHOT_DISK_INFO.toBuilder()
Expand All @@ -241,7 +241,7 @@ public void testSetProjectId() {
.build();
compareDiskInfo(SNAPSHOT_DISK_INFO, diskInfo.setProjectId("project"));
ImageDiskConfiguration imageDiskConfiguration = IMAGE_DISK_CONFIGURATION.toBuilder()
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.diskType()))
.diskType(DiskTypeId.of(TYPE.zone(), TYPE.type()))
.sourceImage(ImageId.of(IMAGE.image()))
.build();
diskInfo = IMAGE_DISK_INFO.toBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public void testOf() {
DiskTypeId diskTypeId = DiskTypeId.of(PROJECT, ZONE, DISK_TYPE);
assertEquals(PROJECT, diskTypeId.project());
assertEquals(ZONE, diskTypeId.zone());
assertEquals(DISK_TYPE, diskTypeId.diskType());
assertEquals(DISK_TYPE, diskTypeId.type());
assertEquals(URL, diskTypeId.selfLink());
diskTypeId = DiskTypeId.of(ZONE, DISK_TYPE);
assertNull(diskTypeId.project());
assertEquals(ZONE, diskTypeId.zone());
assertEquals(DISK_TYPE, diskTypeId.diskType());
assertEquals(DISK_TYPE, diskTypeId.type());
}

@Test
Expand Down Expand Up @@ -77,7 +77,7 @@ private void compareDiskTypeId(DiskTypeId expected, DiskTypeId value) {
assertEquals(expected, value);
assertEquals(expected.project(), expected.project());
assertEquals(expected.zone(), expected.zone());
assertEquals(expected.diskType(), expected.diskType());
assertEquals(expected.type(), expected.type());
assertEquals(expected.selfLink(), expected.selfLink());
assertEquals(expected.hashCode(), expected.hashCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testOf() {
@Test
public void testSetProjectId() {
ImageDiskConfiguration diskConfiguration = DISK_CONFIGURATION.toBuilder()
.diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.diskType()))
.diskType(DiskTypeId.of(DISK_TYPE.zone(), DISK_TYPE.type()))
.sourceImage(ImageId.of(IMAGE.image()))
.build();
compareImageDiskConfiguration(DISK_CONFIGURATION, diskConfiguration.setProjectId("project"));
Expand Down
Loading