001    package com.softnetConsult.utils.collections;
002    
003    import java.util.ArrayList;
004    import java.util.Collection;
005    
006    
007    /**
008     * Extends the default Java {@code ArrayList} by exposing its already present
009     * method {@code removeRange} for public access. 
010     * 
011     * <p style="font-size:smaller;">This product includes software developed by the
012     *    <strong>SoftNet-Consult Java Utility Library</strong> project and its contributors.<br />
013     *    (<a href="http://java-tools.sourceforge.net" target="_blank">http://java-tools.sourceforge.net</a>)<br />
014     *    Copyright (c) 2007-2008 SoftNet-Consult.<br />
015     *    Copyright (c) 2007-2008 G. Paperin.<br />
016     *    All rights reserved.
017     * </p>
018     * <p style="font-size:smaller;">File: ArrayListRemovableRange.java<br />
019     *    Library API version: {@value com.softnetConsult.utils.APIProperties#apiVersion}<br />
020     *    Java compliance version: {@value com.softnetConsult.utils.APIProperties#javaComplianceVersion}
021     * </p>
022     * <p style="font-size:smaller;">Redistribution and use in source and binary forms, with or
023     *    without modification, are permitted provided that the following terms and conditions are met:
024     * </p>
025     * <p style="font-size:smaller;">1. Redistributions of source code must retain the above
026     *    acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
027     *    notice, this list of conditions and the following disclaimer.<br />
028     *    2. Redistributions in binary form must reproduce the above acknowledgement of the
029     *    SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
030     *    conditions and the following disclaimer in the documentation and/or other materials
031     *    provided with the distribution.<br />
032     *    3. All advertising materials mentioning features or use of this software or any derived
033     *    software must display the following acknowledgement:<br />
034     *    <em>This product includes software developed by the SoftNet-Consult Java Utility Library
035     *    project and its contributors.</em>
036     * </p>
037     * <p style="font-size:smaller;">THIS SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY
038     *    OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
039     *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  NONINFRINGEMENT. IN NO EVENT SHALL
040     *    THE AUTHORS, CONTRIBUTORS OR COPYRIGHT  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
041     *    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR
042     *    IN CONNECTION WITH THE SOFTWARE OR THE USE OR  OTHER DEALINGS IN THE SOFTWARE.
043     * </p> 
044     * @author Greg Paperin (<a href="http://www.paperin.org" target="_blank">http://www.paperin.org</a>)
045     * @version {@value com.softnetConsult.utils.APIProperties#apiVersion}
046     *
047     * @param <E> The type of the array-list elements.
048     */
049    public class ArrayListRemovableRange<E> extends ArrayList<E> {
050    
051    /**
052     * Constructs an empty list.
053     * 
054     * @see ArrayList#ArrayList()
055     */
056    public ArrayListRemovableRange() {
057            super();
058    }
059    
060    /**
061     * Constructs an empty list with the specified initial capacity.
062     * 
063     * @param initialCapacity The initial capacity of the list.
064     * @see ArrayList#ArrayList(int)
065     */
066    public ArrayListRemovableRange(int initialCapacity) {
067            super(initialCapacity);
068    }
069    
070    /**
071     * Constructs a list containing the elements of the specified collection,
072     * in the order they are returned by the collection's iterator.
073     * 
074     * @param c The collection whose elements are to be placed into this list.
075     * @see ArrayList#ArrayList(Collection)
076     */
077    public ArrayListRemovableRange(Collection<? extends E> c) {
078            super(c);
079    }
080    
081    /**
082     * Removes from this list all of the elements whose index is between fromIndex, inclusive,
083     * and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index).
084     * This call shortens the list by (toIndex - fromIndex) elements.
085     * (If toIndex==fromIndex, this operation has no effect.)
086     * 
087     * @param fromIndex Index of first element to be removed.
088     * @param toIndex Index after last element to be removed.
089     * @throws IndexOutOfBoundsException If fromIndex or toIndex out of range
090     * {@code (fromIndex < 0 || fromIndex >= size() || toIndex > size() || toIndex < fromIndex)}
091     */
092    @Override
093    public void removeRange(int fromIndex, int toIndex) {
094            
095            if (fromIndex < 0 || fromIndex >= size())
096                    throw new IndexOutOfBoundsException("Invalid index: " + fromIndex);
097            
098            if (toIndex > size() || toIndex < fromIndex)
099                    throw new IndexOutOfBoundsException("Invalid index: " + toIndex);
100            
101            super.removeRange(fromIndex, toIndex);
102    }
103    
104    } // public class ArrayListRemovableRange<E>