001package votorola.g.util; // Copyright 2011-2012, 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.
002
003import java.util.*;
004
005
006/** ArrayList utilities.
007  */
008public final class ArrayListX
009{
010
011    private ArrayListX() {}
012
013
014
015    /** An empty list (intended to be immutable).
016      */
017    public static final ArrayList<?> EMPTY_LIST = new EmptyList();
018
019
020
021    /** Returns the {@linkplain #EMPTY_LIST empty list}.
022      */
023      @SuppressWarnings("unchecked")
024    public static <T> ArrayList<T> emptyList() { return (ArrayList<T>)EMPTY_LIST; }
025
026
027
028//// P r i v a t e ///////////////////////////////////////////////////////////////////////
029
030
031    private static final class EmptyList extends ArrayList<Object> // FIX, try harder to keep it empty
032    {
033
034        private Object readResolve() { return EMPTY_LIST; } // keep it a singleton
035
036
037       // - C o l l e c t i o n ----------------------------------------------------------
038
039
040        public @Override boolean add( Object o ) { throw new UnsupportedOperationException(); }
041
042
043        public @Override int size()
044        {
045            assert super.size() == 0;
046            return 0;
047        }
048
049    }
050
051
052}