commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1520942 - /commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java
Date Mon, 09 Sep 2013 00:22:02 GMT
Author: olamy
Date: Mon Sep  9 00:22:01 2013
New Revision: 1520942

URL: http://svn.apache.org/r1520942
Log:
fix equals and use a better toString()

Modified:
    commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java

Modified: commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java?rev=1520942&r1=1520941&r2=1520942&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java
(original)
+++ commons/sandbox/monitoring/trunk/core/src/main/java/org/apache/commons/monitoring/Role.java
Mon Sep  9 00:22:01 2013
@@ -34,11 +34,10 @@ public class Role implements Comparable<
     public static final Role PERFORMANCES = new Role("performances", NANOSECOND);
     public static final Role FAILURES = new Role("failures", Unit.UNARY);
 
-    private String name;
-    private Unit unit;
+    private final String name;
+    private final Unit unit;
 
     public Role(String name, Unit unit) {
-        super();
         if (name == null) {
             throw new IllegalArgumentException("A role name is required");
         }
@@ -71,23 +70,25 @@ public class Role implements Comparable<
         return name.hashCode();
     }
 
-    /**
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
             return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final Role other = (Role) obj;
-        if (name == null && other.name != null) {
+        }
+        if ( o == null || getClass() != o.getClass() )
+        {
             return false;
-        } else if (!name.equals(other.name)) {
+        }
+
+        Role role = (Role) o;
+
+        if ( !name.equals( role.name ) )
+        {
             return false;
         }
+
         return true;
     }
 
@@ -99,7 +100,12 @@ public class Role implements Comparable<
     }
 
     @Override
-    public String toString() {
-        return name;
+    public String toString()
+    {
+        final StringBuilder sb = new StringBuilder( "Role{" );
+        sb.append( "name='" ).append( name ).append( '\'' );
+        sb.append( ", unit=" ).append( unit );
+        sb.append( '}' );
+        return sb.toString();
     }
 }



Mime
View raw message