public int compareTo( IndexTuple indexTuple ) { int c = this.index - indexTuple.index; if( c != 0 ) return c; return this.tuple.compareTo( indexTuple.tuple ); }
@Override public int compare( Tuple lhs, Tuple rhs ) { return lhs.compareTo( comparators, rhs ); }
/** * Method compareTo implements the {@link Comparable#compareTo(Object)} method. * * @param other of type Object * @return int */ public int compareTo( Object other ) { if( other instanceof Tuple ) return compareTo( (Tuple) other ); else return -1; }
/** * Method compareTo compares this instance to the given TuplePair. * * @param tuplePair of type TuplePair * @return int */ public int compareTo( TuplePair tuplePair ) { int c = tuples[ 0 ].compareTo( tuplePair.tuples[ 0 ] ); if( c != 0 ) return c; c = tuples[ 1 ].compareTo( tuplePair.tuples[ 1 ] ); return c; }
public int compareTo( Comparator[] comparators, Tuple other ) { if( comparators == null ) return compareTo( other ); if( other == null || other.elements == null ) return 1; if( other.elements.size() != this.elements.size() ) return this.elements.size() - other.elements.size(); if( comparators.length != this.elements.size() ) throw new IllegalArgumentException( "comparator array not same size as tuple elements" ); for( int i = 0; i < this.elements.size(); i++ ) { Object lhs = this.elements.get( i ); Object rhs = other.elements.get( i ); int c; if( comparators[ i ] != null ) c = comparators[ i ].compare( lhs, rhs ); else if( lhs == null && rhs == null ) c = 0; else if( lhs == null ) return -1; else if( rhs == null ) return 1; else c = ( (Comparable) lhs ).compareTo( rhs ); // guaranteed to not be null if( c != 0 ) return c; } return 0; }
@Test public void testCompare4() { Tuple aTuple = new Tuple( "Just My Luck", "ClaudiaPuig", null, "LisaRose", null ); Tuple bTuple = new Tuple( "Just My Luck", "ClaudiaPuig", null, "LisaRose", null ); assertEquals( "not equal: aTuple", bTuple, aTuple ); assertTrue( "not equal than: aTuple = bTuple", aTuple.compareTo( bTuple ) == 0 ); bTuple = new Tuple( "Just My Luck", "ClaudiaPuig", null, "Z", null ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) == "LisaRose".compareTo( "Z" ) ); assertTrue( "not less than: bTuple > aTuple", bTuple.compareTo( aTuple ) == "Z".compareTo( "LisaRose" ) ); }
@Test public void testCompare() { Tuple aTuple = new Tuple( "a" ); Tuple bTuple = new Tuple( "b" ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) < 0 ); assertTrue( "not less than: bTuple < aTuple", bTuple.compareTo( aTuple ) > 0 ); aTuple.add( "b" ); assertTrue( "not greater than: aTuple > bTuple", aTuple.compareTo( bTuple ) > 0 ); aTuple = new Tuple( bTuple, "a" ); assertTrue( "not greater than: aTuple > bTuple", aTuple.compareTo( bTuple ) > 0 ); bTuple = new Tuple( bTuple, "b" ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) < 0 ); }
@Test public void testCompare2() { Tuple aTuple = new Tuple( "Just My Luck", "ClaudiaPuig", "3.0", "LisaRose", "3.0" ); Tuple bTuple = new Tuple( "Just My Luck", "ClaudiaPuig", "3.0", "LisaRose", "3.0" ); assertEquals( "not equal: aTuple", bTuple, aTuple ); assertTrue( "not equal than: aTuple = bTuple", aTuple.compareTo( bTuple ) == 0 ); bTuple = new Tuple( "Just My Luck", "ClaudiaPuig", "3.0", "LisaRose", "2.0" ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) > 0 ); assertTrue( "not less than: bTuple > aTuple", bTuple.compareTo( aTuple ) < 0 ); }
@Test public void testCompare3() { Tuple aTuple = new Tuple( "Just My Luck", "ClaudiaPuig", 3.0, "LisaRose", 3.0 ); Tuple bTuple = new Tuple( "Just My Luck", "ClaudiaPuig", 3.0, "LisaRose", 3.0 ); assertEquals( "not equal: aTuple", bTuple, aTuple ); assertTrue( "not equal than: aTuple = bTuple", aTuple.compareTo( bTuple ) == 0 ); bTuple = new Tuple( "Just My Luck", "ClaudiaPuig", 3.0, "LisaRose", 2.0 ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) > 0 ); assertTrue( "not less than: bTuple > aTuple", bTuple.compareTo( aTuple ) < 0 ); }
@Test public void testWritableCompare() { Tuple aTuple = new Tuple( new TestWritableComparable( "Just My Luck" ), "ClaudiaPuig", "3.0", "LisaRose", "3.0" ); Tuple bTuple = new Tuple( new TestWritableComparable( "Just My Luck" ), "ClaudiaPuig", "3.0", "LisaRose", "3.0" ); assertEquals( "not equal: aTuple", bTuple, aTuple ); assertTrue( "not equal than: aTuple = bTuple", aTuple.compareTo( bTuple ) == 0 ); bTuple = new Tuple( new TestWritableComparable( "Just My Luck" ), "ClaudiaPuig", "3.0", "LisaRose", "2.0" ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) > 0 ); } }
@Test public void testWritableCompare() { Tuple aTuple = new Tuple( new TestWritableComparable( "Just My Luck" ), "ClaudiaPuig", "3.0", "LisaRose", "3.0" ); Tuple bTuple = new Tuple( new TestWritableComparable( "Just My Luck" ), "ClaudiaPuig", "3.0", "LisaRose", "3.0" ); assertEquals( "not equal: aTuple", bTuple, aTuple ); assertTrue( "not equal than: aTuple = bTuple", aTuple.compareTo( bTuple ) == 0 ); bTuple = new Tuple( new TestWritableComparable( "Just My Luck" ), "ClaudiaPuig", "3.0", "LisaRose", "2.0" ); assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) > 0 ); } }