Skip to content

Commit 35fc77d

Browse files
committed
Migrate IDs from Long to BigInteger
1 parent c9f028e commit 35fc77d

9 files changed

Lines changed: 51 additions & 59 deletions

File tree

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public com.google.api.services.compute.model.DiskType apply(DiskType diskType) {
4848

4949
private static final long serialVersionUID = -944042261695072026L;
5050

51-
private final Long id;
51+
private final BigInteger id;
5252
private final DiskTypeId diskTypeId;
5353
private final String creationTimestamp;
5454
private final String description;
@@ -59,7 +59,7 @@ public com.google.api.services.compute.model.DiskType apply(DiskType diskType) {
5959

6060
static final class Builder {
6161

62-
private Long id;
62+
private BigInteger id;
6363
private DiskTypeId diskTypeId;
6464
private String creationTimestamp;
6565
private String description;
@@ -70,7 +70,7 @@ static final class Builder {
7070

7171
private Builder() {}
7272

73-
Builder id(Long id) {
73+
Builder id(BigInteger id) {
7474
this.id = id;
7575
return this;
7676
}
@@ -145,7 +145,7 @@ public DiskTypeId diskTypeId() {
145145
/**
146146
* Returns an unique identifier for the disk type; defined by the service.
147147
*/
148-
public Long id() {
148+
public BigInteger id() {
149149
return id;
150150
}
151151

@@ -212,9 +212,7 @@ public boolean equals(Object obj) {
212212
com.google.api.services.compute.model.DiskType toPb() {
213213
com.google.api.services.compute.model.DiskType diskTypePb =
214214
new com.google.api.services.compute.model.DiskType();
215-
if (id != null) {
216-
diskTypePb.setId(BigInteger.valueOf(id));
217-
}
215+
diskTypePb.setId(id);
218216
diskTypePb.setCreationTimestamp(creationTimestamp);
219217
diskTypePb.setDescription(description);
220218
diskTypePb.setValidDiskSize(validDiskSize);
@@ -233,9 +231,7 @@ static Builder builder() {
233231

234232
static DiskType fromPb(com.google.api.services.compute.model.DiskType diskTypePb) {
235233
Builder builder = builder();
236-
if (diskTypePb.getId() != null) {
237-
builder.id(diskTypePb.getId().longValue());
238-
}
234+
builder.id(diskTypePb.getId());
239235
builder.creationTimestamp(diskTypePb.getCreationTimestamp());
240236
builder.diskTypeId(DiskTypeId.fromUrl(diskTypePb.getSelfLink()));
241237
builder.description(diskTypePb.getDescription());

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public com.google.api.services.compute.model.MachineType apply(MachineType type)
5555
private static final long serialVersionUID = -4210962597502860450L;
5656

5757
private final MachineTypeId machineTypeId;
58-
private final Long id;
58+
private final BigInteger id;
5959
private final String creationTimestamp;
6060
private final String description;
6161
private final String selfLink;
@@ -69,7 +69,7 @@ public com.google.api.services.compute.model.MachineType apply(MachineType type)
6969
static final class Builder {
7070

7171
private MachineTypeId machineTypeId;
72-
private Long id;
72+
private BigInteger id;
7373
private String creationTimestamp;
7474
private String description;
7575
private String selfLink;
@@ -87,7 +87,7 @@ Builder machineTypeId(MachineTypeId machineTypeId) {
8787
return this;
8888
}
8989

90-
Builder id(Long id) {
90+
Builder id(BigInteger id) {
9191
this.id = id;
9292
return this;
9393
}
@@ -166,7 +166,7 @@ public MachineTypeId machineTypeId() {
166166
/**
167167
* Returns an unique identifier for the machin type; defined by the service.
168168
*/
169-
public Long id() {
169+
public BigInteger id() {
170170
return id;
171171
}
172172

@@ -268,9 +268,7 @@ public boolean equals(Object obj) {
268268
com.google.api.services.compute.model.MachineType toPb() {
269269
com.google.api.services.compute.model.MachineType machineTypePb =
270270
new com.google.api.services.compute.model.MachineType();
271-
if (id != null) {
272-
machineTypePb.setId(BigInteger.valueOf(id));
273-
}
271+
machineTypePb.setId(id);
274272
machineTypePb.setCreationTimestamp(creationTimestamp);
275273
machineTypePb.setName(machineTypeId.machineType());
276274
machineTypePb.setDescription(description);
@@ -302,9 +300,7 @@ static Builder builder() {
302300
static MachineType fromPb(com.google.api.services.compute.model.MachineType machineTypePb) {
303301
Builder builder = builder();
304302
builder.machineTypeId(MachineTypeId.fromUrl(machineTypePb.getSelfLink()));
305-
if (machineTypePb.getId() != null) {
306-
builder.id(machineTypePb.getId().longValue());
307-
}
303+
builder.id(machineTypePb.getId());
308304
builder.creationTimestamp(machineTypePb.getCreationTimestamp());
309305
builder.description(machineTypePb.getDescription());
310306
builder.selfLink(machineTypePb.getSelfLink());

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

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public com.google.api.services.compute.model.Region apply(Region region) {
5050

5151
private static final long serialVersionUID = -3578710133393645135L;
5252

53+
private final RegionId regionId;
54+
private final BigInteger id;
55+
private final String creationTimestamp;
56+
private final String description;
57+
private final String selfLink;
58+
private final Status status;
59+
private final List<ZoneId> zones;
60+
private final List<Quota> quotas;
61+
5362
/**
5463
* Status of the region.
5564
*/
@@ -141,19 +150,10 @@ static Quota fromPb(com.google.api.services.compute.model.Quota quotaPb) {
141150
}
142151
}
143152

144-
private final RegionId regionId;
145-
private final Long id;
146-
private final String creationTimestamp;
147-
private final String description;
148-
private final String selfLink;
149-
private final Status status;
150-
private final List<ZoneId> zones;
151-
private final List<Quota> quotas;
152-
153153
static final class Builder {
154154

155155
private RegionId regionId;
156-
private Long id;
156+
private BigInteger id;
157157
private String creationTimestamp;
158158
private String description;
159159
private String selfLink;
@@ -168,7 +168,7 @@ Builder regionId(RegionId regionId) {
168168
return this;
169169
}
170170

171-
Builder id(Long id) {
171+
Builder id(BigInteger id) {
172172
this.id = id;
173173
return this;
174174
}
@@ -223,7 +223,7 @@ public RegionId regionId() {
223223
return regionId;
224224
}
225225

226-
public Long id() {
226+
public BigInteger id() {
227227
return id;
228228
}
229229

@@ -278,9 +278,7 @@ public boolean equals(Object obj) {
278278
com.google.api.services.compute.model.Region toPb() {
279279
com.google.api.services.compute.model.Region regionPb =
280280
new com.google.api.services.compute.model.Region();
281-
if (id != null) {
282-
regionPb.setId(BigInteger.valueOf(id));
283-
}
281+
regionPb.setId(id);
284282
regionPb.setCreationTimestamp(creationTimestamp);
285283
regionPb.setName(regionId.region());
286284
regionPb.setDescription(description);
@@ -302,9 +300,7 @@ static Builder builder() {
302300
static Region fromPb(com.google.api.services.compute.model.Region regionPb) {
303301
Builder builder = builder();
304302
builder.regionId(RegionId.fromUrl(regionPb.getSelfLink()));
305-
if (regionPb.getId() != null) {
306-
builder.id(regionPb.getId().longValue());
307-
}
303+
builder.id(regionPb.getId());
308304
builder.creationTimestamp(regionPb.getCreationTimestamp());
309305
builder.description(regionPb.getDescription());
310306
builder.selfLink(regionPb.getSelfLink());

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public com.google.api.services.compute.model.Zone apply(Zone region) {
5050

5151
private static final long serialVersionUID = 6113636504417213010L;
5252

53+
private final ZoneId zoneId;
54+
private final BigInteger id;
55+
private final String creationTimestamp;
56+
private final String description;
57+
private final String selfLink;
58+
private final Status status;
59+
private final List<MaintenanceWindow> maintenanceWindows;
60+
private final RegionId region;
61+
5362
/**
5463
* Status of the region.
5564
*/
@@ -166,19 +175,10 @@ static MaintenanceWindow fromPb(MaintenanceWindows windowPb) {
166175
}
167176
}
168177

169-
private final ZoneId zoneId;
170-
private final Long id;
171-
private final String creationTimestamp;
172-
private final String description;
173-
private final String selfLink;
174-
private final Status status;
175-
private final List<MaintenanceWindow> maintenanceWindows;
176-
private final RegionId region;
177-
178178
static final class Builder {
179179

180180
private ZoneId zoneId;
181-
private Long id;
181+
private BigInteger id;
182182
private String creationTimestamp;
183183
private String description;
184184
private String selfLink;
@@ -193,7 +193,7 @@ Builder zoneId(ZoneId zoneId) {
193193
return this;
194194
}
195195

196-
Builder id(Long id) {
196+
Builder id(BigInteger id) {
197197
this.id = id;
198198
return this;
199199
}
@@ -270,7 +270,7 @@ public String description() {
270270
/**
271271
* Returns an unique identifier for the zone; defined by the service.
272272
*/
273-
public Long id() {
273+
public BigInteger id() {
274274
return id;
275275
}
276276

@@ -333,7 +333,7 @@ public boolean equals(Object obj) {
333333
com.google.api.services.compute.model.Zone toPb() {
334334
com.google.api.services.compute.model.Zone zonePb =
335335
new com.google.api.services.compute.model.Zone();
336-
zonePb.setId(BigInteger.valueOf(id));
336+
zonePb.setId(id);
337337
zonePb.setCreationTimestamp(creationTimestamp);
338338
zonePb.setName(zoneId.zone());
339339
zonePb.setDescription(description);
@@ -356,9 +356,7 @@ static Builder builder() {
356356
static Zone fromPb(com.google.api.services.compute.model.Zone zonePb) {
357357
Builder builder = builder();
358358
builder.zoneId(ZoneId.fromUrl(zonePb.getSelfLink()));
359-
if (zonePb.getId() != null) {
360-
builder.id(zonePb.getId().longValue());
361-
}
359+
builder.id(zonePb.getId());
362360
builder.creationTimestamp(zonePb.getCreationTimestamp());
363361
builder.description(zonePb.getDescription());
364362
builder.selfLink(zonePb.getSelfLink());

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020

2121
import org.junit.Test;
2222

23+
import java.math.BigInteger;
24+
2325
public class DiskTypeTest {
2426

25-
private static final Long ID = 42L;
27+
private static final BigInteger ID = BigInteger.valueOf(42L);
2628
private static final String CREATION_TIMESTAMP = "2016-01-20T04:39:00.210-08:00";
2729
private static final String DESCRIPTION = "description";
2830
private static final String VALID_DISK_SIZE = "10GB-10TB";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
import org.junit.Test;
2424

25+
import java.math.BigInteger;
2526
import java.util.List;
2627

2728
public class MachineTypeTest {
2829

29-
private static final Long ID = 42L;
30+
private static final BigInteger ID = BigInteger.valueOf(42L);
3031
private static final String CREATION_TIMESTAMP = "2016-01-20T04:39:00.210-08:00";
3132
private static final String DESCRIPTION = "description";
3233
private static final MachineTypeId MACHINE_TYPE_ID = MachineTypeId.of("project", "zone", "type");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222

2323
import org.junit.Test;
2424

25+
import java.math.BigInteger;
2526
import java.util.List;
2627

2728
public class RegionTest {
2829

2930
private static final RegionId REGION_ID = RegionId.of("project", "region");
30-
private static final Long ID = 42L;
31+
private static final BigInteger ID = BigInteger.valueOf(42L);
3132
private static final String CREATION_TIMESTAMP = "2016-01-20T04:39:00.210-08:00";
3233
private static final String DESCRIPTION = "description";
3334
private static final Region.Status STATUS = Region.Status.DOWN;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
import java.io.ObjectInputStream;
3333
import java.io.ObjectOutputStream;
3434
import java.io.Serializable;
35+
import java.math.BigInteger;
3536
import java.util.List;
3637

3738
public class SerializationTest {
3839

39-
private static final Long ID = 42L;
40+
private static final BigInteger ID = BigInteger.valueOf(42L);
4041
private static final String CREATION_TIMESTAMP = "2016-01-20T04:39:00.210-08:00";
4142
private static final String DESCRIPTION = "description";
4243
private static final String VALID_DISK_SIZE = "10GB-10TB";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323

2424
import org.junit.Test;
2525

26+
import java.math.BigInteger;
2627
import java.util.List;
2728

2829
public class ZoneTest {
2930

3031
private static final ZoneId ZONE_ID = ZoneId.of("project", "zone");
3132
private static final RegionId REGION_ID = RegionId.of("project", "region");
32-
private static final Long ID = 42L;
33+
private static final BigInteger ID = BigInteger.valueOf(42L);
3334
private static final String CREATION_TIMESTAMP = "2016-01-20T04:39:00.210-08:00";
3435
private static final String DESCRIPTION = "description";
3536
private static final Zone.Status STATUS = Zone.Status.DOWN;

0 commit comments

Comments
 (0)