net.ranides.assira.collection
Class SingleCollection<T>

java.lang.Object
  extended by net.ranides.assira.collection.SingleCollection<T>
Type Parameters:
T -
All Implemented Interfaces:
Iterable<T>, Collection<T>, List<T>, Set<T>

public class SingleCollection<T>
extends Object
implements List<T>, Set<T>

Wydajna pamięciowo implementacja kolekcji zawierającej tylko 1 element. Kolekcja nie może zmieniać rozmiarów, ani być modyfikowana za pomocą iteratora. Niemniej przechowywana pojedyncza wartość może być modyfikowana bezpośrednio za pomocą funkcji set.

Kolekcja implementuje interfejsy Set oraz List

Author:
ranides

Constructor Summary
SingleCollection(T value)
          Tworzy nową kolekcję zawierającą podany obiekt
 
Method Summary
 void add(int index, T element)
           
 boolean add(T element)
           
 boolean addAll(Collection<? extends T> collection)
           
 boolean addAll(int index, Collection<? extends T> collection)
           
 void clear()
           
 boolean contains(Object object)
           
 boolean containsAll(Collection<?> collection)
           
 T get(int index)
           
 int indexOf(Object object)
           
 boolean isEmpty()
           
 Iterator<T> iterator()
           
 int lastIndexOf(Object object)
           
 ListIterator<T> listIterator()
           
 ListIterator<T> listIterator(int index)
           
static
<ST> SingleCollection<ST>
of(ST value)
           
 T remove(int index)
           
 boolean remove(Object object)
           
 boolean removeAll(Collection<?> collection)
           
 boolean retainAll(Collection<?> collection)
           
 T set(int index, T element)
           
 int size()
           
 List<T> subList(int fromIndex, int toIndex)
           
 Object[] toArray()
           
<K> K[]
toArray(K[] target)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.List
equals, hashCode
 
Methods inherited from interface java.util.Set
equals, hashCode
 

Constructor Detail

SingleCollection

public SingleCollection(T value)
Tworzy nową kolekcję zawierającą podany obiekt

Parameters:
value -
Method Detail

of

public static <ST> SingleCollection<ST> of(ST value)

size

public int size()
Specified by:
size in interface Collection<T>
Specified by:
size in interface List<T>
Specified by:
size in interface Set<T>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<T>
Specified by:
isEmpty in interface List<T>
Specified by:
isEmpty in interface Set<T>

contains

public boolean contains(Object object)
Specified by:
contains in interface Collection<T>
Specified by:
contains in interface List<T>
Specified by:
contains in interface Set<T>

iterator

public Iterator<T> iterator()
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 interface Set<T>

toArray

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

toArray

public <K> K[] toArray(K[] target)
Specified by:
toArray in interface Collection<T>
Specified by:
toArray in interface List<T>
Specified by:
toArray in interface Set<T>

add

public boolean add(T element)
Specified by:
add in interface Collection<T>
Specified by:
add in interface List<T>
Specified by:
add in interface Set<T>

remove

public boolean remove(Object object)
Specified by:
remove in interface Collection<T>
Specified by:
remove in interface List<T>
Specified by:
remove in interface Set<T>

containsAll

public boolean containsAll(Collection<?> collection)
Specified by:
containsAll in interface Collection<T>
Specified by:
containsAll in interface List<T>
Specified by:
containsAll in interface Set<T>

addAll

public boolean addAll(Collection<? extends T> collection)
Specified by:
addAll in interface Collection<T>
Specified by:
addAll in interface List<T>
Specified by:
addAll in interface Set<T>

addAll

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

removeAll

public boolean removeAll(Collection<?> collection)
Specified by:
removeAll in interface Collection<T>
Specified by:
removeAll in interface List<T>
Specified by:
removeAll in interface Set<T>

retainAll

public boolean retainAll(Collection<?> collection)
Specified by:
retainAll in interface Collection<T>
Specified by:
retainAll in interface List<T>
Specified by:
retainAll in interface Set<T>

clear

public void clear()
Specified by:
clear in interface Collection<T>
Specified by:
clear in interface List<T>
Specified by:
clear in interface Set<T>

get

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

set

public T set(int index,
             T element)
Specified by:
set in interface List<T>

add

public void add(int index,
                T element)
Specified by:
add in interface List<T>

remove

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

indexOf

public int indexOf(Object object)
Specified by:
indexOf in interface List<T>

lastIndexOf

public int lastIndexOf(Object object)
Specified by:
lastIndexOf in interface List<T>

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)
Specified by:
subList in interface List<T>


Copyright © 2013. All Rights Reserved.