/** * Gets the number of properties held by the instance. * * @return the number of properties held by the instance. */ public final int size() { return this.getProperties().length; }
/** * Creates a string representing the properties of the instance. * * @return a string representing the properties of the instance. */ private String internalString() { final StringBuffer buf = new StringBuffer( 200 ).append( '{' ); buf.append( this.internalString( this ) ); final Property[] props = this.getProperties(); for ( int i = props.length - 1; i >= 0; i-- ) { buf.append( ", [" ).append( i ).append( "]=" ).append( props[i] ); } buf.append( '}' ); return buf.toString(); }
/** * Gets a property for an index. * * @param index the index of the property to return. * * @return a reference to the property at {@code index}. * * @throws IndexOutOfBoundsException if {@code index} is negativ, * greater than or equal to {@code size()}. */ public final Property getProperty( final int index ) { if ( index < 0 || index >= this.size() ) { throw new ArrayIndexOutOfBoundsException( index ); } return this.getProperties()[index]; }
/** * Indicates whether some other object is equal to this one by comparing * the values of all properties. * * @param o the reference object with which to compare. * * @return {@code true} if this object is the same as {@code o}; * {@code false} otherwise. */ public boolean equals( final Object o ) { boolean equal = this == o; if ( !equal && o instanceof Properties ) { final Properties that = (Properties) o; final Collection these = Arrays.asList( this.getProperties() ); final Collection those = Arrays.asList( that.getProperties() ); equal = this.size() == that.size() && these.containsAll( those ); } return equal; }
/** * Creates and returns a deep copy of this object. * * @return a clone of this instance. */ public Object clone() { try { final Properties ret = (Properties) super.clone(); final Property[] props = this.getProperties(); final Property[] cloned = new Property[ props.length ]; for ( int i = props.length - 1; i >= 0; i-- ) { cloned[i] = (Property) props[i].clone(); } ret.setProperties( cloned ); return ret; } catch ( final CloneNotSupportedException e ) { throw new AssertionError( e ); } }
final Collection props = Arrays.asList( this.getProperties() ); props.add( property ); this.setProperties( (Property[]) props.toArray(