]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/TIntArrayListInternal.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / TIntArrayListInternal.java
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/TIntArrayListInternal.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/TIntArrayListInternal.java
new file mode 100644 (file)
index 0000000..0fa24d4
--- /dev/null
@@ -0,0 +1,1078 @@
+///////////////////////////////////////////////////////////////////////////////\r
+// Copyright (c) 2001, Eric D. Friedman All Rights Reserved.\r
+// Copyright (c) 2009, Rob Eden All Rights Reserved.\r
+// Copyright (c) 2009, Jeff Randall All Rights Reserved.\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Lesser General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2.1 of the License, or (at your option) any later version.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+// GNU General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Lesser General Public\r
+// License along with this program; if not, write to the Free Software\r
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+package org.simantics.db.impl.graph;\r
+\r
+import gnu.trove.TIntCollection;\r
+import gnu.trove.function.TIntFunction;\r
+import gnu.trove.impl.Constants;\r
+import gnu.trove.impl.HashFunctions;\r
+import gnu.trove.iterator.TIntIterator;\r
+import gnu.trove.procedure.TIntProcedure;\r
+\r
+import java.io.IOException;\r
+import java.io.ObjectInput;\r
+import java.io.ObjectOutput;\r
+import java.util.Arrays;\r
+import java.util.Collection;\r
+import java.util.ConcurrentModificationException;\r
+import java.util.NoSuchElementException;\r
+import java.util.Random;\r
+\r
+\r
+//////////////////////////////////////////////////\r
+// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! //\r
+//////////////////////////////////////////////////\r
+\r
+\r
+/**\r
+ * A resizable, array-backed list of int primitives.\r
+ */\r
+public class TIntArrayListInternal {\r
+\r
+    /** the data of the list */\r
+    protected int[] _data;\r
+\r
+    /** the index after the last entry in the list */\r
+    protected int _pos;\r
+\r
+    /** the default capacity for new lists */\r
+    protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY;\r
+\r
+    /** the int value that represents null */\r
+    protected int no_entry_value;\r
+\r
+\r
+    /**\r
+     * Creates a new <code>TIntArrayList</code> instance with the\r
+     * default capacity.\r
+     */\r
+    @SuppressWarnings({"RedundantCast"})\r
+    public TIntArrayListInternal() {\r
+        this( DEFAULT_CAPACITY, ( int ) 0 );\r
+    }\r
+\r
+\r
+    /**\r
+     * Creates a new <code>TIntArrayList</code> instance with the\r
+     * specified capacity.\r
+     *\r
+     * @param capacity an <code>int</code> value\r
+     */\r
+    @SuppressWarnings({"RedundantCast"})\r
+    public TIntArrayListInternal( int capacity ) {\r
+        this( capacity, ( int ) 0 );\r
+    }\r
+\r
+\r
+    /**\r
+     * Creates a new <code>TIntArrayList</code> instance with the\r
+     * specified capacity.\r
+     *\r
+     * @param capacity an <code>int</code> value\r
+     * @param no_entry_value an <code>int</code> value that represents null.\r
+     */\r
+    public TIntArrayListInternal( int capacity, int no_entry_value ) {\r
+        _data = new int[ capacity ];\r
+        _pos = 0;\r
+        this.no_entry_value = no_entry_value;\r
+    }\r
+\r
+    /**\r
+     * Creates a new <code>TIntArrayList</code> instance that contains\r
+     * a copy of the collection passed to us.\r
+     *\r
+     * @param collection the collection to copy\r
+     */\r
+    public TIntArrayListInternal ( TIntCollection collection ) {\r
+        this( collection.size() );\r
+        addAll( collection ); \r
+    }\r
+\r
+\r
+    /**\r
+     * Creates a new <code>TIntArrayList</code> instance whose\r
+     * capacity is the length of <tt>values</tt> array and whose\r
+     * initial contents are the specified values.\r
+     * <p>\r
+     * A defensive copy of the given values is held by the new instance.\r
+     *\r
+     * @param values an <code>int[]</code> value\r
+     */\r
+    public TIntArrayListInternal( int[] values ) {\r
+        this( values.length );\r
+        add( values );\r
+    }\r
+\r
+    protected TIntArrayListInternal(int[] values, int no_entry_value, boolean wrap) {\r
+        if (!wrap)\r
+            throw new IllegalStateException("Wrong call");\r
+\r
+        if (values == null)\r
+            throw new IllegalArgumentException("values can not be null");\r
+\r
+        _data = values;\r
+        _pos = values.length;\r
+        this.no_entry_value = no_entry_value;\r
+    }\r
+\r
+    /**\r
+     * Returns a primitive List implementation that wraps around the given primitive array.\r
+     * <p/>\r
+     * NOTE: mutating operation are allowed as long as the List does not grow. In that case\r
+     * an IllegalStateException will be thrown\r
+     *\r
+     * @param values\r
+     * @return\r
+     */\r
+    public static TIntArrayListInternal wrap(int[] values) {\r
+        return wrap(values, ( int ) 0);\r
+    }\r
+\r
+    /**\r
+     * Returns a primitive List implementation that wraps around the given primitive array.\r
+     * <p/>\r
+     * NOTE: mutating operation are allowed as long as the List does not grow. In that case\r
+     * an IllegalStateException will be thrown\r
+     *\r
+     * @param values\r
+     * @param no_entry_value\r
+     * @return\r
+     */\r
+    public static TIntArrayListInternal wrap(int[] values, int no_entry_value) {\r
+        return new TIntArrayListInternal(values, no_entry_value, true) {\r
+            /**\r
+             * Growing the wrapped external array is not allow\r
+             */\r
+            @Override\r
+            public void ensureCapacity(int capacity) {\r
+                if (capacity > _data.length)\r
+                    throw new IllegalStateException("Can not grow ArrayList wrapped external array");\r
+            }\r
+        };\r
+    }\r
+\r
+    /** {@inheritDoc} */\r
+    public int getNoEntryValue() {\r
+        return no_entry_value;\r
+    }\r
+\r
+\r
+    // sizing\r
+\r
+    /**\r
+     * Grow the internal array as needed to accommodate the specified number of elements.\r
+     * The size of the array bytes on each resize unless capacity requires more than twice\r
+     * the current capacity.\r
+     */\r
+    public void ensureCapacity( int capacity ) {\r
+        if ( capacity > _data.length ) {\r
+            int newCap = Math.max( _data.length << 1, capacity );\r
+            int[] tmp = new int[ newCap ];\r
+            System.arraycopy( _data, 0, tmp, 0, _data.length );\r
+            _data = tmp;\r
+        }\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int sizeInternal() {\r
+        return _pos;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean isEmpty() {\r
+        return _pos == 0;\r
+    }\r
+\r
+\r
+    /**\r
+     * Sheds any excess capacity above and beyond the current size of the list.\r
+     */\r
+    public void trimToSize() {\r
+        if ( _data.length > sizeInternal() ) {\r
+            int[] tmp = new int[ sizeInternal() ];\r
+            toArray( tmp, 0, tmp.length );\r
+            _data = tmp;\r
+        }\r
+    }\r
+\r
+\r
+    // modifying\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean add( int val ) {\r
+        ensureCapacity( _pos + 1 );\r
+        _data[ _pos++ ] = val;\r
+        return true;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void add( int[] vals ) {\r
+        add( vals, 0, vals.length );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void add( int[] vals, int offset, int length ) {\r
+        ensureCapacity( _pos + length );\r
+        System.arraycopy( vals, offset, _data, _pos, length );\r
+        _pos += length;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void insert( int offset, int value ) {\r
+        if ( offset == _pos ) {\r
+            add( value );\r
+            return;\r
+        }\r
+        ensureCapacity( _pos + 1 );\r
+        // shift right\r
+        System.arraycopy( _data, offset, _data, offset + 1, _pos - offset );\r
+        // insert\r
+        _data[ offset ] = value;\r
+        _pos++;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void insert( int offset, int[] values ) {\r
+        insert( offset, values, 0, values.length );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void insert( int offset, int[] values, int valOffset, int len ) {\r
+        if ( offset == _pos ) {\r
+            add( values, valOffset, len );\r
+            return;\r
+        }\r
+\r
+        ensureCapacity( _pos + len );\r
+        // shift right\r
+        System.arraycopy( _data, offset, _data, offset + len, _pos - offset );\r
+        // insert\r
+        System.arraycopy( values, valOffset, _data, offset, len );\r
+        _pos += len;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int getAt( int offset ) {\r
+        if ( offset >= _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException( offset );\r
+        }\r
+        return _data[ offset ];\r
+    }\r
+\r
+\r
+    /**\r
+     * Returns the value at the specified offset without doing any bounds checking.\r
+     */\r
+    public int getQuick( int offset ) {\r
+        return _data[ offset ];\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int set( int offset, int val ) {\r
+        if ( offset >= _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException( offset );\r
+        }\r
+\r
+               int prev_val = _data[ offset ];\r
+        _data[ offset ] = val;\r
+               return prev_val;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int replace( int offset, int val ) {\r
+        if ( offset >= _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException( offset );\r
+        }\r
+        int old = _data[ offset ];\r
+        _data[ offset ] = val;\r
+        return old;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void set( int offset, int[] values ) {\r
+        set( offset, values, 0, values.length );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void set( int offset, int[] values, int valOffset, int length ) {\r
+        if ( offset < 0 || offset + length > _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException( offset );\r
+        }\r
+        System.arraycopy( values, valOffset, _data, offset, length );\r
+    }\r
+\r
+\r
+    /**\r
+     * Sets the value at the specified offset without doing any bounds checking.\r
+     */\r
+    public void setQuick( int offset, int val ) {\r
+        _data[ offset ] = val;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void clear() {\r
+        clear( DEFAULT_CAPACITY );\r
+    }\r
+\r
+\r
+    /**\r
+     * Flushes the internal state of the list, setting the capacity of the empty list to\r
+     * <tt>capacity</tt>.\r
+     */\r
+    public void clear( int capacity ) {\r
+        _data = new int[ capacity ];\r
+        _pos = 0;\r
+    }\r
+\r
+\r
+    /**\r
+     * Sets the size of the list to 0, but does not change its capacity. This method can\r
+     * be used as an alternative to the {@link #clear()} method if you want to recycle a\r
+     * list without allocating new backing arrays.\r
+     */\r
+    public void reset() {\r
+        _pos = 0;\r
+        Arrays.fill( _data, no_entry_value );\r
+    }\r
+\r
+\r
+    /**\r
+     * Sets the size of the list to 0, but does not change its capacity. This method can\r
+     * be used as an alternative to the {@link #clear()} method if you want to recycle a\r
+     * list without allocating new backing arrays. This method differs from\r
+     * {@link #reset()} in that it does not clear the old values in the backing array.\r
+     * Thus, it is possible for getQuick to return stale data if this method is used and\r
+     * the caller is careless about bounds checking.\r
+     */\r
+    public void resetQuick() {\r
+        _pos = 0;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean removeValue( int value ) {\r
+        for ( int index = 0; index < _pos; index++ ) {\r
+            if ( value == _data[index]  ) {\r
+                remove( index, 1 );\r
+                return true;\r
+            }\r
+        }\r
+        return false;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int removeAt( int offset ) {\r
+        int old = getAt( offset );\r
+        remove( offset, 1 );\r
+        return old;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void remove( int offset, int length ) {\r
+               if ( length == 0 ) return;\r
+        if ( offset < 0 || offset >= _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException(offset);\r
+        }\r
+\r
+        if ( offset == 0 ) {\r
+            // data at the front\r
+            System.arraycopy( _data, length, _data, 0, _pos - length );\r
+        }\r
+        else if ( _pos - length == offset ) {\r
+            // no copy to make, decrementing pos "deletes" values at\r
+            // the end\r
+        }\r
+        else {\r
+            // data in the middle\r
+            System.arraycopy( _data, offset + length, _data, offset,\r
+                _pos - ( offset + length ) );\r
+        }\r
+        _pos -= length;\r
+        // no need to clear old values beyond _pos, because this is a\r
+        // primitive collection and 0 takes as much room as any other\r
+        // value\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public TIntIterator iteratorInternal() {\r
+        return new TIntArrayIterator( 0 );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean containsAll( Collection<?> collection ) {\r
+        for ( Object element : collection ) {\r
+            if ( element instanceof Integer ) {\r
+                int c = ( ( Integer ) element ).intValue();\r
+                if ( ! contains( c ) ) {\r
+                    return false;\r
+                }\r
+            } else {\r
+                return false;\r
+            }\r
+\r
+        }\r
+        return true;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean containsAll( TIntCollection collection ) {\r
+        if ( this == collection ) {\r
+            return true;\r
+        }\r
+        TIntIterator iter = collection.iterator();\r
+        while ( iter.hasNext() ) {\r
+            int element = iter.next();\r
+            if ( ! contains( element ) ) {\r
+                return false;\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean containsAll( int[] array ) {\r
+        for ( int i = array.length; i-- > 0; ) {\r
+            if ( ! contains( array[i] ) ) {\r
+                return false;\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
+\r
+//    /** {@inheritDoc} */\r
+//    public boolean addAll( Collection<? extends Integer> collection ) {\r
+//        boolean changed = false;\r
+//        for ( Integer element : collection ) {\r
+//            int e = element.intValue();\r
+//            if ( add( e ) ) {\r
+//                changed = true;\r
+//            }\r
+//        }\r
+//        return changed;\r
+//    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean addAll( TIntCollection collection ) {\r
+        boolean changed = false;\r
+        TIntIterator iter = collection.iterator();\r
+        while ( iter.hasNext() ) {\r
+            int element = iter.next();\r
+            if ( add( element ) ) {\r
+                changed = true;\r
+            }\r
+        }\r
+        return changed;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean addAll( int[] array ) {\r
+        boolean changed = false;\r
+        for ( int element : array ) {\r
+            if ( add( element ) ) {\r
+                changed = true;\r
+            }\r
+        }\r
+        return changed;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    @SuppressWarnings({"SuspiciousMethodCalls"})\r
+    public boolean retainAll( Collection<?> collection ) {\r
+        boolean modified = false;\r
+           TIntIterator iter = iteratorInternal();\r
+           while ( iter.hasNext() ) {\r
+               if ( ! collection.contains( Integer.valueOf ( iter.next() ) ) ) {\r
+                       iter.remove();\r
+                       modified = true;\r
+               }\r
+           }\r
+           return modified;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean retainAll( TIntCollection collection ) {\r
+        if ( this == collection ) {\r
+            return false;\r
+        }\r
+        boolean modified = false;\r
+           TIntIterator iter = iteratorInternal();\r
+           while ( iter.hasNext() ) {\r
+               if ( ! collection.contains( iter.next() ) ) {\r
+                       iter.remove();\r
+                       modified = true;\r
+               }\r
+           }\r
+           return modified;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean retainAll( int[] array ) {\r
+        boolean changed = false;\r
+        Arrays.sort( array );\r
+        int[] data = _data;\r
+\r
+        for ( int i = _pos; i-- > 0; ) {\r
+            if ( Arrays.binarySearch( array, data[i] ) < 0 ) {\r
+                remove( i, 1 );\r
+                changed = true;\r
+            }\r
+        }\r
+        return changed;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean removeAll( Collection<?> collection ) {\r
+        boolean changed = false;\r
+        for ( Object element : collection ) {\r
+            if ( element instanceof Integer ) {\r
+                int c = ( ( Integer ) element ).intValue();\r
+                if ( removeValue( c ) ) {\r
+                    changed = true;\r
+                }\r
+            }\r
+        }\r
+        return changed;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean removeAll( TIntCollection collection ) {\r
+        if ( collection == this ) {\r
+            clear();\r
+            return true;\r
+        }\r
+        boolean changed = false;\r
+        TIntIterator iter = collection.iterator();\r
+        while ( iter.hasNext() ) {\r
+            int element = iter.next();\r
+            if ( removeValue( element ) ) {\r
+                changed = true;\r
+            }\r
+        }\r
+        return changed;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean removeAll( int[] array ) {\r
+        boolean changed = false;\r
+        for ( int i = array.length; i-- > 0; ) {\r
+            if ( removeValue(array[i]) ) {\r
+                changed = true;\r
+            }\r
+        }\r
+        return changed;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void transformValues( TIntFunction function ) {\r
+        for ( int i = _pos; i-- > 0; ) {\r
+            _data[ i ] = function.execute( _data[ i ] );\r
+        }\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void reverse() {\r
+        reverse( 0, _pos );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void reverse( int from, int to ) {\r
+        if ( from == to ) {\r
+            return;             // nothing to do\r
+        }\r
+        if ( from > to ) {\r
+            throw new IllegalArgumentException( "from cannot be greater than to" );\r
+        }\r
+        for ( int i = from, j = to - 1; i < j; i++, j-- ) {\r
+            swap( i, j );\r
+        }\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void shuffle( Random rand ) {\r
+        for ( int i = _pos; i-- > 1; ) {\r
+            swap( i, rand.nextInt( i ) );\r
+        }\r
+    }\r
+\r
+\r
+    /**\r
+     * Swap the values at offsets <tt>i</tt> and <tt>j</tt>.\r
+     *\r
+     * @param i an offset into the data array\r
+     * @param j an offset into the data array\r
+     */\r
+    private void swap( int i, int j ) {\r
+        int tmp = _data[ i ];\r
+        _data[ i ] = _data[ j ];\r
+        _data[ j ] = tmp;\r
+    }\r
+\r
+\r
+    // copying\r
+\r
+//    /** {@inheritDoc} */\r
+//    public TIntList subList( int begin, int end ) {\r
+//     if ( end < begin ) {\r
+//                     throw new IllegalArgumentException( "end index " + end +\r
+//                             " greater than begin index " + begin );\r
+//             }\r
+//             if ( begin < 0 ) {\r
+//                     throw new IndexOutOfBoundsException( "begin index can not be < 0" );\r
+//             }\r
+//             if ( end > _data.length ) {\r
+//                     throw new IndexOutOfBoundsException( "end index < " + _data.length );\r
+//             }\r
+//             TIntArrayListInternal list = new TIntArrayListInternal( end - begin );\r
+//        for ( int i = begin; i < end; i++ ) {\r
+//             list.add( _data[ i ] );\r
+//        }\r
+//        return list;\r
+//    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int[] toArrayInternal() {\r
+        return toArray( 0, _pos );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int[] toArray( int offset, int len ) {\r
+        int[] rv = new int[ len ];\r
+        toArray( rv, offset, len );\r
+        return rv;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int[] toArray( int[] dest ) {\r
+        int len = dest.length;\r
+        if ( dest.length > _pos ) {\r
+            len = _pos;\r
+            dest[len] = no_entry_value;\r
+        }\r
+        toArray( dest, 0, len );\r
+        return dest;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int[] toArray( int[] dest, int offset, int len ) {\r
+        if ( len == 0 ) {\r
+            return dest;             // nothing to copy\r
+        }\r
+        if ( offset < 0 || offset >= _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException( offset );\r
+        }\r
+        System.arraycopy( _data, offset, dest, 0, len );\r
+        return dest;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int[] toArray( int[] dest, int source_pos, int dest_pos, int len ) {\r
+        if ( len == 0 ) {\r
+            return dest;             // nothing to copy\r
+        }\r
+        if ( source_pos < 0 || source_pos >= _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException( source_pos );\r
+        }\r
+        System.arraycopy( _data, source_pos, dest, dest_pos, len );\r
+        return dest;\r
+    }\r
+\r
+\r
+    // comparing\r
+\r
+    /** {@inheritDoc} */\r
+    @Override\r
+    public boolean equals( Object other ) {\r
+        if ( other == this ) {\r
+            return true;\r
+        }\r
+        else if ( other instanceof TIntArrayListInternal ) {\r
+               TIntArrayListInternal that = ( TIntArrayListInternal )other;\r
+            if ( that.sizeInternal() != this.sizeInternal() ) return false;\r
+            else {\r
+                for ( int i = _pos; i-- > 0; ) {\r
+                    if ( this._data[ i ] != that._data[ i ] ) {\r
+                        return false;\r
+                    }\r
+                }\r
+                return true;\r
+            }\r
+        }\r
+        else return false;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    @Override\r
+    public int hashCode() {\r
+        int h = 0;\r
+        for ( int i = _pos; i-- > 0; ) {\r
+            h += HashFunctions.hash( _data[ i ] );\r
+        }\r
+        return h;\r
+    }\r
+\r
+\r
+    // procedures\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean forEach( TIntProcedure procedure ) {\r
+        for ( int i = 0; i < _pos; i++ ) {\r
+            if ( !procedure.execute( _data[ i ] ) ) {\r
+                return false;\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean forEachDescending( TIntProcedure procedure ) {\r
+        for ( int i = _pos; i-- > 0; ) {\r
+            if ( !procedure.execute( _data[ i ] ) ) {\r
+                return false;\r
+            }\r
+        }\r
+        return true;\r
+    }\r
+\r
+\r
+    // sorting\r
+\r
+    /** {@inheritDoc} */\r
+    public void sort() {\r
+        Arrays.sort( _data, 0, _pos );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void sort( int fromIndex, int toIndex ) {\r
+        Arrays.sort( _data, fromIndex, toIndex );\r
+    }\r
+\r
+\r
+    // filling\r
+\r
+    /** {@inheritDoc} */\r
+    public void fill( int val ) {\r
+        Arrays.fill( _data, 0, _pos, val );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public void fill( int fromIndex, int toIndex, int val ) {\r
+        if ( toIndex > _pos ) {\r
+          ensureCapacity( toIndex );\r
+          _pos = toIndex;\r
+        }\r
+        Arrays.fill( _data, fromIndex, toIndex, val );\r
+    }\r
+\r
+\r
+    // searching\r
+\r
+    /** {@inheritDoc} */\r
+    public int binarySearch( int value ) {\r
+        return binarySearch( value, 0, _pos );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int binarySearch(int value, int fromIndex, int toIndex) {\r
+        if ( fromIndex < 0 ) {\r
+            throw new ArrayIndexOutOfBoundsException( fromIndex );\r
+        }\r
+        if ( toIndex > _pos ) {\r
+            throw new ArrayIndexOutOfBoundsException( toIndex );\r
+        }\r
+\r
+        int low = fromIndex;\r
+        int high = toIndex - 1;\r
+\r
+        while ( low <= high ) {\r
+            int mid = ( low + high ) >>> 1;\r
+            int midVal = _data[ mid ];\r
+\r
+            if ( midVal < value ) {\r
+                low = mid + 1;\r
+            }\r
+            else if ( midVal > value ) {\r
+                high = mid - 1;\r
+            }\r
+            else {\r
+                return mid; // value found\r
+            }\r
+        }\r
+        return -( low + 1 );  // value not found.\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int indexOf( int value ) {\r
+        return indexOf( 0, value );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int indexOf( int offset, int value ) {\r
+        for ( int i = offset; i < _pos; i++ ) {\r
+            if ( _data[ i ] == value ) {\r
+                return i;\r
+            }\r
+        }\r
+        return -1;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int lastIndexOf( int value ) {\r
+        return lastIndexOf( _pos, value );\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int lastIndexOf( int offset, int value ) {\r
+        for ( int i = offset; i-- > 0; ) {\r
+            if ( _data[ i ] == value ) {\r
+                return i;\r
+            }\r
+        }\r
+        return -1;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public boolean contains( int value ) {\r
+        return lastIndexOf( value ) >= 0;\r
+    }\r
+\r
+\r
+//    /** {@inheritDoc} */\r
+//    public TIntList grep( TIntProcedure condition ) {\r
+//     TIntArrayListInternal list = new TIntArrayListInternal();\r
+//        for ( int i = 0; i < _pos; i++ ) {\r
+//            if ( condition.execute( _data[ i ] ) ) {\r
+//                list.add( _data[ i ] );\r
+//            }\r
+//        }\r
+//        return list;\r
+//    }\r
+\r
+\r
+//    /** {@inheritDoc} */\r
+//    public TIntList inverseGrep( TIntProcedure condition ) {\r
+//     TIntArrayListInternal list = new TIntArrayListInternal();\r
+//        for ( int i = 0; i < _pos; i++ ) {\r
+//            if ( !condition.execute( _data[ i ] ) ) {\r
+//                list.add( _data[ i ] );\r
+//            }\r
+//        }\r
+//        return list;\r
+//    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int max() {\r
+        if ( sizeInternal() == 0 ) {\r
+            throw new IllegalStateException("cannot find maximum of an empty list");\r
+        }\r
+        int max = Integer.MIN_VALUE;\r
+        for ( int i = 0; i < _pos; i++ ) {\r
+               if ( _data[ i ] > max ) {\r
+                       max = _data[ i ];\r
+               }\r
+        }\r
+        return max;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int min() {\r
+        if ( sizeInternal() == 0 ) {\r
+            throw new IllegalStateException( "cannot find minimum of an empty list" );\r
+        }\r
+        int min = Integer.MAX_VALUE;\r
+        for ( int i = 0; i < _pos; i++ ) {\r
+               if ( _data[i] < min ) {\r
+                       min = _data[i];\r
+               }\r
+        }\r
+        return min;\r
+    }\r
+\r
+\r
+    /** {@inheritDoc} */\r
+    public int sum() {\r
+        int sum = 0;\r
+        for ( int i = 0; i < _pos; i++ ) {\r
+                       sum += _data[ i ];\r
+        }\r
+        return sum;\r
+    }\r
+\r
+\r
+    // stringification\r
+\r
+    /** {@inheritDoc} */\r
+    @Override\r
+    public String toString() {\r
+        final StringBuilder buf = new StringBuilder( "{" );\r
+        for ( int i = 0, end = _pos - 1; i < end; i++ ) {\r
+            buf.append( _data[ i ] );\r
+            buf.append( ", " );\r
+        }\r
+        if ( sizeInternal() > 0 ) {\r
+            buf.append( _data[ _pos - 1 ] );\r
+        }\r
+        buf.append( "}" );\r
+        return buf.toString();\r
+    }\r
+\r
+\r
+    /** TIntArrayList iterator */\r
+    class TIntArrayIterator implements TIntIterator {\r
+\r
+        /** Index of element to be returned by subsequent call to next. */\r
+        private int cursor = 0;\r
+\r
+        /**\r
+         * Index of element returned by most recent call to next or\r
+         * previous.  Reset to -1 if this element is deleted by a call\r
+         * to remove.\r
+         */\r
+        int lastRet = -1;\r
+\r
+\r
+        TIntArrayIterator( int index ) {\r
+            cursor = index;\r
+        }\r
+\r
+\r
+        /** {@inheritDoc} */\r
+        public boolean hasNext() {\r
+            return cursor < sizeInternal();\r
+           }\r
+\r
+\r
+        /** {@inheritDoc} */\r
+        public int next() {\r
+            try {\r
+                int next = getAt( cursor );\r
+                lastRet = cursor++;\r
+                return next;\r
+            } catch ( IndexOutOfBoundsException e ) {\r
+                throw new NoSuchElementException();\r
+            }\r
+        }\r
+\r
+\r
+        /** {@inheritDoc} */\r
+        public void remove() {\r
+            if ( lastRet == -1 )\r
+                       throw new IllegalStateException();\r
+\r
+            try {\r
+               TIntArrayListInternal.this.remove( lastRet, 1);\r
+                if ( lastRet < cursor )\r
+                    cursor--;\r
+                lastRet = -1;\r
+            } catch ( IndexOutOfBoundsException e ) {\r
+                throw new ConcurrentModificationException();\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+    public void writeExternal( ObjectOutput out ) throws IOException {\r
+       // VERSION\r
+       out.writeByte( 0 );\r
+\r
+       // POSITION\r
+       out.writeInt( _pos );\r
+\r
+       // NO_ENTRY_VALUE\r
+       out.writeInt( no_entry_value );\r
+\r
+       // ENTRIES\r
+       int len = _data.length;\r
+       out.writeInt( len );\r
+       for( int i = 0; i < len; i++ ) {\r
+               out.writeInt( _data[ i ] );\r
+       }\r
+    }\r
+\r
+\r
+    public void readExternal( ObjectInput in )\r
+       throws IOException, ClassNotFoundException {\r
+\r
+       // VERSION\r
+       in.readByte();\r
+\r
+       // POSITION\r
+       _pos = in.readInt();\r
+\r
+       // NO_ENTRY_VALUE\r
+       no_entry_value = in.readInt();\r
+\r
+       // ENTRIES\r
+       int len = in.readInt();\r
+       _data = new int[ len ];\r
+       for( int i = 0; i < len; i++ ) {\r
+               _data[ i ] = in.readInt();\r
+       }\r
+    }\r
+} // TIntArrayList\r