uk.ac.ebi.jmzidml.model.utils
Class FacadeList<T>

java.lang.Object
  extended by java.util.AbstractCollection<T>
      extended by uk.ac.ebi.jmzidml.model.utils.FacadeList<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>

public class FacadeList<T>
extends AbstractCollection<T>
implements List<T>

Created by IntelliJ IDEA. User: rwang Date: 26/01/11 Time: 10:16

Controls access to a standard java list which contains more than one instance type, providing the developer with a virtual list of a specified type. When this list is created, the developer must specify the class of interest. Methods called on this class will be applied to the original list but will only act on instances of the specified type. For example, an originalList could contain a mixture of CvParams and UserParams. To work with a list of CvParams, a developer creates an instance of this class passing in 'CvParam.class' as clazz in the constructor. If the size method is called the list be searched and only instances of CvParam are counted towards the size. Likewise, if get(3) (3 is the index) is called the 3rd instance of CvParam will be returned. Note, this CvParam might not be the third element in the originallist.

TODO Implement CvParam and UserParam's toString, equals, hashcode. With equals objects are normally considered equals if contents match. TODO Check iterator working with foreach TODO check the checkIndex(), maybe not the best implementation TODO finish all the add methods with checking the null input values


Constructor Summary
FacadeList(List originalList, Class<T> clazz)
           
 
Method Summary
 void add(int index, T element)
          Add a new element to the sublist This will add the new element to the immediate index after the element at (index -1) in the sublist
 boolean add(T t)
           
 boolean addAll(int index, Collection<? extends T> c)
           
 boolean contains(Object o)
          Check whether the sublist contains the element
 boolean equals(Object comparedToListObject)
           
 T get(int index)
          Get an element from the original list at index.
 int hashCode()
           
 int indexOf(Object o)
          Get the index of sublist using a given object
 boolean isEmpty()
          Check whether the sublist is empty
 Iterator<T> iterator()
          Get an iterator of the sublist
 int lastIndexOf(Object o)
          Get the last index of sublist using a given object
 ListIterator<T> listIterator()
           
 ListIterator<T> listIterator(int index)
           
 T remove(int index)
          Remove a element from the original list The index here is the index of the specified element int the original list
 boolean remove(Object o)
          Remove an object from the sublist
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 T set(int index, T element)
          Set an new element based on the index of the sublist
 int size()
          Get the size of the sublist
 List<T> subList(int fromIndex, int toIndex)
          sublist returned is an unmodifiable list, structural change to the sublist is not allowed.
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 String toString()
          This method is overridden to print out the list in concatenated string format
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, clear, containsAll
 

Constructor Detail

FacadeList

public FacadeList(List originalList,
                  Class<T> clazz)
Method Detail

add

public boolean add(T t)
Specified by:
add in interface Collection<T>
Specified by:
add in interface List<T>
Overrides:
add in class AbstractCollection<T>

remove

public T remove(int index)
Remove a element from the original list The index here is the index of the specified element int the original list

Specified by:
remove in interface List<T>
Parameters:
index - list index
Returns:
T element has been removed

get

public T get(int index)
Get an element from the original list at index.

Specified by:
get in interface List<T>
Parameters:
index - list index
Returns:
T element to get

set

public T set(int index,
             T element)
Set an new element based on the index of the sublist

Specified by:
set in interface List<T>
Parameters:
index - index of the sublist
element - new element
Returns:
T old element in the position

size

public int size()
Get the size of the sublist

Specified by:
size in interface Collection<T>
Specified by:
size in interface List<T>
Specified by:
size in class AbstractCollection<T>
Returns:
int size of the sublist

isEmpty

public boolean isEmpty()
Check whether the sublist is empty

Specified by:
isEmpty in interface Collection<T>
Specified by:
isEmpty in interface List<T>
Overrides:
isEmpty in class AbstractCollection<T>
Returns:
boolean true means empty

contains

public boolean contains(Object o)
Check whether the sublist contains the element

Specified by:
contains in interface Collection<T>
Specified by:
contains in interface List<T>
Overrides:
contains in class AbstractCollection<T>
Parameters:
o - input object
Returns:
boolean true means sublist contains the input object

iterator

public Iterator<T> iterator()
Get an iterator of the sublist

Specified by:
iterator in interface Iterable<T>
Specified by:
iterator in interface Collection<T>
Specified by:
iterator in interface List<T>
Specified by:
iterator in class AbstractCollection<T>
Returns:
Iterator an iterator of the sublist

indexOf

public int indexOf(Object o)
Get the index of sublist using a given object

Specified by:
indexOf in interface List<T>
Parameters:
o - input object
Returns:
int index of the object

lastIndexOf

public int lastIndexOf(Object o)
Get the last index of sublist using a given object

Specified by:
lastIndexOf in interface List<T>
Parameters:
o - input object
Returns:
int index of the object

listIterator

public ListIterator<T> listIterator()
Specified by:
listIterator in interface List<T>

listIterator

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

subList

public List<T> subList(int fromIndex,
                       int toIndex)
sublist returned is an unmodifiable list, structural change to the sublist is not allowed. Please note: this behaves differently from the definition of the interface. Changes to the element in sublist will affect the element in the original list However, the behaviour is undefined if the original list has been changed

Specified by:
subList in interface List<T>
Parameters:
fromIndex - low endpoint (inclusive) of the sublist
toIndex - high endpoint (exclusive) of the sublist
Returns:
List unmodifiable sublist

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<T>
Specified by:
toArray in interface List<T>
Overrides:
toArray in class AbstractCollection<T>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<T>
Specified by:
toArray in interface List<T>
Overrides:
toArray in class AbstractCollection<T>

add

public void add(int index,
                T element)
Add a new element to the sublist This will add the new element to the immediate index after the element at (index -1) in the sublist

Specified by:
add in interface List<T>
Parameters:
index - index of the sublist
element - the new element

remove

public boolean remove(Object o)
Remove an object from the sublist

Specified by:
remove in interface Collection<T>
Specified by:
remove in interface List<T>
Overrides:
remove in class AbstractCollection<T>
Parameters:
o - object to be removed
Returns:
boolean true a object has been found and removed

addAll

public boolean addAll(int index,
                      Collection<? extends T> c)
Specified by:
addAll in interface List<T>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<T>
Specified by:
removeAll in interface List<T>
Overrides:
removeAll in class AbstractCollection<T>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<T>
Specified by:
retainAll in interface List<T>
Overrides:
retainAll in class AbstractCollection<T>

toString

public String toString()
This method is overridden to print out the list in concatenated string format

Overrides:
toString in class AbstractCollection<T>
Returns:
String list string

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<T>
Specified by:
hashCode in interface List<T>
Overrides:
hashCode in class Object

equals

public boolean equals(Object comparedToListObject)
Specified by:
equals in interface Collection<T>
Specified by:
equals in interface List<T>
Overrides:
equals in class Object


Copyright © 2012. All Rights Reserved.