All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.talk2object.common.SortableItem Maven / Gradle / Ivy

The newest version!
package com.talk2object.common;

/**
 * a generic sort-able wrapper.
 * 
 * @author jack
 *
 * @param 
 */
public class SortableItem implements Comparable> {

	public T t;
	/**
	 * the value for ordering.
	 */
	public int weight;

	public SortableItem(T t, int weight) {
		this.t = t;
		this.weight = weight;
	}

	@Override
	public int compareTo(SortableItem o) {

		return this.weight - o.weight;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;

		SortableItem si = (SortableItem) obj;
		return compareTo(si) == 0;
	}

	@Override
	public int hashCode() {
		return weight * 31;

	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy