|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.mcgill.cs.postina.util.LinkedHashSet<E>
E - The type of the elements of the structure.public class LinkedHashSet<E>
The datastructure LinkedHashSet combines the advantages of a
LinkedList and of the HashSet. Internally it keeps the data both as a HashSet
and as a LinkedList, so the restrictions for HashSets still apply. This
structure is useful when a list has to be ordered but also requires many
checks if a specified element is in the list (i.e. calls of
contains()). The call of contains() on a
LinkedList is of complexity O(n) whereas the same operation on
a HashSet is of O(1).
| Field Summary | |
|---|---|
private java.util.HashSet<E> |
hashSet
The internal representation of the list as a HashSet. |
private java.util.LinkedList<E> |
linkedList
The internal representation of the list as a LinkedList. |
private static long |
serialVersionUID
|
| Constructor Summary | |
|---|---|
LinkedHashSet()
The default constructor does not take any argument. |
|
| Method Summary | |
|---|---|
void |
add(E e)
This method adds an element to the list. |
boolean |
contains(E e)
This method checks if a given element is in the list. |
E |
getFirst()
This method returns the first element in the ordered list but does not delete it in the list. |
boolean |
isEmpty()
This method indicates whether the list is empty. |
E |
removeFirst()
This method returns the first element in the ordered list and removes it from the list. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final long serialVersionUID
private final java.util.HashSet<E> hashSet
private final java.util.LinkedList<E> linkedList
| Constructor Detail |
|---|
public LinkedHashSet()
| Method Detail |
|---|
public void add(E e)
e - The element to be added.public boolean contains(E e)
e - The element for which it should be indicated if it is in the
list.
True if the element is in the list,
false else.public E getFirst()
public boolean isEmpty()
True if the list is empty, false
else.public E removeFirst()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||