package biz.mbisoftware.fn.wstypes; import biz.mbisoftware.common.Constants; /** * Wrapper class for an array of string arrays. */ public class StringArrayArray { /** The encapsulated value of this object. */ private StringArray[] value; /** * The default parameterless constructor. */ public StringArrayArray( ) { } /** * A constructor with assignment of the value attribute. * @param value The value to store. */ public StringArrayArray( final StringArray[] value ) { this.value = value; } /** * Get the current value. * @return The current value. */ public StringArray[] getValue() { return this.value; } /** * Set the value attribute to a new value. * @param value The new value. */ public void setValue( final StringArray[] value ) { this.value = value; } /** * Get the value from an String[][]. * @param source the source to get the data from */ public void fromArray( final String[][] source ) { if ( source == null ) { this.value = null; } else { this.value = new StringArray[source.length]; for ( int i = 0; i < source.length; i++ ) { this.value[i] = new StringArray( source[i] ); } } } /** * Get the value attribute of this object in String[][] format. * @return returns the value as an String[][] */ public String[][] to2DArray() { String[][] saa; int width = 0; int height = 0; if ( this.value != null ) { height = this.value.length; for ( int i = 0; i < height; i++ ) { String[] row; if ( this.value[i] == null ) { row = null; } else { row = this.value[i].getValue(); } if ( row != null && row.length > width ) { width = row.length; } } } saa = new String[height][width]; for ( int l = 0; l < height; l++ ) { if ( this.value[l] != null ) { String [] row = this.value[l].getValue(); if ( row != null ) { for ( int c = 0; c < row.length; c++ ) { saa[l][c] = row[c]; } } } } return saa; } /** * @see Object#toString() * @return a string representation of the object. */ public String toString() { StringBuilder sb = new StringBuilder( Constants.DEFAULT_STRING_BUFFER_SIZE ); sb.append( '[' ); if ( this.value == null ) { sb.append( "null" ); } else { for ( int row = 0; row < this.value.length; row++ ) { if ( this.value[row] == null ) { sb.append( "null" ); } else { sb.append( this.value[row].toString() ); } if ( row < this.value.length - 1 ) { sb.append( ',' ); } } } sb.append( ']' ); return sb.toString(); } }