package votorola.g.util; // Copyright 2008, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import java.util.*; import votorola.g.lang.*; /** An unmodifiable list backed by an array. It is unmodifiable in the sense that clients * are provided no means to access and modify the array. Modification of the array by * other means will still affect the list. The list is actually serializeable only if * its elements are serializeable. */ public @ThreadSafe class ArrayListU extends AbstractList implements java.io.Serializable { /** Contructs an ArrayListU. */ public ArrayListU( E[] _backingArray ) { if( _backingArray == null ) throw new NullPointerException(); // fail fast backingArray = _backingArray; } // - C o l l e c t i o n -------------------------------------------------------------- public @Override int size() { return backingArray.length; } // - L i s t -------------------------------------------------------------------------- public @Override E get( int index ) { return backingArray[index]; } // ==================================================================================== /** An unmodifiable list that provides open access to the backing array. */ public static @ThreadRestricted("touch") final class Open extends ArrayListU { /** Contructs an ArrayListU.Open. * * @param backingArray per {@linkplain #getBackingArray getBackingArray}() */ public Open( E[] backingArray ) { super( backingArray ); } // -------------------------------------------------------------------------------- /** Returns the array that backs this list. * * @return non-null array * * @see #setBackingArray(Object[]) */ public E[] getBackingArray() { return backingArray; } /** Sets the array that backs this list. * * @see #getBackingArray() */ public void setBackingArray( final E[] newBackingArray ) { if( newBackingArray == null ) throw new NullPointerException(); // fail fast backingArray = newBackingArray; } } //// P r i v a t e /////////////////////////////////////////////////////////////////////// protected E[] backingArray; }