net.ranides.assira.collection.set
Class IdentitySet<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<T>
          extended by net.ranides.assira.collection.set.IdentitySet<T>
Type Parameters:
T -
All Implemented Interfaces:
Iterable<T>, Collection<T>, Set<T>

public final class IdentitySet<T>
extends AbstractSet<T>

Zbiór, który nie używa metody equals do porównywania elementów, lecz sprawdza identyczność referencji. Wersja znacznie wydajniejsza od naiwnej implementacji opierającej się na IdentityHashMap wzorowana na kodzie udostępnianym na www.koders.com będącym częścią projektu Maxwell Assembler.

Porównać z cięższą wersją używającą linkowanych węzłów z: castor.org

Author:
ranides

Constructor Summary
IdentitySet()
          Tworzy nowy zbiór o początkowej capacity = 16.
IdentitySet(int initialCapacity)
          Tworzy nowy zbiór o określonej pojemności oraz loadFactor = 75%.
IdentitySet(int initialCapacity, float loadFactor)
          Tworzy nowy zbiór o określonej początkowej capacity oraz loadFactor
 
Method Summary
 boolean add(T element)
           
 void clear()
           
 boolean contains(Object element)
           
 boolean isEmpty()
           
 Iterator<T> iterator()
           
 boolean remove(Object element)
           
 int size()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] target)
           
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, retainAll
 

Constructor Detail

IdentitySet

public IdentitySet()
Tworzy nowy zbiór o początkowej capacity = 16.


IdentitySet

public IdentitySet(int initialCapacity)
Tworzy nowy zbiór o określonej pojemności oraz loadFactor = 75%.

Parameters:
initialCapacity -

IdentitySet

public IdentitySet(int initialCapacity,
                   float loadFactor)
Tworzy nowy zbiór o określonej początkowej capacity oraz loadFactor

Parameters:
initialCapacity -
loadFactor -
Method Detail

add

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

contains

public boolean contains(Object element)
Specified by:
contains in interface Collection<T>
Specified by:
contains in interface Set<T>
Overrides:
contains in class AbstractCollection<T>

remove

public boolean remove(Object element)
Specified by:
remove in interface Collection<T>
Specified by:
remove in interface Set<T>
Overrides:
remove in class AbstractCollection<T>

size

public int size()
Specified by:
size in interface Collection<T>
Specified by:
size in interface Set<T>
Specified by:
size in class AbstractCollection<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 Set<T>
Specified by:
iterator in class AbstractCollection<T>

clear

public void clear()
Specified by:
clear in interface Collection<T>
Specified by:
clear in interface Set<T>
Overrides:
clear in class AbstractCollection<T>

toArray

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

toArray

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

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<T>
Specified by:
isEmpty in interface Set<T>
Overrides:
isEmpty in class AbstractCollection<T>


Copyright © 2013. All Rights Reserved.