/** * Returns whether "types" of the values are exactly the same: type, name, length, precision. * * @param v * Value to compare type against. * * @return == true when types are the same == false when the types differ */ public boolean equalValueType( Value v, boolean checkTypeOnly ) { if ( v == null ) { return false; } if ( getType() != v.getType() ) { return false; } if ( !checkTypeOnly ) { if ( ( getName() == null && v.getName() != null ) || ( getName() != null && v.getName() == null ) || !( getName().equals( v.getName() ) ) ) { return false; } if ( getLength() != v.getLength() ) { return false; } if ( getPrecision() != v.getPrecision() ) { return false; } } return true; }
/** * Search the Value by name in the row, return the Values index. * * @param name * the value name to search for. * @return the index of the value with the given name, -1 is nothing was found. */ public int searchValueIndex( String name ) { if ( name == null ) { return -1; } for ( int i = 0; i < size(); i++ ) { Value v = getValue( i ); if ( v.getName().equalsIgnoreCase( name ) ) { return i; } } return -1; }
/** * Convert the row to a String representation. * * @return the row as a String. */ @Override public String toString() { StringBuilder retval = new StringBuilder( 128 ); retval.append( '[' ); for ( int i = 0; i < size(); i++ ) { Value value = getValue( i ); if ( i != 0 ) { retval.append( ", " ); } if ( value != null ) { retval.append( value.getName() ).append( '=' ).append( value.toString( false ) ); } else { retval.append( "NULL" ); } } retval.append( ']' ); return retval.toString(); }
/** * Search the Value by name in the row. * * @param name * the value name to search for * @return the Value with the given name, null if nothing was found. */ public Value searchValue( String name ) { if ( name == null ) { return null; } for ( int i = 0; i < size(); i++ ) { Value v = getValue( i ); String nm = v.getName(); if ( nm != null && nm.equalsIgnoreCase( name ) ) { return v; } } return null; }
retval.append( v.getName() ).append( '(' ); retval.append( v.getTypeDesc() ); if ( v.getLength() > 0 ) {
/** * Print the names and the String representations of the values of the Values in row to stdout. */ public void print() { int i; for ( i = 0; i < size(); i++ ) { System.out.println( "Element[" + i + "] = [" + getValue( i ).getName() + "] = " + getValue( i ).toString() ); } }
/** * Get an array of the names of all the Values in the Row. * * @return an array of Strings: the names of all the Values in the Row. */ public String[] getFieldNames() { String[] retval = new String[size()]; for ( int i = 0; i < size(); i++ ) { retval[i] = getValue( i ).getName(); } return retval; }
/** * Produce the XML representation of this value. * * @return a String containing the XML to represent this Value. */ @Override public String getXML() { StringBuilder retval = new StringBuilder( 128 ); retval.append( "<" + XML_TAG + ">" ); retval.append( XMLHandler.addTagValue( "name", getName(), false ) ); retval.append( XMLHandler.addTagValue( "type", getTypeDesc(), false ) ); retval.append( XMLHandler.addTagValue( "text", toString( false ), false ) ); retval.append( XMLHandler.addTagValue( "length", getLength(), false ) ); retval.append( XMLHandler.addTagValue( "precision", getPrecision(), false ) ); retval.append( XMLHandler.addTagValue( "isnull", isNull(), false ) ); retval.append( "</" + XML_TAG + ">" ); return retval.toString(); }
/** * Merge the values of row r to this Row. Merge means: only the values that are not yet in the row are added * (comparing on the value name). * * @param r * The row to be merged with this row */ public void mergeRow( Row r ) { if ( r == null ) { return; } for ( int x = 0; x < r.size(); x++ ) { Value field = r.getValue( x ); if ( searchValue( field.getName() ) == null ) { addValue( field ); // Not in list yet: add } } }
/** * Merge the data of row r to this Row. That means: All fields in row r that do exist in this row (same name and same * type) and have non-empty values will have their values written into this row, if the value of that field is empty * in this row. * * @param r * The row to be merged with this row */ public void mergeData( Row r ) { if ( r == null ) { return; } for ( int x = 0; x < r.size(); x++ ) { Value other = r.getValue( x ); Value value = searchValue( other.getName() ); if ( value != null ) { value.merge( other ); } } }
setName( metaData.getName() );
/** * Get an array of strings showing the name of the values in the row padded to a maximum length, followed by the types * of the values. * * @param maxlen * The length to which the name will be padded. * @return an array of strings: the names and the types of the fieldnames in the row. */ public String[] getFieldNamesAndTypes( int maxlen ) { String[] retval = new String[size()]; for ( int i = 0; i < size(); i++ ) { Value v = getValue( i ); retval[i] = Const.rightPad( v.getName(), maxlen ) + " (" + v.getTypeDesc() + ")"; } return retval; }
/** * Constructs a new Value as a copy of another value * * @param v * The Value to be copied */ public Value( Value v ) { if ( v != null ) { // setType(v.getType()); // Is this really needed??? value = v.getValueCopy(); setName( v.getName() ); setLength( v.getLength(), v.getPrecision() ); setNull( v.isNull() ); setOrigin( v.origin ); } else { clearValue(); setNull( true ); } }