javatools.datatypes
Class FinalSet<T extends java.lang.Comparable<?>>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<T>
          extended by javatools.datatypes.FinalSet<T>
All Implemented Interfaces:
java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.Set<T>

public class FinalSet<T extends java.lang.Comparable<?>>
extends java.util.AbstractList<T>
implements java.util.Set<T>

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class provides a very simple container implementation with zero overhead. A FinalSet bases on a sorted, unmodifiable array. The constructor can either be called with a sorted unmodifiable array (default constructor) or with an array that can be cloned and sorted beforehand if desired. Example:

   FinalSet f=new FinalSet("a","b","c");
   // equivalently: 
   //   FinalSet f=new FinalSet(new String[]{"a","b","c"});
   //   FinalSet f=new FinalSet(SHALLNOTBECLONED,ISSORTED,"a","b","c");
   System.out.println(f.get(1));
   --> b


Field Summary
 T[] data
          Holds the data, must be sorted
 
Constructor Summary
FinalSet(boolean clone, T... a)
          Constructs a FinalSet from an array, clones and sorts the array if indicated.
FinalSet(T... a)
          Constructs a FinalSet from an array that does not need to be cloned
 
Method Summary
 boolean contains(T x)
          Tells whether x is in the container
 T get(int i)
          Returns the element at position i
 int indexOf(T x)
          Returns the position in the array or -1
static void main(java.lang.String[] args)
          Test routine
 int size()
          Returns the number of elements in this FinalSet
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

data

public T extends java.lang.Comparable<?>[] data
Holds the data, must be sorted

Constructor Detail

FinalSet

public FinalSet(boolean clone,
                T... a)
Constructs a FinalSet from an array, clones and sorts the array if indicated.


FinalSet

public FinalSet(T... a)
Constructs a FinalSet from an array that does not need to be cloned

Method Detail

contains

public boolean contains(T x)
Tells whether x is in the container


indexOf

public int indexOf(T x)
Returns the position in the array or -1


get

public T get(int i)
Returns the element at position i

Specified by:
get in interface java.util.List<T extends java.lang.Comparable<?>>
Specified by:
get in class java.util.AbstractList<T extends java.lang.Comparable<?>>

size

public int size()
Returns the number of elements in this FinalSet

Specified by:
size in interface java.util.Collection<T extends java.lang.Comparable<?>>
Specified by:
size in interface java.util.List<T extends java.lang.Comparable<?>>
Specified by:
size in interface java.util.Set<T extends java.lang.Comparable<?>>
Specified by:
size in class java.util.AbstractCollection<T extends java.lang.Comparable<?>>

main

public static void main(java.lang.String[] args)
Test routine