- Timestamp:
- 06/02/10 03:21:37 (3 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/main/java/com/davidsoergel/dsutils/collections/Dereplicator.java
r571 r574 5 5 6 6 /** 7 * Save memory by storing only one object for each set of equal() objects. This is sensible only if the objects are immutable and equals() is legitimate. 7 * Save memory by storing only one object for each set of equal() objects. This is sensible only if the objects are 8 * immutable and equals() is legitimate. 8 9 * 9 10 * @author <a href="mailto:dev@davidsoergel.com">David Soergel</a> … … 12 13 public class Dereplicator<T> 13 14 { 14 private Map<T, T> objects = new HashMap<T,T>();15 private Map<T, T> objects = new HashMap<T, T>(); 15 16 16 17 public T derep(T o) 17 18 { 19 if (o == null) 20 { 21 return null; 22 } 18 23 T result = objects.get(o); 19 if (result == null)24 if (result == null) 20 25 { 21 objects.put(o, o);26 objects.put(o, o); 22 27 result = o; 23 28 }
