You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/11/15 03:37:06 UTC

[3/4] incubator-brooklyn git commit: LocationEvent/UsageEvent hashCode+equals

LocationEvent/UsageEvent hashCode+equals

- Useful for tests.
- As is constructor that takes Date.

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

Branch: refs/heads/master
Commit: bf79f85b9b11e950861385ff93db40119c42931b
Parents: ac1ffa7
Author: Aled Sage <al...@gmail.com>
Authored: Fri Nov 14 19:53:13 2014 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Nov 14 19:53:13 2014 +0000

----------------------------------------------------------------------
 .../management/usage/ApplicationUsage.java      | 18 +++++++++++++++++-
 .../management/usage/LocationUsage.java         | 20 +++++++++++++++++++-
 2 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bf79f85b/core/src/main/java/brooklyn/management/usage/ApplicationUsage.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/usage/ApplicationUsage.java b/core/src/main/java/brooklyn/management/usage/ApplicationUsage.java
index cf72791..3dd30f4 100644
--- a/core/src/main/java/brooklyn/management/usage/ApplicationUsage.java
+++ b/core/src/main/java/brooklyn/management/usage/ApplicationUsage.java
@@ -40,7 +40,11 @@ public class ApplicationUsage {
         private final Lifecycle state;
 
         public ApplicationEvent(Lifecycle state) {
-            this.date = new Date();
+            this(new Date(), state);
+        }
+
+        public ApplicationEvent(Date date, Lifecycle state) {
+            this.date = checkNotNull(date, "date");
             this.state = checkNotNull(state, "state");
         }
 
@@ -53,6 +57,18 @@ public class ApplicationUsage {
         }
         
         @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof ApplicationEvent)) return false;
+            ApplicationEvent o = (ApplicationEvent) other;
+            return Objects.equal(date, o.date) && Objects.equal(state, o.state);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hashCode(date, state);
+        }
+        
+        @Override
         public String toString() {
             return Objects.toStringHelper(this).add("date", date).add("state", state).toString();
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/bf79f85b/core/src/main/java/brooklyn/management/usage/LocationUsage.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/management/usage/LocationUsage.java b/core/src/main/java/brooklyn/management/usage/LocationUsage.java
index f04055e..a8323d2 100644
--- a/core/src/main/java/brooklyn/management/usage/LocationUsage.java
+++ b/core/src/main/java/brooklyn/management/usage/LocationUsage.java
@@ -43,7 +43,11 @@ public class LocationUsage {
         private final String applicationId;
 
         public LocationEvent(Lifecycle state, String entityId, String entityType, String applicationId) {
-            this.date = new Date();
+            this(new Date(), state, entityId, entityType, applicationId);
+        }
+        
+        public LocationEvent(Date date, Lifecycle state, String entityId, String entityType, String applicationId) {
+            this.date = checkNotNull(date, "date");
             this.state = checkNotNull(state, "state");
             this.entityId = checkNotNull(entityId, "entityId");
             this.entityType = checkNotNull(entityType, "entityType");
@@ -71,6 +75,20 @@ public class LocationUsage {
         }
         
         @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof LocationEvent)) return false;
+            LocationEvent o = (LocationEvent) other;
+            return Objects.equal(date, o.date) && Objects.equal(state, o.state) 
+                    && Objects.equal(entityId, o.entityId) && Objects.equal(entityType, o.entityType)
+                    && Objects.equal(applicationId, o.applicationId);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hashCode(date, state, entityId, entityType, applicationId);
+        }
+        
+        @Override
         public String toString() {
             return Objects.toStringHelper(this).add("date", date).add("state", state).add("entityId", entityId)
                     .add("appId", applicationId).toString();