private static int[][] makePos( Fields[] fields ) { int[][] pos = new int[ fields.length ][]; for( int i = 0; i < fields.length; i++ ) pos[ i ] = fields[ i ].getPos(); return pos; }
public NarrowTupleList( Fields fields ) { this( fields.getPos(), null ); }
protected TupleBuilder createDefaultNarrowBuilder( final Fields incomingFields, final Fields narrowFields ) { return new TupleBuilder() { int[] pos = incomingFields.getPos( narrowFields ); @Override public Tuple makeResult( Tuple input, Tuple output ) { return createNarrow( pos, input ); } }; }
public final int[] getPos( Fields fields ) { return getPos( fields, -1 ); }
public NarrowTupleList( Fields fields, Tuple base ) { this( fields.getPos(), base ); }
protected TupleBuilder createDefaultNarrowBuilder( final Fields incomingFields, final Fields narrowFields ) { return new TupleBuilder() { Tuple result = createNarrow( incomingFields.getPos( narrowFields ) ); @Override public Tuple makeResult( Tuple input, Tuple output ) { return reset( result, input ); } }; }
private static List<DataField> toDataFields( Fields fields, String[][] categories ) { List<DataField> dataFields = new ArrayList<DataField>(); for( Comparable field : fields ) { if( field instanceof Number ) throw new IllegalArgumentException( "all fields must be names, not ordinal, got: " + field ); dataFields.add( new CategoricalDataField( (String) field, fields.getType( field ), categories[ fields.getPos( field ) ] ) ); } return dataFields; }
/** * Returns the Type at the given position or having the fieldName. * * @param fieldName of type String or Number * @return the Type */ public Type getType( Comparable fieldName ) { if( !hasTypes() ) return null; return getType( getPos( fieldName ) ); }
/** * Method set sets the value in the given field or position. * <p> * No coercion is performed if there is an associated coercible type. * * @param fieldName field name or position to set * @param value of type Comparable */ public void setRaw( Comparable fieldName, Object value ) { tuple.set( fields.getPos( asFieldName( fieldName ) ), value ); }
private static int[][] makePos( Tuple[] bases ) { int[][] pos = new int[ bases.length ][]; for( int i = 0; i < bases.length; i++ ) { Tuple base = bases[ i ]; pos[ i ] = Fields.size( base.size() ).getPos(); } return pos; }
public static Tuple nulledCopy( Fields declarator, Tuple tuple, Fields selector ) { // use tuple.size() in case declarator is UNKNOWN and selector has relative pos return tuple.nulledCopy( declarator.getPos( selector, tuple.size() ) ); }
public static Tuple nulledCopy( TupleEntry tupleEntry, Fields selector ) { return tupleEntry.tuple.nulledCopy( tupleEntry.getFields().getPos( selector, tupleEntry.getFields().size() ) ); }
/** * Method extract creates a new Tuple from the given selector, but sets the values in the current tuple to null. * * @param tupleEntry of type TupleEntry * @param selector of type Fields * @return Tuple */ public static Tuple extract( TupleEntry tupleEntry, Fields selector ) { return tupleEntry.tuple.extract( tupleEntry.getFields().getPos( selector, tupleEntry.getFields().size() ) ); }
public int[] getPos( Fields declarator, Fields selector ) { if( !declarator.isUnknown() && elements.size() != declarator.size() ) throw new TupleException( "field declaration: " + declarator.print() + ", does not match tuple: " + print() ); return declarator.getPos( selector, size() ); }
/** * Method setShort sets the value in the given field or position. * * @param fieldName field name or position to set * @param value of type short */ public void setShort( Comparable fieldName, short value ) { int pos = fields.getPos( asFieldName( fieldName ) ); if( pos > coercions.length - 1 ) throw new TupleException( "position value is too large: " + pos + ", positions in field: " + tuple.size() ); tuple.set( pos, coercions[ pos ].canonical( value ) ); }
/** * Method setFloat sets the value in the given field or position. * * @param fieldName field name or position to set * @param value of type float */ public void setFloat( Comparable fieldName, float value ) { int pos = fields.getPos( asFieldName( fieldName ) ); if( pos > coercions.length - 1 ) throw new TupleException( "position value is too large: " + pos + ", positions in field: " + tuple.size() ); tuple.set( pos, coercions[ pos ].canonical( value ) ); }
/** * Method setDouble sets the value in the given field or position. * * @param fieldName field name or position to set * @param value of type double */ public void setDouble( Comparable fieldName, double value ) { int pos = fields.getPos( asFieldName( fieldName ) ); if( pos > coercions.length - 1 ) throw new TupleException( "position value is too large: " + pos + ", positions in field: " + tuple.size() ); tuple.set( pos, coercions[ pos ].canonical( value ) ); }
protected void set( Fields declarator, Fields selector, Tuple tuple, CoercibleType[] coercions ) { try { set( declarator.getPos( selector ), declarator.getTypes(), tuple, coercions ); } catch( Exception exception ) { throw new TupleException( "unable to set into: " + declarator.print() + ", using selector: " + selector.print(), exception ); } }
/** * Method setLong sets the value in the given field or position. * * @param fieldName field name or position to set * @param value of type long */ public void setLong( Comparable fieldName, long value ) { int pos = fields.getPos( asFieldName( fieldName ) ); if( pos > coercions.length - 1 ) throw new TupleException( "position value is too large: " + pos + ", positions in field: " + tuple.size() ); tuple.set( pos, coercions[ pos ].canonical( value ) ); }
private void useSize( TupleEntry input, TupleEntryCollector outputCollector ) { LOG.debug( "using size: {}", size ); Tuple tuple = new Tuple( input.getTuple() ); // make clone Tuple group = tuple.remove( input.getFields(), groupFieldSelector ); for( int i = 0; i < tuple.size(); i = i + size ) { Tuple result = new Tuple( group ); result.addAll( tuple.get( Fields.offsetSelector( size, i ).getPos() ) ); outputCollector.add( result ); } }