Class Relation<K,​V>

  • All Implemented Interfaces:
    Freezable<Relation<K,​V>>, java.lang.Cloneable

    public class Relation<K,​V>
    extends java.lang.Object
    implements Freezable<Relation<K,​V>>
    A Relation is a set of mappings from keys to values. Unlike Map, there is not guaranteed to be a single value per key. The Map-like APIs return collections for values.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  Relation.SimpleEntry<K,​V>  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<K,​java.util.Set<V>> data  
      (package private) boolean frozen  
      (package private) java.lang.Object[] setComparatorParam  
      (package private) java.lang.reflect.Constructor<? extends java.util.Set<V>> setCreator  
    • Constructor Summary

      Constructors 
      Constructor Description
      Relation​(java.util.Map<K,​java.util.Set<V>> map, java.lang.Class<?> setCreator)  
      Relation​(java.util.Map<K,​java.util.Set<V>> map, java.lang.Class<?> setCreator, java.util.Comparator<V> setComparator)  
    • Field Detail

      • data

        private java.util.Map<K,​java.util.Set<V>> data
      • setCreator

        java.lang.reflect.Constructor<? extends java.util.Set<V>> setCreator
      • setComparatorParam

        java.lang.Object[] setComparatorParam
      • frozen

        volatile boolean frozen
    • Constructor Detail

      • Relation

        public Relation​(java.util.Map<K,​java.util.Set<V>> map,
                        java.lang.Class<?> setCreator)
      • Relation

        public Relation​(java.util.Map<K,​java.util.Set<V>> map,
                        java.lang.Class<?> setCreator,
                        java.util.Comparator<V> setComparator)
    • Method Detail

      • of

        public static <K,​V> Relation<K,​V> of​(java.util.Map<K,​java.util.Set<V>> map,
                                                         java.lang.Class<?> setCreator)
      • of

        public static <K,​V> Relation<K,​V> of​(java.util.Map<K,​java.util.Set<V>> map,
                                                         java.lang.Class<?> setCreator,
                                                         java.util.Comparator<V> setComparator)
      • clear

        public void clear()
      • containsKey

        public boolean containsKey​(java.lang.Object key)
      • containsValue

        public boolean containsValue​(java.lang.Object value)
      • entrySet

        public final java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
      • keyValuesSet

        public java.util.Set<java.util.Map.Entry<K,​java.util.Set<V>>> keyValuesSet()
      • keyValueSet

        public java.util.Set<java.util.Map.Entry<K,​V>> keyValueSet()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • getAll

        public java.util.Set<V> getAll​(java.lang.Object key)
      • get

        public java.util.Set<V> get​(java.lang.Object key)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • isEmpty

        public boolean isEmpty()
      • keySet

        public java.util.Set<K> keySet()
      • put

        public V put​(K key,
                     V value)
      • putAll

        public V putAll​(K key,
                        java.util.Collection<? extends V> values)
      • putAll

        public V putAll​(java.util.Collection<K> keys,
                        V value)
      • newSet

        private java.util.Set<V> newSet()
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> t)
      • putAll

        public void putAll​(Relation<? extends K,​? extends V> t)
      • removeAll

        public java.util.Set<V> removeAll​(K key)
      • remove

        public boolean remove​(K key,
                              V value)
      • size

        public int size()
      • values

        public java.util.Set<V> values()
      • values

        public <C extends java.util.Collection<V>> C values​(C result)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • addAllInverted

        public Relation<K,​V> addAllInverted​(java.util.Map<V,​K> source)
      • isFrozen

        public boolean isFrozen()
        Description copied from interface: Freezable
        Determines whether the object has been frozen or not.
        Specified by:
        isFrozen in interface Freezable<K>
      • freeze

        public Relation<K,​V> freeze()
        Description copied from interface: Freezable
        Freezes the object.
        Specified by:
        freeze in interface Freezable<K>
        Returns:
        the object itself.
      • cloneAsThawed

        public Relation<K,​V> cloneAsThawed()
        Description copied from interface: Freezable
        Provides for the clone operation. Any clone is initially unfrozen.
        Specified by:
        cloneAsThawed in interface Freezable<K>
      • removeAll

        public boolean removeAll​(Relation<K,​V> toBeRemoved)
      • removeAll

        @SafeVarargs
        public final java.util.Set<V> removeAll​(K... keys)
      • removeAll

        public boolean removeAll​(K key,
                                 java.lang.Iterable<V> toBeRemoved)
      • removeAll

        public java.util.Set<V> removeAll​(java.util.Collection<K> toBeRemoved)