Class LinkedHashKeyedSet<K,V>

java.lang.Object
java.util.AbstractCollection<V>
java.util.AbstractSet<V>
org.checkerframework.afu.scenelib.util.coll.LinkedHashKeyedSet<K,V>
All Implemented Interfaces:
Iterable<V>, Collection<V>, Set<V>, KeyedSet<K,V>

public class LinkedHashKeyedSet<K,V> extends AbstractSet<V> implements KeyedSet<K,V>
A simple implementation of KeyedSet backed by an insertion-order LinkedHashMap and its value collection.
  • Constructor Details

    • LinkedHashKeyedSet

      public LinkedHashKeyedSet(Keyer<? extends K,? super V> keyer)
      Constructs a LinkedHashKeyedSet that uses the given Keyer to obtain keys for elements.
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface Collection<K>
      Specified by:
      size in interface Set<K>
      Specified by:
      size in class AbstractCollection<V>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<K>
      Specified by:
      contains in interface Set<K>
      Overrides:
      contains in class AbstractCollection<V>
    • iterator

      public Iterator<V> iterator()
      Specified by:
      iterator in interface Collection<K>
      Specified by:
      iterator in interface Iterable<K>
      Specified by:
      iterator in interface Set<K>
      Specified by:
      iterator in class AbstractCollection<V>
    • toArray

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

      public <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<K>
      Specified by:
      toArray in interface Set<K>
      Overrides:
      toArray in class AbstractCollection<V>
    • add

      public V add(V o, int conflictBehavior, int equalBehavior)
      Description copied from interface: KeyedSet
      Adds v to this KeyedSet; this set's Keyer will be called once to fetch v's key. If an object equal to v is already present in this KeyedSet, then this method carries out the equalBehavior and returns the existing object. Otherwise, if an object having a key equal to v's is already present in this KeyedSet, then this method carries out the conflictBehavior and returns the existing object. Otherwise, this method adds v to this KeyedSet and returns null.
      Specified by:
      add in interface KeyedSet<K,V>
      Parameters:
      o - the object to be added
      conflictBehavior - specifies what to do if v's key equals an existing object's key
      equalBehavior - specifies what to do if v equals an existing object
      Returns:
      the existing object whose key matched v's, if any
    • add

      public boolean add(V o)
      Specified by:
      add in interface Collection<K>
      Specified by:
      add in interface Set<K>
      Overrides:
      add in class AbstractCollection<V>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<K>
      Specified by:
      remove in interface Set<K>
      Overrides:
      remove in class AbstractCollection<V>
    • addAll

      public boolean addAll(Collection<? extends V> c)
      Specified by:
      addAll in interface Collection<K>
      Specified by:
      addAll in interface Set<K>
      Overrides:
      addAll in class AbstractCollection<V>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<K>
      Specified by:
      clear in interface Set<K>
      Overrides:
      clear in class AbstractCollection<V>
    • getKeyer

      public Keyer<? extends K,? super V> getKeyer()
      Description copied from interface: KeyedSet
      Returns the Keyer that this KeyedSet uses to obtain keys for elements.
      Specified by:
      getKeyer in interface KeyedSet<K,V>
      Returns:
      the Keyer that this KeyedSet uses to obtain keys for elements
    • replace

      public V replace(V v)
      Description copied from interface: KeyedSet
      Adds v to this KeyedSet, replacing and returning an existing object with the same key as v (if any). The existing object is replaced with v even if it equals v. If no existing object is replaced, null is returned.
      Specified by:
      replace in interface KeyedSet<K,V>
    • lookup

      public V lookup(K k)
      Description copied from interface: KeyedSet
      Looks for and returns an element with key k, or null if none.
      Specified by:
      lookup in interface KeyedSet<K,V>
      Returns:
      the element with key k, or null if none