Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package brooklyn.policy.followthesun;
 public class WeightedObject<T> implements Comparable<WeightedObject<T>>{
 	final T object;
 	final double weight;
 	public WeightedObject(T objdouble weight) {
 		this. = obj;
		this. = weight;
	public T getObject() {
		return ;
	public double getWeight() {
		return ;

Note that equals and compareTo are not consistent: x.compareTo(y)==0 iff x.equals(y) is highly recommended in Java, but is not required. This can make TreeSet etc behave poorly...
	public int compareTo(WeightedObject<T> o) {
		double diff = o.getWeight() - ;
		if (diff>0.0000000000000001) return -1;
		if (diff<-0.0000000000000001) return 1;
		return 0;
true irrespective of weight
	public boolean equals(Object obj) {
		if (!(obj instanceof WeightedObject<?>)) return false;
		if (getObject()==null) {
			return ((WeightedObject<?>)obj).getObject() == null;
else {
			return getObject().equals( ((WeightedObject<?>)obj).getObject() );
	public int hashCode() {
		if (getObject()==nullreturn 234519078;
		return getObject().hashCode();
	public String toString() {
		return ""+getObject()+"["+getWeight()+"]";
New to GrepCode? Check out our FAQ X