3434
3535/**
3636 * A Google Compute Engine address. With Compute Engine you can create static external IP addresses
37- * that are assigned to your project and persists until you explicitly release them. A region
38- * address can be assigned to a Compute Engine instance or to a regional forwarding rule. To create
39- * a region address use a {@link RegionAddressId} identity. Compute Engine also allows to create
40- * global addresses that are used for global forwarding rules. Both global addresses and global
41- * forwarding rules can only be used for HTTP load balancing. To create a global address use a
37+ * that are assigned to your project and persist until you explicitly release them. A region address
38+ * can be assigned to a Compute Engine instance or to a regional forwarding rule. To create a region
39+ * address, use a {@link RegionAddressId} identity. Compute Engine also allows you to create global
40+ * addresses that are used for global forwarding rules. Both global addresses and global forwarding
41+ * rules can only be used for HTTP load balancing. To create a global address, use a
4242 * {@link GlobalAddressId} identity.
4343 *
4444 * @see <a href="https://cloud.google.com/compute/docs/instances-and-network#reservedaddress">
@@ -94,8 +94,8 @@ public enum Status {
9494 * class represent different possible usages of a Compute Engine address. {@link InstanceUsage}
9595 * contains information for region addresses assigned to a Google Compute Engine instance.
9696 * {@link RegionForwardingUsage} contains information for region addresses assigned to one or more
97- * region forwarding rule . {@link GlobalForwardingUsage} contains information for global addresses
98- * assigned to one or more global forwarding rule .
97+ * region forwarding rules . {@link GlobalForwardingUsage} contains information for global
98+ * addresses assigned to one or more global forwarding rules .
9999 */
100100 public abstract static class Usage implements Serializable {
101101
@@ -106,7 +106,7 @@ public abstract static class Usage implements Serializable {
106106 /**
107107 * Returns the identities of resources currently using this address.
108108 */
109- public abstract List <ResourceId > users ();
109+ public abstract List <? extends ResourceId > users ();
110110
111111 final boolean baseEquals (Usage usage ) {
112112 return Objects .equals (toPb (), usage .toPb ());
@@ -128,8 +128,10 @@ static <T extends Usage> T fromPb(Address addressPb) {
128128 return (T ) InstanceUsage .fromPb (addressPb );
129129 } else if (RegionForwardingRuleId .matchesUrl (url )) {
130130 return (T ) RegionForwardingUsage .fromPb (addressPb );
131- } else {
131+ } else if ( GlobalForwardingRuleId . matchesUrl ( url )) {
132132 return (T ) GlobalForwardingUsage .fromPb (addressPb );
133+ } else {
134+ throw new IllegalArgumentException ("Unexpected resource URL for address user" );
133135 }
134136 }
135137 }
@@ -156,8 +158,8 @@ public InstanceId instance() {
156158 }
157159
158160 @ Override
159- public List <ResourceId > users () {
160- return ImmutableList .< ResourceId > of (instance );
161+ public List <InstanceId > users () {
162+ return ImmutableList .of (instance );
161163 }
162164
163165 @ Override
@@ -203,9 +205,8 @@ public List<RegionForwardingRuleId> forwardingRules() {
203205 }
204206
205207 @ Override
206- @ SuppressWarnings ("unchecked" )
207- public List <ResourceId > users () {
208- return (List <ResourceId >) (List ) forwardingRules ;
208+ public List <RegionForwardingRuleId > users () {
209+ return forwardingRules ;
209210 }
210211
211212 @ Override
@@ -252,9 +253,8 @@ public List<GlobalForwardingRuleId> forwardingRules() {
252253 }
253254
254255 @ Override
255- @ SuppressWarnings ("unchecked" )
256- public List <ResourceId > users () {
257- return (List <ResourceId >) (List ) forwardingRules ;
256+ public List <GlobalForwardingRuleId > users () {
257+ return forwardingRules ;
258258 }
259259
260260 @ Override
@@ -298,7 +298,7 @@ public abstract static class Builder {
298298
299299 abstract Builder id (String id );
300300
301- abstract Builder addressId (AddressId addressId );
301+ public abstract Builder addressId (AddressId addressId );
302302
303303 abstract Builder status (Status status );
304304
@@ -379,7 +379,7 @@ BuilderImpl id(String id) {
379379 }
380380
381381 @ Override
382- BuilderImpl addressId (AddressId addressId ) {
382+ public BuilderImpl addressId (AddressId addressId ) {
383383 this .addressId = checkNotNull (addressId );
384384 return this ;
385385 }
@@ -457,11 +457,11 @@ public Status status() {
457457 }
458458
459459 /**
460- * Returns the usage information of the address. Returns a {@link InstanceUsage} object for region
461- * addresses that are assigned to VM instances. Returns a {@link RegionForwardingUsage} object for
462- * region addresses assigned to region forwarding rules. Returns a {@link GlobalForwardingUsage}
463- * object for global addresses assigned to global forwarding rules. Returns {@code null} if the
464- * address is not in use.
460+ * Returns the usage information of the address. Returns an {@link InstanceUsage} object for
461+ * region addresses that are assigned to VM instances. Returns a {@link RegionForwardingUsage}
462+ * object for region addresses assigned to region forwarding rules. Returns a
463+ * {@link GlobalForwardingUsage} object for global addresses assigned to global forwarding rules.
464+ * Returns {@code null} if the address is not in use.
465465 */
466466 @ SuppressWarnings ("unchecked" )
467467 public <T extends Usage > T usage () {
@@ -501,14 +501,10 @@ public boolean equals(Object obj) {
501501 }
502502
503503 AddressInfo setProjectId (String projectId ) {
504- Builder builder = toBuilder ();
505- AddressId addressIdWithProject ;
506- if (addressId instanceof RegionAddressId ) {
507- addressIdWithProject = this .<RegionAddressId >addressId ().setProjectId (projectId );
508- } else {
509- addressIdWithProject = this .<GlobalAddressId >addressId ().setProjectId (projectId );
510- }
511- return builder .addressId (addressIdWithProject ).build ();
504+ if (addressId ().project () != null ) {
505+ return this ;
506+ }
507+ return toBuilder ().addressId (addressId .setProjectId (projectId )).build ();
512508 }
513509
514510 Address toPb () {
0 commit comments