net.didion.jwnl.util
Class TypeCheckingList

java.lang.Object
  extended by net.didion.jwnl.util.TypeCheckingList
All Implemented Interfaces:
Cloneable, Iterable, Collection, List, DeepCloneable
Direct Known Subclasses:
PointerTargetNodeList, RelationshipList

public class TypeCheckingList
extends Object
implements List, DeepCloneable

Wrapper for a list that checks the type of arguments before putting them in the list. It also does type-checking on methods which iterate over the list so that they fail fast if the argument is not of the correct type.


Nested Class Summary
 class TypeCheckingList.TypeCheckingListIterator
           
 
Constructor Summary
  TypeCheckingList(Class type)
           
  TypeCheckingList(List backingList, Class type)
           
protected TypeCheckingList(List backingList, Class type, Class parentType)
          Create a new Type checking list that checks for type type, but only if parentType is equal to, a super class/interface of, or an interface implemented by type.
 
Method Summary
 void add(int index, Object o)
           
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 boolean addAll(int index, Collection c)
           
 void clear()
           
 Object clone()
          Create a shallow clone of the object
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
protected  List copyBackingList()
          Make a copy of the wrapped list - used by subclasses when the overriding the clone method
 Object deepClone()
          Create a deep clone of the object
 boolean equals(Object obj)
           
 Object get(int index)
           
 Class getType()
           
protected  TypeCheckingList.TypeCheckingListIterator getTypeCheckingListIterator()
           
protected  TypeCheckingList.TypeCheckingListIterator getTypeCheckingListIterator(int index)
           
 int indexOf(Object o)
           
 boolean isEmpty()
           
 Iterator iterator()
           
 int lastIndexOf(Object o)
           
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
           
 Object remove(int index)
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 boolean retainAll(Collection c)
           
 Object set(int index, Object element)
           
 int size()
           
 List subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
hashCode
 

Constructor Detail

TypeCheckingList

public TypeCheckingList(Class type)

TypeCheckingList

public TypeCheckingList(List backingList,
                        Class type)

TypeCheckingList

protected TypeCheckingList(List backingList,
                           Class type,
                           Class parentType)
Create a new Type checking list that checks for type type, but only if parentType is equal to, a super class/interface of, or an interface implemented by type.

Method Detail

getType

public Class getType()

clone

public Object clone()
             throws CloneNotSupportedException
Description copied from interface: DeepCloneable
Create a shallow clone of the object

Specified by:
clone in interface DeepCloneable
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

copyBackingList

protected List copyBackingList()
                        throws CloneNotSupportedException
Make a copy of the wrapped list - used by subclasses when the overriding the clone method

Throws:
CloneNotSupportedException

deepClone

public Object deepClone()
                 throws UnsupportedOperationException
Description copied from interface: DeepCloneable
Create a deep clone of the object

Specified by:
deepClone in interface DeepCloneable
Throws:
UnsupportedOperationException

equals

public boolean equals(Object obj)
Specified by:
equals in interface Collection
Specified by:
equals in interface List
Overrides:
equals in class Object

add

public boolean add(Object o)
Specified by:
add in interface Collection
Specified by:
add in interface List

add

public void add(int index,
                Object o)
Specified by:
add in interface List

addAll

public boolean addAll(Collection c)
Specified by:
addAll in interface Collection
Specified by:
addAll in interface List

addAll

public boolean addAll(int index,
                      Collection c)
Specified by:
addAll in interface List

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection
Specified by:
contains in interface List

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection
Specified by:
containsAll in interface List

set

public Object set(int index,
                  Object element)
Specified by:
set in interface List

indexOf

public int indexOf(Object o)
Specified by:
indexOf in interface List

lastIndexOf

public int lastIndexOf(Object o)
Specified by:
lastIndexOf in interface List

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection
Specified by:
remove in interface List

listIterator

public ListIterator listIterator()
Specified by:
listIterator in interface List

listIterator

public ListIterator listIterator(int index)
Specified by:
listIterator in interface List

getTypeCheckingListIterator

protected TypeCheckingList.TypeCheckingListIterator getTypeCheckingListIterator()

getTypeCheckingListIterator

protected TypeCheckingList.TypeCheckingListIterator getTypeCheckingListIterator(int index)

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in interface List

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection
Specified by:
isEmpty in interface List

iterator

public Iterator iterator()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List

removeAll

public boolean removeAll(Collection c)
Specified by:
removeAll in interface Collection
Specified by:
removeAll in interface List

retainAll

public boolean retainAll(Collection c)
Specified by:
retainAll in interface Collection
Specified by:
retainAll in interface List

clear

public void clear()
Specified by:
clear in interface Collection
Specified by:
clear in interface List

get

public Object get(int index)
Specified by:
get in interface List

remove

public Object remove(int index)
Specified by:
remove in interface List

subList

public List subList(int fromIndex,
                    int toIndex)
Specified by:
subList in interface List


Copyright © 2011. All Rights Reserved.