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

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

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

Tuple.add介绍

[英]Method add adds a new element value to this instance.
[中]方法add向该实例添加新元素值。

代码示例

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

/**
 * Method add adds a new element value to this instance.
 *
 * @param value of type Comparable
 */
public void add( Comparable value )
 {
 add( (Object) value );
 }

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

/**
 * Creates a new Tuple from the given positions, but sets the values in the current tuple to null.
 *
 * @param pos of type int[]
 * @return Tuple
 */
Tuple extract( int[] pos )
 {
 Tuple results = new Tuple();
 for( int i : pos )
  results.add( elements.set( i, null ) );
 return results;
 }

代码示例来源:origin: cascading/cascading-jdbc-core

public void readFields( ResultSet resultSet ) throws SQLException
 {
 tuple = new Tuple();
 for( int i = 0; i < resultSet.getMetaData().getColumnCount(); i++ )
  tuple.add( resultSet.getObject( i + 1 ) );
 }

代码示例来源:origin: LiveRamp/cascading_ext

@Override
public Tuple toTuple(Number[] values) {
 Tuple tuple = new Tuple();
 for (Number value : values) {
  tuple.add(value);
 }
 return tuple;
}

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

private void addGroupsToTuple( Matcher matcher, TupleEntry output, int count )
 {
 Tuple tuple = output.getTuple();
 tuple.clear();
 if( count == 0 )
  {
  tuple.add( matcher.group( 0 ) );
  }
 else
  {
  for( int i = 0; i < count; i++ )
   tuple.add( matcher.group( i + 1 ) ); // skip group 0
  }
 }

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

/**
 * Method size returns a new Tuple instance of the given size with the given Comparable as its element values.
 *
 * @param size  of type int
 * @param value of type Comparable
 * @return Tuple
 */
public static Tuple size( int size, Comparable value )
 {
 Tuple result = new Tuple( new ArrayList<Object>( size ) );
 for( int i = 0; i < size; i++ )
  result.add( value );
 return result;
 }

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

private TupleEntry getDiagnostics( Throwable throwable )
 {
 if( !recordAnyDiagnostics )
  return TupleEntry.NULL;
 Tuple diagnostics = new Tuple();
 if( recordElementTrace )
  diagnostics.add( elementTrace );
 if( recordThrowableMessage )
  diagnostics.add( throwable.getMessage() );
 if( recordThrowableStackTrace )
  diagnostics.add( TraceUtil.stringifyStackTrace( throwable, stackTraceLineDelimiter, stackTraceTrimLine, -1 ) );
 diagnosticEntry.setTuple( diagnostics );
 return diagnosticEntry;
 }

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

@Override
public void setUp() throws Exception
 {
 super.setUp();
 tuple = new Tuple();
 tuple.add( "a" );
 tuple.add( "b" );
 tuple.add( "c" );
 tuple.add( "d" );
 tuple.add( "d" );
 }

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

@Override
public void setUp() throws Exception
 {
 tuple = new Tuple();
 tuple.add( "a" );
 tuple.add( "b" );
 tuple.add( "c" );
 tuple.add( "d" );
 tuple.add( "d" );
 fields = new Fields( "one", "two", "three", "four", "five" );
 }

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

/**
 * Method get will return a new Tuple instance populated with element values from the given array of positions.
 *
 * @param pos of type int[]
 * @return Tuple
 */
public Tuple get( int[] pos )
 {
 if( pos == null || pos.length == 0 )
  return new Tuple( this );
 Tuple results = new Tuple();
 for( int i : pos )
  results.add( elements.get( i ) );
 return results;
 }

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

protected void performOperation( Tuple[] context, TupleEntry entry )
 {
 if( context[ 0 ] == null )
  context[ 0 ] = new Tuple();
 if( context[ 0 ].size() < firstN )
  context[ 0 ].add( entry.getTupleCopy() );
 }

代码示例来源:origin: stackoverflow.com

public class SampleFunction extends BaseOperation implements Function
{
   public void operate( FlowProcess flowProcess, FunctionCall functionCall )
   {
     TupleEntry argument = functionCall.getArguments();
     String regex = argument.getString( 0 );
     String argument = argument.getString( 1 );
     String parsed = someRegexOperation();

     Tuple result = new Tuple();
     result.add( parsed );
     functionCall.getOutputCollector().add( result );
   }
}

代码示例来源:origin: com.backtype/dfs-datastores-cascading

@Override
public boolean source(FlowProcess<JobConf> flowProcess,
  SourceCall<Object[], RecordReader> sourceCall) throws IOException {
 BytesWritable key = (BytesWritable) sourceCall.getContext()[0];
 BytesWritable value = (BytesWritable) sourceCall.getContext()[1];
 boolean result = sourceCall.getInput().next(key, value);
 if (!result) { return false; }
 Tuple tuple = sourceCall.getIncomingEntry().getTuple();
 tuple.clear();
 tuple.add(getBytes(key));
 tuple.add(getBytes(value));
 return true;
}

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

static Tuple parse( String string )
 {
 if( string == null || string.length() == 0 )
  return null;
 string = string.replaceAll( "^ *\\[*", "" );
 string = string.replaceAll( "\\]* *$", "" );
 Scanner scanner = new Scanner( new StringReader( string ) );
 scanner.useDelimiter( "(' *, *')|(^ *')|(' *$)" );
 Tuple result = new Tuple();
 while( scanner.hasNext() )
  {
  if( scanner.hasNextInt() )
   result.add( scanner.nextInt() );
  else if( scanner.hasNextDouble() )
   result.add( scanner.nextDouble() );
  else
   result.add( scanner.next() );
  }
 scanner.close();
 return result;
 }

代码示例来源:origin: com.twitter/scalding-commons

@Override
public boolean source(FlowProcess<JobConf> flowProcess,
  SourceCall<Object[], RecordReader> sourceCall) throws IOException {
 BytesWritable key = (BytesWritable) sourceCall.getContext()[0];
 BytesWritable value = (BytesWritable) sourceCall.getContext()[1];
 boolean result = sourceCall.getInput().next(key, value);
 if (!result) { return false; }
 Tuple tuple = sourceCall.getIncomingEntry().getTuple();
 tuple.clear();
 tuple.add(getBytes(key));
 tuple.add(getBytes(value));
 return true;
}

代码示例来源:origin: sujitpal/hia-examples

@Override
public void operate(FlowProcess flowProcess, FunctionCall funCall) {
 TupleEntry args = funCall.getArguments();
 String keyword = args.getString(0);
 List<String> urls = parseSearchResult(keyword);
 for (String url : urls) {
  Tuple t = new Tuple();
  t.add(url);
  funCall.getOutputCollector().add(t);
 }
}

代码示例来源:origin: sujitpal/hia-examples

@Override
public void operate(FlowProcess flowProcess, FunctionCall funCall) {
 TupleEntry args = funCall.getArguments();
 String url = args.getString(1);
 String rawText = download(url);
 String plainText = parse(rawText);
 List<String> keywords = extractKeywords(plainText);
 for (String keyword : keywords) {
  Tuple t = new Tuple();
  t.add(keyword);
  funCall.getOutputCollector().add(t);
 }
}

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

@Test
public void testCompare()
 {
 Fields fields = new Fields( "a" );
 fields.setComparator( "a", comparator );
 Tuple aTuple = new Tuple( "a" );
 Tuple bTuple = new Tuple( "b" );
 assertTrue( "not less than: aTuple < bTuple", fields.compare( aTuple, bTuple ) < 0 );
 assertTrue( "not less than: bTuple < aTuple", fields.compare( bTuple, aTuple ) > 0 );
 aTuple.add( "b" );
 assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 0 );
 aTuple = new Tuple( bTuple, "a" );
 assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 0 );
 }

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

@Test
public void testCompare2()
 {
 Fields fields = new Fields( "a" );
 fields.setComparators( new Comparator[]{comparator} );
 Tuple aTuple = new Tuple( "a" );
 Tuple bTuple = new Tuple( "b" );
 assertTrue( "not less than: aTuple < bTuple", fields.compare( aTuple, bTuple ) < 0 );
 assertTrue( "not less than: bTuple < aTuple", fields.compare( bTuple, aTuple ) > 0 );
 aTuple.add( "b" );
 assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 0 );
 aTuple = new Tuple( bTuple, "a" );
 assertTrue( "not greater than: aTuple > bTuple", fields.compare( aTuple, bTuple ) > 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 );
 }

相关文章