1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
2020
21- import com .google .common .base .Function ;
2221import com .google .common .collect .ImmutableList ;
23- import com .google .common .collect .Lists ;
2422
2523import java .io .Serializable ;
2624import java .util .Arrays ;
@@ -176,44 +174,7 @@ public boolean equals(Object obj) {
176174 return false ;
177175 }
178176 Identity other = (Identity ) obj ;
179- return Objects .equals (toPb (), other .toPb ());
180- }
181-
182- String toPb () {
183- switch (type ) {
184- case ALL_USERS :
185- return "allUsers" ;
186- case ALL_AUTHENTICATED_USERS :
187- return "allAuthenticatedUsers" ;
188- case USER :
189- return "user:" + id ;
190- case SERVICE_ACCOUNT :
191- return "serviceAccount:" + id ;
192- case GROUP :
193- return "group:" + id ;
194- default :
195- return "domain:" + id ;
196- }
197- }
198-
199- static Identity fromPb (String identityStr ) {
200- String [] info = identityStr .split (":" );
201- switch (info [0 ]) {
202- case "allUsers" :
203- return allUsers ();
204- case "allAuthenticatedUsers" :
205- return allAuthenticatedUsers ();
206- case "user" :
207- return user (info [1 ]);
208- case "serviceAccount" :
209- return serviceAccount (info [1 ]);
210- case "group" :
211- return group (info [1 ]);
212- case "domain" :
213- return domain (info [1 ]);
214- default :
215- throw new IllegalArgumentException ("Unexpected identity type: " + info [0 ]);
216- }
177+ return Objects .equals (id , other .id ()) && Objects .equals (type , other .type ());
217178 }
218179 }
219180
@@ -351,31 +312,7 @@ public boolean equals(Object obj) {
351312 return false ;
352313 }
353314 Acl other = (Acl ) obj ;
354- return Objects .equals (toPb (), other .toPb ());
355- }
356-
357- com .google .api .services .cloudresourcemanager .model .Binding toPb () {
358- com .google .api .services .cloudresourcemanager .model .Binding bindingPb =
359- new com .google .api .services .cloudresourcemanager .model .Binding ();
360- bindingPb .setMembers (Lists .transform (identities , new Function <Identity , String >() {
361- @ Override
362- public String apply (Identity identity ) {
363- return identity .toPb ();
364- }
365- }));
366- bindingPb .setRole ("roles/" + role );
367- return bindingPb ;
368- }
369-
370- static Acl fromPb (com .google .api .services .cloudresourcemanager .model .Binding bindingPb ) {
371- return of (
372- bindingPb .getRole ().substring ("roles/" .length ()),
373- Lists .transform (bindingPb .getMembers (), new Function <String , Identity >() {
374- @ Override
375- public Identity apply (String memberPb ) {
376- return Identity .fromPb (memberPb );
377- }
378- }));
315+ return Objects .equals (identities , other .identities ()) && Objects .equals (role , other .role ());
379316 }
380317 }
381318
@@ -489,7 +426,8 @@ public boolean equals(Object obj) {
489426 return false ;
490427 }
491428 IamPolicy other = (IamPolicy ) obj ;
492- return Objects .equals (toPb (), other .toPb ());
429+ return Objects .equals (acls , other .acls ()) && Objects .equals (etag , other .etag ())
430+ && Objects .equals (version , other .version ());
493431 }
494432
495433 public static Builder builder () {
@@ -499,32 +437,4 @@ public static Builder builder() {
499437 public Builder toBuilder () {
500438 return new Builder ().acls (acls ).etag (etag ).version (version );
501439 }
502-
503- com .google .api .services .cloudresourcemanager .model .Policy toPb () {
504- com .google .api .services .cloudresourcemanager .model .Policy policyPb =
505- new com .google .api .services .cloudresourcemanager .model .Policy ();
506- policyPb .setBindings (Lists .transform (
507- acls , new Function <Acl , com .google .api .services .cloudresourcemanager .model .Binding >() {
508- @ Override
509- public com .google .api .services .cloudresourcemanager .model .Binding apply (Acl acl ) {
510- return acl .toPb ();
511- }
512- }));
513- policyPb .setEtag (etag );
514- policyPb .setVersion (version );
515- return policyPb ;
516- }
517-
518- static IamPolicy fromPb (com .google .api .services .cloudresourcemanager .model .Policy policyPb ) {
519- Builder builder = new Builder ();
520- builder .acls (Lists .transform (
521- policyPb .getBindings (),
522- new Function <com .google .api .services .cloudresourcemanager .model .Binding , Acl >() {
523- @ Override
524- public Acl apply (com .google .api .services .cloudresourcemanager .model .Binding binding ) {
525- return Acl .fromPb (binding );
526- }
527- }));
528- return builder .etag (policyPb .getEtag ()).version (policyPb .getVersion ()).build ();
529- }
530440}
0 commit comments