cascading.tuple.Tuple.compareTo()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中cascading.tuple.Tuple.compareTo()方法的一些代码示例,展示了Tuple.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple.compareTo()方法的具体详情如下:
包路径:cascading.tuple.Tuple
类名称:Tuple
方法名:compareTo

Tuple.compareTo介绍

[英]Method compareTo compares this Tuple to the given Tuple instance.
[中]方法compareTo将此元组与给定的元组实例进行比较。

代码示例

代码示例来源:origin: cwensel/cascading

public int compareTo( IndexTuple indexTuple )
 {
 int c = this.index - indexTuple.index;
 if( c != 0 )
  return c;
 return this.tuple.compareTo( indexTuple.tuple );
 }

代码示例来源:origin: cwensel/cascading

@Override
public int compare( Tuple lhs, Tuple rhs )
 {
 return lhs.compareTo( comparators, rhs );
 }

代码示例来源:origin: cwensel/cascading

/**
 * 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;
 }

代码示例来源:origin: cwensel/cascading

/**
 * 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;
 }

代码示例来源:origin: cwensel/cascading

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;
 }

代码示例来源:origin: cwensel/cascading

@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" ) );
 }

代码示例来源:origin: cwensel/cascading

@Test
public void testCompareNull()
 {
 Tuple aTuple = new Tuple( "a", null, "c" );
 Tuple bTuple = new Tuple( "a", "b", null );
 assertTrue( "not less than: aTuple < bTuple", aTuple.compareTo( bTuple ) < 0 );
 assertTrue( "not less than: bTuple < aTuple", bTuple.compareTo( aTuple ) > 0 );
 }

代码示例来源:origin: cwensel/cascading

@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 );
 }

代码示例来源:origin: cwensel/cascading

@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 );
 }

代码示例来源:origin: cwensel/cascading

@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 );
 }

代码示例来源:origin: cascading/cascading-hadoop2-common

@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 );
 }
}

代码示例来源:origin: cwensel/cascading

@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 );
 }
}

相关文章