aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject aurora git commit: Remove generated FROM_BUILDER and TO_BUILDER methods.
Date Wed, 22 Jul 2015 22:52:00 GMT
Repository: aurora
Updated Branches:
  refs/heads/master b002e4223 -> fff3e38b4


Remove generated FROM_BUILDER and TO_BUILDER methods.

With method references in Java 8 these are no longer needed. Method
references have the additional advantage that they can be used in
functions that take either `com.google.common.base.Function` or
`java.util.function.Function` (or any other functional interface).

Testing Done:
./gradlew -Pq clean build

Reviewed at https://reviews.apache.org/r/36709/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/fff3e38b
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/fff3e38b
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/fff3e38b

Branch: refs/heads/master
Commit: fff3e38b493dcc63b117876c404a2527691f7aca
Parents: b002e42
Author: Kevin Sweeney <kevints@apache.org>
Authored: Wed Jul 22 15:51:42 2015 -0700
Committer: Kevin Sweeney <kevints@apache.org>
Committed: Wed Jul 22 15:51:42 2015 -0700

----------------------------------------------------------------------
 .../aurora/scheduler/http/StructDump.java       |  2 +-
 .../ShiroAuthorizingParamInterceptor.java       |  4 +--
 .../scheduler/storage/db/DbAttributeStore.java  |  2 +-
 .../scheduler/storage/db/DbQuotaStore.java      |  2 +-
 .../aurora/tools/java/thrift_wrapper_codegen.py | 27 ++++----------------
 .../storage/entities/IHostAttributesTest.java   |  2 +-
 6 files changed, 11 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/fff3e38b/src/main/java/org/apache/aurora/scheduler/http/StructDump.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/StructDump.java b/src/main/java/org/apache/aurora/scheduler/http/StructDump.java
index 05434f8..5ecb706 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/StructDump.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/StructDump.java
@@ -109,7 +109,7 @@ public class StructDump extends JerseyTemplateServlet {
           @Override
           public Optional<JobConfiguration> apply(StoreProvider storeProvider) {
             return storeProvider.getCronJobStore().fetchJob(jobKey)
-                .transform(IJobConfiguration.TO_BUILDER);
+                .transform(IJobConfiguration::newBuilder);
           }
         });
   }

http://git-wip-us.apache.org/repos/asf/aurora/blob/fff3e38b/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroAuthorizingParamInterceptor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroAuthorizingParamInterceptor.java
b/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroAuthorizingParamInterceptor.java
index a95e1ec..f097edf 100644
--- a/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroAuthorizingParamInterceptor.java
+++ b/src/main/java/org/apache/aurora/scheduler/http/api/security/ShiroAuthorizingParamInterceptor.java
@@ -100,7 +100,7 @@ class ShiroAuthorizingParamInterceptor implements MethodInterceptor {
           Optional<Set<IJobKey>> targetJobs = JobKeys.from(Query.arbitrary(input));
           if (targetJobs.isPresent() && targetJobs.get().size() == 1) {
             return Optional.of(Iterables.getOnlyElement(targetJobs.get()))
-                .transform(IJobKey.TO_BUILDER);
+                .transform(IJobKey::newBuilder);
           } else {
             return Optional.absent();
           }
@@ -336,7 +336,7 @@ class ShiroAuthorizingParamInterceptor implements MethodInterceptor {
     Optional<IJobKey> jobKey = authorizingParamGetters
         .getUnchecked(invocation.getMethod())
         .apply(invocation.getArguments())
-        .transform(IJobKey.FROM_BUILDER);
+        .transform(IJobKey::build);
     if (jobKey.isPresent() && JobKeys.isValid(jobKey.get())) {
       Permission targetPermission = makeTargetPermission(method.getName(), jobKey.get());
       if (subject.isPermitted(targetPermission)) {

http://git-wip-us.apache.org/repos/asf/aurora/blob/fff3e38b/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
index 1b274c8..8b0a825 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbAttributeStore.java
@@ -88,7 +88,7 @@ class DbAttributeStore implements AttributeStore.Mutable {
   @Timed("attribute_store_fetch_one")
   @Override
   public Optional<IHostAttributes> getHostAttributes(String host) {
-    return Optional.fromNullable(mapper.select(host)).transform(IHostAttributes.FROM_BUILDER);
+    return Optional.fromNullable(mapper.select(host)).transform(IHostAttributes::build);
   }
 
   @Timed("attribute_store_fetch_all")

http://git-wip-us.apache.org/repos/asf/aurora/blob/fff3e38b/src/main/java/org/apache/aurora/scheduler/storage/db/DbQuotaStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/DbQuotaStore.java b/src/main/java/org/apache/aurora/scheduler/storage/db/DbQuotaStore.java
index 9371907..a8d7973 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/db/DbQuotaStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/db/DbQuotaStore.java
@@ -43,7 +43,7 @@ class DbQuotaStore implements QuotaStore.Mutable {
   @Override
   public Optional<IResourceAggregate> fetchQuota(String role) {
     return Optional.fromNullable(mapper.select(role))
-        .transform(IResourceAggregate.FROM_BUILDER);
+        .transform(IResourceAggregate::build);
   }
 
   @Timed("quota_store_fetch_quotas")

http://git-wip-us.apache.org/repos/asf/aurora/blob/fff3e38b/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py b/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
index f3d9288..b5f2bc9 100644
--- a/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
+++ b/src/main/python/apache/aurora/tools/java/thrift_wrapper_codegen.py
@@ -131,7 +131,7 @@ IMMUTABLE_COLLECTION_ASSIGNMENT = '''this.%(field)s = !wrapped.%(isset)s()
 STRUCT_COLLECTION_FIELD_ASSIGNMENT = '''this.%(field)s = !wrapped.%(isset)s()
         ? Immutable%(collection)s.<%(params)s>of()
         : FluentIterable.from(wrapped.%(fn_name)s())
-              .transform(%(params)s.FROM_BUILDER)
+              .transform(%(params)s::build)
               .to%(collection)s();'''
 
 PACKAGE_NAME = 'org.apache.aurora.scheduler.storage.entities'
@@ -162,36 +162,20 @@ public final class %(name)s {
     return buildNoCopy(wrapped.deepCopy());
   }
 
-  public static final Function<%(name)s, %(wrapped)s> TO_BUILDER =
-      new Function<%(name)s, %(wrapped)s>() {
-        @Override
-        public %(wrapped)s apply(%(name)s input) {
-          return input.newBuilder();
-        }
-      };
-
-  public static final Function<%(wrapped)s, %(name)s> FROM_BUILDER =
-      new Function<%(wrapped)s, %(name)s>() {
-        @Override
-        public %(name)s apply(%(wrapped)s input) {
-          return %(name)s.build(input);
-        }
-      };
-
   public static ImmutableList<%(wrapped)s> toBuildersList(Iterable<%(name)s>
w) {
-    return FluentIterable.from(w).transform(TO_BUILDER).toList();
+    return FluentIterable.from(w).transform(%(name)s::newBuilder).toList();
   }
 
   public static ImmutableList<%(name)s> listFromBuilders(Iterable<%(wrapped)s>
b) {
-    return FluentIterable.from(b).transform(FROM_BUILDER).toList();
+    return FluentIterable.from(b).transform(%(name)s::build).toList();
   }
 
   public static ImmutableSet<%(wrapped)s> toBuildersSet(Iterable<%(name)s> w)
{
-    return FluentIterable.from(w).transform(TO_BUILDER).toSet();
+    return FluentIterable.from(w).transform(%(name)s::newBuilder).toSet();
   }
 
   public static ImmutableSet<%(name)s> setFromBuilders(Iterable<%(wrapped)s>
b) {
-    return FluentIterable.from(b).transform(FROM_BUILDER).toSet();
+    return FluentIterable.from(b).transform(%(name)s::build).toSet();
   }
 
   public %(wrapped)s newBuilder() {
@@ -462,7 +446,6 @@ def parse_services(service_defs):
 def generate_java(struct):
   code = GeneratedCode(struct.codegen_name, struct.name)
   code.add_import('java.util.Objects')
-  code.add_import('com.google.common.base.Function')
   code.add_import('com.google.common.collect.ImmutableList')
   code.add_import('com.google.common.collect.ImmutableSet')
   code.add_import('com.google.common.collect.FluentIterable')

http://git-wip-us.apache.org/repos/asf/aurora/blob/fff3e38b/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
b/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
index 05b31c2..4dcc3e5 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/entities/IHostAttributesTest.java
@@ -32,7 +32,7 @@ public class IHostAttributesTest {
     HostAttributes mutable = new HostAttributes()
         .setHost("a")
         .setAttributes(ImmutableSet.of(attribute));
-    IHostAttributes immutable1 = IHostAttributes.FROM_BUILDER.apply(mutable);
+    IHostAttributes immutable1 = IHostAttributes.build(mutable);
     IHostAttributes immutable2 = IHostAttributes.build(mutable);
     assertEquals(immutable1, immutable2);
     assertEquals(immutable2, immutable1);


Mime
View raw message