org.fuzzydb.util.TupleKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.fuzzydb.util Show documentation
Show all versions of org.fuzzydb.util Show documentation
Contains classes not specific to fuzzydb implementation which
could be used in any implementation of fuzzy matching, or as
general utility classes such as those in the geo package.
The newest version!
/******************************************************************************
* Copyright (c) 2004-2008 Whirlwind Match Limited. All rights reserved.
*
* This is open source software; you can use, redistribute and/or modify
* it under the terms of the Open Software Licence v 3.0 as published by the
* Open Source Initiative.
*
* You should have received a copy of the Open Software Licence along with this
* application. if not, contact the Open Source Initiative (www.opensource.org)
*****************************************************************************/
package org.fuzzydb.util;
/**
* Class for creating a Comparable key based on two objects, which can
* then be used in sorted collections.
* @author Neale
*
* @param
* @param
*/
public class TupleKey implements Comparable> {
private A objectA;
private B objectB;
public TupleKey(A objectA, B objectB) {
super();
this.objectA = objectA;
this.objectB = objectB;
}
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(TupleKey rhs) {
if ( rhs.objectB.equals(objectB) ) {
if ( rhs.objectA.equals(objectA) )
return 0;
else
return objectA.hashCode() - rhs.objectA.hashCode();
} else
return objectB.hashCode() - rhs.objectB.hashCode();
}
@Override
public int hashCode() {
return objectA.hashCode() + objectB.hashCode();
}
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object o) {
TupleKey rhs = (TupleKey)o;
return objectA.equals(rhs.objectA) && objectB.equals(rhs.objectB);
}
public A getObjectA() {
return objectA;
}
public B getObjectB() {
return objectB;
}
}