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

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

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

Tuple.getLong介绍

[英]Method getLong returns the element at the given position as an long. Zero if null.
[中]方法getLong将给定位置的元素作为long返回。如果为空,则为零。

代码示例

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

/**
 * Method posToLong returns the long value at the given tuple position.
 *
 * @param pos the ordinal position to select from
 * @return the value in the given ordinal position
 */
public static ToLongFunction<Tuple> posToLong( int pos )
 {
 return value -> value.getLong( pos );
 }

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

@Override
public Tuple aggregate( FlowProcess flowProcess, TupleEntry args, Tuple context )
 {
 if( context == null )
  context = Tuple.size( 2 );
 if( include == Include.NO_NULLS && args.getObject( 0 ) == null )
  return context;
 context.set( 0, context.getDouble( 0 ) + args.getDouble( 0 ) );
 context.set( 1, context.getLong( 1 ) + 1 );
 return context;
 }

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

private void validateCase( String test, Boolean[] testCase, Tap sink ) throws IOException
 {
 TupleEntryIterator iterator = sink.openForRead( getPlatform().getFlowProcess() );
 LinkedHashMap<Long, List<String>> group = new LinkedHashMap<Long, List<String>>();
 while( iterator.hasNext() )
  {
  Tuple tuple = iterator.next().getTuple();
  if( !group.containsKey( tuple.getLong( 0 ) ) )
   group.put( tuple.getLong( 0 ), new ArrayList<String>() );
  group.get( tuple.getLong( 0 ) ).add( tuple.getString( 2 ) );
  }
 boolean groupIsReversed = testCase[ 0 ];
 if( testCase[ 2 ] )
  groupIsReversed = !groupIsReversed;
 compare( "grouping+" + test, groupIsReversed, group.keySet() );
 if( testCase[ 1 ] == null )
  return;
 boolean valueIsReversed = testCase[ 1 ];
 if( testCase[ 2 ] )
  valueIsReversed = !valueIsReversed;
 for( Long grouping : group.keySet() )
  compare( "values+" + test, valueIsReversed, group.get( grouping ) );
 }

代码示例来源:origin: cascading/cascading-platform

private void validateCase( String test, Boolean[] testCase, Tap sink ) throws IOException
 {
 TupleEntryIterator iterator = sink.openForRead( getPlatform().getFlowProcess() );
 LinkedHashMap<Long, List<String>> group = new LinkedHashMap<Long, List<String>>();
 while( iterator.hasNext() )
  {
  Tuple tuple = iterator.next().getTuple();
  if( !group.containsKey( tuple.getLong( 0 ) ) )
   group.put( tuple.getLong( 0 ), new ArrayList<String>() );
  group.get( tuple.getLong( 0 ) ).add( tuple.getString( 2 ) );
  }
 boolean groupIsReversed = testCase[ 0 ];
 if( testCase[ 2 ] )
  groupIsReversed = !groupIsReversed;
 compare( "grouping+" + test, groupIsReversed, group.keySet() );
 if( testCase[ 1 ] == null )
  return;
 boolean valueIsReversed = testCase[ 1 ];
 if( testCase[ 2 ] )
  valueIsReversed = !valueIsReversed;
 for( Long grouping : group.keySet() )
  compare( "values+" + test, valueIsReversed, group.get( grouping ) );
 }

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

@Override
public Tuple aggregate( FlowProcess flowProcess, TupleEntry args, Tuple context )
 {
 if( context == null )
  context = new Tuple( 0L );
 switch( include )
  {
  case ALL:
   break;
  case NO_NULLS:
   if( Tuples.frequency( args, null ) == args.size() )
    return context;
   break;
  case ONLY_NULLS:
   if( Tuples.frequency( args, null ) != args.size() )
    return context;
   break;
  }
 context.set( 0, context.getLong( 0 ) + 1L );
 return context;
 }

代码示例来源:origin: cascading/cascading-platform

private void validateFile( Tap tap, int length, int uniqueValues, boolean isReversed, int comparePosition ) throws IOException, ParseException
 {
 TupleEntryIterator iterator = tap.openForRead( getPlatform().getFlowProcess() );
 Set<Long> values = new HashSet<Long>();
 long lastValue = isReversed ? Long.MAX_VALUE : Long.MIN_VALUE;
 int count = 0;
 while( iterator.hasNext() )
  {
  Tuple tuple = iterator.next().getTuple();
  count++;
  tuple = new Tuple( (Object[]) tuple.getString( 1 ).split( "\t" ) );
  long value = tuple.getLong( comparePosition );
  values.add( value );
  if( isReversed )
   assertTrue( "out of order in " + tap, lastValue >= value );
  else
   assertTrue( "out of order in " + tap, lastValue <= value );
  lastValue = value;
  }
 if( length != -1 )
  assertEquals( "length of " + tap, length, count );
 if( uniqueValues != -1 )
  assertEquals( "unique values of " + tap, uniqueValues, values.size() );
 }
}

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

private void validateFile( Tap tap, int length, int uniqueValues, boolean isReversed, int comparePosition ) throws IOException, ParseException
 {
 TupleEntryIterator iterator = tap.openForRead( getPlatform().getFlowProcess() );
 Set<Long> values = new HashSet<Long>();
 long lastValue = isReversed ? Long.MAX_VALUE : Long.MIN_VALUE;
 int count = 0;
 while( iterator.hasNext() )
  {
  Tuple tuple = iterator.next().getTuple();
  count++;
  tuple = new Tuple( (Object[]) tuple.getString( 1 ).split( "\t" ) );
  long value = tuple.getLong( comparePosition );
  values.add( value );
  if( isReversed )
   assertTrue( "out of order in " + tap, lastValue >= value );
  else
   assertTrue( "out of order in " + tap, lastValue <= value );
  lastValue = value;
  }
 if( length != -1 )
  assertEquals( "length of " + tap, length, count );
 if( uniqueValues != -1 )
  assertEquals( "unique values of " + tap, uniqueValues, values.size() );
 }
}

相关文章