brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@apache.org
Subject [14/16] git commit: PR #1405: predicate input @Nullable
Date Tue, 27 May 2014 11:05:30 GMT
PR #1405: predicate input @Nullable


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

Branch: refs/heads/master
Commit: d4fd07465e56316e103983206d6c455368aac7a5
Parents: e7a49e9
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue May 27 11:49:18 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue May 27 11:49:29 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/catalog/CatalogPredicates.java     |  8 +++----
 .../java/brooklyn/config/ConfigPredicates.java  |  8 +++----
 .../brooklyn/entity/basic/EntityFunctions.java  | 16 +++++++++----
 .../brooklyn/entity/basic/EntityPredicates.java | 24 ++++++++++----------
 .../location/basic/LocationPredicates.java      | 15 ++++++------
 .../brooklyn/util/text/StringPredicates.java    |  7 ++----
 6 files changed, 40 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d4fd0746/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/CatalogPredicates.java b/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
index 2be5660..7112282 100644
--- a/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
+++ b/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
@@ -16,7 +16,7 @@ public class CatalogPredicates {
         return new Predicate<CatalogItem<T>>() {
             @Override
             public boolean apply(@Nullable CatalogItem<T> item) {
-                return item!=null && item.getCatalogItemType()==ciType;
+                return (item != null) && item.getCatalogItemType()==ciType;
             }
         };
     }
@@ -40,7 +40,7 @@ public class CatalogPredicates {
         return new Predicate<CatalogItem<T>>() {
             @Override
             public boolean apply(@Nullable CatalogItem<T> item) {
-                return item!=null && filter.apply(item.getName());
+                return (item != null) && filter.apply(item.getName());
             }
         };
     }
@@ -49,7 +49,7 @@ public class CatalogPredicates {
         return new Predicate<CatalogItem<T>>() {
             @Override
             public boolean apply(@Nullable CatalogItem<T> item) {
-                return item!=null && filter.apply(item.getJavaType());
+                return (item != null) && filter.apply(item.getJavaType());
             }
         };
     }
@@ -58,7 +58,7 @@ public class CatalogPredicates {
         return new Predicate<CatalogItem<T>>() {
             @Override
             public boolean apply(@Nullable CatalogItem<T> item) {
-                return item!=null && filter.apply(item.toXmlString());
+                return (item != null) && filter.apply(item.toXmlString());
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d4fd0746/core/src/main/java/brooklyn/config/ConfigPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/ConfigPredicates.java b/core/src/main/java/brooklyn/config/ConfigPredicates.java
index 97f08b5..f4925ff 100644
--- a/core/src/main/java/brooklyn/config/ConfigPredicates.java
+++ b/core/src/main/java/brooklyn/config/ConfigPredicates.java
@@ -14,7 +14,7 @@ public class ConfigPredicates {
         return new Predicate<ConfigKey<?>>() {
             @Override
             public boolean apply(@Nullable ConfigKey<?> input) {
-                return input.getName().startsWith(prefix);
+                return (input != null) && input.getName().startsWith(prefix);
             }
         };
     }
@@ -23,7 +23,7 @@ public class ConfigPredicates {
         return new Predicate<ConfigKey<?>>() {
             @Override
             public boolean apply(@Nullable ConfigKey<?> input) {
-                return WildcardGlobs.isGlobMatched(glob, input.getName());
+                return (input != null) && WildcardGlobs.isGlobMatched(glob, input.getName());
             }
         };
     }
@@ -33,7 +33,7 @@ public class ConfigPredicates {
         return new Predicate<ConfigKey<?>>() {
             @Override
             public boolean apply(@Nullable ConfigKey<?> input) {
-                return p.matcher(input.getName()).matches();
+                return (input != null) && p.matcher(input.getName()).matches();
             }
         };
     }
@@ -42,7 +42,7 @@ public class ConfigPredicates {
         return new Predicate<ConfigKey<?>>() {
             @Override
             public boolean apply(@Nullable ConfigKey<?> input) {
-                return filter.apply(input.getName());
+                return (input != null) && filter.apply(input.getName());
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d4fd0746/core/src/main/java/brooklyn/entity/basic/EntityFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/EntityFunctions.java b/core/src/main/java/brooklyn/entity/basic/EntityFunctions.java
index 06f7f97..7ac5bb5 100644
--- a/core/src/main/java/brooklyn/entity/basic/EntityFunctions.java
+++ b/core/src/main/java/brooklyn/entity/basic/EntityFunctions.java
@@ -1,5 +1,7 @@
 package brooklyn.entity.basic;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.Map;
 
 import brooklyn.config.ConfigKey;
@@ -9,13 +11,12 @@ import brooklyn.util.flags.TypeCoercions;
 
 import com.google.common.base.Function;
 
-// TODO Move to core
 public class EntityFunctions {
 
     public static <T> Function<Entity, T> attribute(final AttributeSensor<T>
attribute) {
         return new Function<Entity, T>() {
             @Override public T apply(Entity input) {
-                return (input == null ? null : input.getAttribute(attribute));
+                return (input == null) ? null : input.getAttribute(attribute);
             }
         };
     }
@@ -23,7 +24,7 @@ public class EntityFunctions {
     public static <T> Function<Entity, T> config(final ConfigKey<T> key)
{
         return new Function<Entity, T>() {
             @Override public T apply(Entity input) {
-                return (input == null ? null : input.getConfig(key));
+                return (input == null) ? null : input.getConfig(key);
             }
         };
     }
@@ -31,7 +32,7 @@ public class EntityFunctions {
     public static Function<Entity, String> displayName() {
         return new Function<Entity, String>() {
             @Override public String apply(Entity input) {
-                return (input == null ? null : input.getDisplayName());
+                return (input == null) ? null : input.getDisplayName();
             }
         };
     }
@@ -39,7 +40,7 @@ public class EntityFunctions {
     public static Function<Entity, String> id() {
         return new Function<Entity, String>() {
             @Override public String apply(Entity input) {
-                return (input == null ? null : input.getId());
+                return (input == null) ? null : input.getId();
             }
         };
     }
@@ -47,6 +48,7 @@ public class EntityFunctions {
     /** returns a function which sets the given sensors on the entity passed in,
      * with {@link Entities#UNCHANGED} and {@link Entities#REMOVE} doing those actions. */
     public static Function<Entity,Void> settingSensorsConstant(final Map<AttributeSensor<?>,Object>
values) {
+        checkNotNull(values, "values");
         return new Function<Entity,Void>() {
             @SuppressWarnings({ "unchecked", "rawtypes" })
             @Override public Void apply(Entity input) {
@@ -69,6 +71,8 @@ public class EntityFunctions {
 
     /** as {@link #settingSensorsConstant(Map)} but as a {@link Runnable} */
     public static Runnable settingSensorsConstantRunnable(final Entity entity, final Map<AttributeSensor<?>,Object>
values) {
+        checkNotNull(entity, "entity");
+        checkNotNull(values, "values");
         return new Runnable() {
             @Override
             public void run() {
@@ -81,6 +85,8 @@ public class EntityFunctions {
     /** as {@link #settingSensorsConstant(Map)} but creating a {@link Function} which ignores
its input,
      * suitable for use with sensor feeds where the input is ignored */
     public static <T> Function<T,Void> settingSensorsConstantFunction(final Entity
entity, final Map<AttributeSensor<?>,Object> values) {
+        checkNotNull(entity, "entity");
+        checkNotNull(values, "values");
         return new Function<T,Void>() {
             @Override
             public Void apply(T input) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d4fd0746/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java b/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
index 9e42d24..930412d 100644
--- a/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
+++ b/core/src/main/java/brooklyn/entity/basic/EntityPredicates.java
@@ -18,7 +18,7 @@ public class EntityPredicates {
         return new Predicate<Entity>() {
             @Override
             public boolean apply(@Nullable Entity input) {
-                return Objects.equal(input.getId(), val);
+                return (input != null) && Objects.equal(input.getId(), val);
             }
         };
     }
@@ -27,7 +27,7 @@ public class EntityPredicates {
         return new Predicate<Entity>() {
             @Override
             public boolean apply(@Nullable Entity input) {
-                return Objects.equal(input.getDisplayName(), val);
+                return (input != null) && Objects.equal(input.getDisplayName(), val);
             }
         };
     }
@@ -35,8 +35,8 @@ public class EntityPredicates {
     public static Predicate<Entity> applicationIdEqualTo(final String val) {
         return new Predicate<Entity>() {
             @Override
-            public boolean apply(Entity input) {
-                return val.equals(input.getApplicationId());
+            public boolean apply(@Nullable Entity input) {
+                return (input != null) && val.equals(input.getApplicationId());
             }
         };
     }
@@ -45,7 +45,7 @@ public class EntityPredicates {
         return new Predicate<Entity>() {
             @Override
             public boolean apply(@Nullable Entity input) {
-                return Objects.equal(input.getAttribute(attribute), val);
+                return (input != null) && Objects.equal(input.getAttribute(attribute),
val);
             }
         };
     }
@@ -53,8 +53,8 @@ public class EntityPredicates {
     public static <T> Predicate<Entity> configEqualTo(final ConfigKey<T>
configKey, final T val) {
         return new Predicate<Entity>() {
             @Override
-            public boolean apply(Entity input) {
-                return Objects.equal(input.getConfig(configKey), val);
+            public boolean apply(@Nullable Entity input) {
+                return (input != null) && Objects.equal(input.getConfig(configKey),
val);
             }
         };
     }
@@ -62,8 +62,8 @@ public class EntityPredicates {
     public static <T> Predicate<Entity> configEqualTo(final HasConfigKey<T>
configKey, final T val) {
         return new Predicate<Entity>() {
             @Override
-            public boolean apply(Entity input) {
-                return Objects.equal(input.getConfig(configKey), val);
+            public boolean apply(@Nullable Entity input) {
+                return (input != null) && Objects.equal(input.getConfig(configKey),
val);
             }
         };
     }
@@ -75,7 +75,7 @@ public class EntityPredicates {
         return new Predicate<Entity>() {
             @Override
             public boolean apply(@Nullable Entity input) {
-                return Objects.equal(input.getParent(), parent);
+                return (input != null) && Objects.equal(input.getParent(), parent);
             }
         };
     }
@@ -84,7 +84,7 @@ public class EntityPredicates {
         return new Predicate<Entity>() {
             @Override
             public boolean apply(@Nullable Entity input) {
-                return group.hasMember(input);
+                return (input != null) && group.hasMember(input);
             }
         };
     }
@@ -106,7 +106,7 @@ public class EntityPredicates {
         return new Predicate<Entity>() {
             @Override
             public boolean apply(@Nullable Entity input) {
-                return input != null && Entities.isManaged(input);
+                return (input != null) && Entities.isManaged(input);
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d4fd0746/core/src/main/java/brooklyn/location/basic/LocationPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/LocationPredicates.java b/core/src/main/java/brooklyn/location/basic/LocationPredicates.java
index 34c5788..096e5a6 100644
--- a/core/src/main/java/brooklyn/location/basic/LocationPredicates.java
+++ b/core/src/main/java/brooklyn/location/basic/LocationPredicates.java
@@ -15,7 +15,7 @@ public class LocationPredicates {
         return new Predicate<Location>() {
             @Override
             public boolean apply(@Nullable Location input) {
-                return Objects.equal(input.getId(), val);
+                return (input != null) && Objects.equal(input.getId(), val);
             }
         };
     }
@@ -24,7 +24,7 @@ public class LocationPredicates {
         return new Predicate<Location>() {
             @Override
             public boolean apply(@Nullable Location input) {
-                return Objects.equal(input.getDisplayName(), val);
+                return (input != null) && Objects.equal(input.getDisplayName(), val);
             }
         };
     }
@@ -32,8 +32,8 @@ public class LocationPredicates {
     public static <T> Predicate<Location> configEqualTo(final ConfigKey<T>
configKey, final T val) {
         return new Predicate<Location>() {
             @Override
-            public boolean apply(Location input) {
-                return Objects.equal(input.getConfig(configKey), val);
+            public boolean apply(@Nullable Location input) {
+                return (input != null) && Objects.equal(input.getConfig(configKey),
val);
             }
         };
     }
@@ -41,8 +41,8 @@ public class LocationPredicates {
     public static <T> Predicate<Location> configEqualTo(final HasConfigKey<T>
configKey, final T val) {
         return new Predicate<Location>() {
             @Override
-            public boolean apply(Location input) {
-                return Objects.equal(input.getConfig(configKey), val);
+            public boolean apply(@Nullable Location input) {
+                return (input != null) && Objects.equal(input.getConfig(configKey),
val);
             }
         };
     }
@@ -83,9 +83,8 @@ public class LocationPredicates {
         return new Predicate<Location>() {
             @Override
             public boolean apply(@Nullable Location input) {
-                return input != null && Locations.isManaged(input);
+                return (input != null) && Locations.isManaged(input);
             }
         };
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d4fd0746/utils/common/src/main/java/brooklyn/util/text/StringPredicates.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/text/StringPredicates.java b/utils/common/src/main/java/brooklyn/util/text/StringPredicates.java
index 42b251b..5399db2 100644
--- a/utils/common/src/main/java/brooklyn/util/text/StringPredicates.java
+++ b/utils/common/src/main/java/brooklyn/util/text/StringPredicates.java
@@ -51,8 +51,7 @@ public class StringPredicates {
         return new Predicate<CharSequence>() {
             @Override
             public boolean apply(CharSequence input) {
-                if (input==null) return false;
-                return input.toString().startsWith(prefix);
+                return (input != null) && input.toString().startsWith(prefix);
             }
         };
     }
@@ -62,9 +61,7 @@ public class StringPredicates {
         return new Predicate<Object>() {
             @Override
             public boolean apply(Object input) {
-                if (input==null) return false;
-                if (!(input instanceof CharSequence)) return false;
-                return input.toString().startsWith(prefix);
+                return (input instanceof CharSequence) && input.toString().startsWith(prefix);
             }
         };
     }


Mime
View raw message