equals(), hashCode() updated/added, also a few minor changes

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@110 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
asivache 2009-03-20 05:13:07 +00:00
parent 4badd54216
commit f810412d75
2 changed files with 13 additions and 4 deletions

View File

@ -20,6 +20,7 @@ public class CountedObject<T> {
* @param o object to start counting for * @param o object to start counting for
*/ */
public CountedObject(T o) { public CountedObject(T o) {
assert o!=null : "Can not create counted object over null";
mObject = o; mObject = o;
mCounter = 1; mCounter = 1;
} }
@ -30,6 +31,7 @@ public class CountedObject<T> {
* @param n initial count * @param n initial count
*/ */
public CountedObject(T o, int n) { public CountedObject(T o, int n) {
assert o!=null : "Can not create counted object over null";
mObject = o; mObject = o;
mCounter = n; mCounter = n;
} }
@ -40,11 +42,18 @@ public class CountedObject<T> {
public void increment(int n) { mCounter+=n; } public void increment(int n) { mCounter+=n; }
public void decrement() { mCounter--; } public void decrement() { mCounter--; }
public void decrement(int n) { mCounter -= n; } public void decrement(int n) { mCounter -= n; }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) return true; if ( this == o ) return true;
if ( ! ( o instanceof CountedObject )) return false; if ( ! ( o instanceof CountedObject ) ) return false;
return mObject.equals(o); if ( ((CountedObject)o).mObject.getClass() != this.mObject.getClass() ) return false;
return mObject.equals(((CountedObject<T>)o).getObject());
}
@Override
public int hashCode() {
return mObject.hashCode();
} }
} }

View File

@ -11,10 +11,10 @@ package org.broadinstitute.sting.utils;
*/ */
public class CountedObjectComparatorAdapter<T> implements java.util.Comparator<CountedObject<T>> { public class CountedObjectComparatorAdapter<T> implements java.util.Comparator<CountedObject<T>> {
private java.util.Comparator<T> mComp; private java.util.Comparator<? super T> mComp;
/** Initializes comparator adapter with a comparator for objects of trype T */ /** Initializes comparator adapter with a comparator for objects of trype T */
public CountedObjectComparatorAdapter(java.util.Comparator<T> adaptee) { public CountedObjectComparatorAdapter(java.util.Comparator<? super T> adaptee) {
mComp = adaptee; mComp = adaptee;
} }