All pastes #904803 Raw Edit

Meins

public text v1 · immutable
·published 2008-02-15 08:50 UTC
rendered paste body
import java.util.HashSet;

public class HashSetTest {
	public class Point{
		private String id = null;
		
		public Point(String id){
			this.id=id;
		}
		public String getId(){
			return this.id;
		}
		
		@Override
		public boolean equals(Object obj){
			System.out.println("point.equals called");
			if(obj instanceof Point){
				Point tempPoint=(Point)obj;
				if(tempPoint.getId().equalsIgnoreCase(this.getId())){
					return true;
				}
			}
			return false;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HashSetTest test = new HashSetTest();
		HashSet<Point> testSet = new HashSet<Point>();
		
		Point p1= test.new Point("p1");
		Point p12=test.new Point("p1");
		Point p2= test.new Point("p2");
		
		testSet.add(p1);
		System.out.println(String.format("size=%d", testSet.size()));
		testSet.add(p2);
		System.out.println(String.format("size=%d", testSet.size()));
		testSet.add(p12);
		System.out.println(String.format("size=%d", testSet.size()));

	}

}