commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1173882 - /commons/proper/pool/trunk/src/test/org/apache/commons/pool2/Waiter.java
Date Wed, 21 Sep 2011 21:51:15 GMT
Author: psteitz
Date: Wed Sep 21 21:51:15 2011
New Revision: 1173882

URL: http://svn.apache.org/viewvc?rev=1173882&view=rev
Log:
Implemented equals, haschCode and toString.

Modified:
    commons/proper/pool/trunk/src/test/org/apache/commons/pool2/Waiter.java

Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool2/Waiter.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/Waiter.java?rev=1173882&r1=1173881&r2=1173882&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool2/Waiter.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool2/Waiter.java Wed Sep 21 21:51:15
2011
@@ -17,6 +17,8 @@
 
 package org.apache.commons.pool2;
 
+import java.util.concurrent.atomic.AtomicInteger;
+
 /**
  * <p>Object created by {@link WaiterFactory}. Maintains active / valid state,
  * last passivated and idle times.  Waits with configurable latency when 
@@ -25,11 +27,13 @@ package org.apache.commons.pool2;
  * <p>This class is *not* threadsafe.</p>
  */
 public class Waiter {
+    private static AtomicInteger instanceCount = new AtomicInteger();
     private boolean active = false;
     private boolean valid = true;
     private long latency = 0;
     private long lastPassivated = 0;
     private long lastIdleTimeMs = 0;
+    private int id = instanceCount.getAndIncrement();
     
     public Waiter(boolean active, boolean valid, long latency) {
         this.active = active;
@@ -129,4 +133,28 @@ public class Waiter {
         return lastIdleTimeMs;
     }
     
+    @Override
+    public int hashCode() {
+        return id;     
+    }
+    
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof Waiter)) {
+            return false;
+        }
+        return obj.hashCode() == id;
+    }
+    
+    @Override
+    public String toString() {
+        StringBuffer buff = new StringBuffer();
+        buff.append("ID = " + id + "\n");
+        buff.append("valid = " + valid + "\n");
+        buff.append("active = " + active + "\n");
+        buff.append("lastPassivated = " + lastPassivated + "\n");
+        buff.append("lastIdleTimeMs = " + lastIdleTimeMs + "\n");
+        buff.append("latency = " + latency + "\n");
+        return buff.toString();
+    } 
 }



Mime
View raw message