Class ImmutableTripletonMap<K,V>

All Implemented Interfaces:
Serializable, Iterable<V>, Map<K,V>, InternalIterable<V>, ImmutableMap<K,V>, ImmutableMapIterable<K,V>, MapIterable<K,V>, UnsortedMapIterable<K,V>, RichIterable<V>

final class ImmutableTripletonMap<K,V> extends AbstractImmutableMap<K,V> implements Serializable
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • key1

      private final K key1
    • value1

      private final V value1
    • key2

      private final K key2
    • value2

      private final V value2
    • key3

      private final K key3
    • value3

      private final V value3
  • Constructor Details

    • ImmutableTripletonMap

      ImmutableTripletonMap(K key1, V value1, K key2, V value2, K key3, V value3)
  • Method Details

    • keysView

      public RichIterable<K> keysView()
      Description copied from interface: MapIterable
      Returns an unmodifiable lazy iterable wrapped around the keySet for the map.
      Specified by:
      keysView in interface MapIterable<K,V>
    • valuesView

      public RichIterable<V> valuesView()
      Description copied from interface: MapIterable
      Returns an unmodifiable lazy iterable wrapped around the values for the map.
      Specified by:
      valuesView in interface MapIterable<K,V>
    • keyValuesView

      public RichIterable<Pair<K,V>> keyValuesView()
      Description copied from interface: MapIterable
      Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map.
      Specified by:
      keyValuesView in interface MapIterable<K,V>
    • size

      public int size()
      Description copied from interface: RichIterable
      Returns the number of items in this iterable.
      Specified by:
      size in interface Map<K,V>
      Specified by:
      size in interface RichIterable<K>
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
      Specified by:
      containsKey in interface MapIterable<K,V>
      See Also:
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
      Specified by:
      containsValue in interface MapIterable<K,V>
      See Also:
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
      Specified by:
      get in interface MapIterable<K,V>
      See Also:
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
    • hashCode

      public int hashCode()
      Description copied from interface: MapIterable
      Follows the same general contract as Map.hashCode().
      Specified by:
      hashCode in interface Map<K,V>
      Specified by:
      hashCode in interface MapIterable<K,V>
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Description copied from interface: MapIterable
      Follows the same general contract as Map.equals(Object).
      Specified by:
      equals in interface Map<K,V>
      Specified by:
      equals in interface MapIterable<K,V>
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Description copied from class: AbstractRichIterable
      Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.
       Assert.assertEquals("[]", Lists.mutable.empty().toString());
       Assert.assertEquals("[1]", Lists.mutable.with(1).toString());
       Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());
       
      Specified by:
      toString in interface MapIterable<K,V>
      Specified by:
      toString in interface RichIterable<K>
      Overrides:
      toString in class AbstractRichIterable<V>
      Returns:
      a string representation of this collection.
      See Also:
    • flipUniqueValues

      public ImmutableMap<V,K> flipUniqueValues()
      Description copied from interface: MapIterable
      Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.
           MapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
           MapIterable<String, Integer> result = map.flipUniqueValues();
           Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
       
      Specified by:
      flipUniqueValues in interface ImmutableMap<K,V>
      Specified by:
      flipUniqueValues in interface ImmutableMapIterable<K,V>
      Specified by:
      flipUniqueValues in interface MapIterable<K,V>
      Specified by:
      flipUniqueValues in interface UnsortedMapIterable<K,V>
      Overrides:
      flipUniqueValues in class AbstractImmutableMap<K,V>
    • forEachKeyValue

      public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
      Description copied from interface: MapIterable
      Calls the procedure with each key-value pair of the map.
           final Collection<String> collection = new ArrayList<String>();
           MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three");
           map.forEachKeyValue((Integer key, String value) -> collection.add(String.valueOf(key) + value));
           Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
       
      Specified by:
      forEachKeyValue in interface MapIterable<K,V>
    • forEachKey

      public void forEachKey(Procedure<? super K> procedure)
      Description copied from interface: MapIterable
      Calls the procedure with each key of the map.
           final Collection<Integer> result = new ArrayList<Integer>();
           MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
           map.forEachKey(new CollectionAddProcedure<Integer>(result));
           Verify.assertContainsAll(result, 1, 2, 3);
       
      Specified by:
      forEachKey in interface MapIterable<K,V>
      Overrides:
      forEachKey in class AbstractMapIterable<K,V>
    • forEachValue

      public void forEachValue(Procedure<? super V> procedure)
      Description copied from interface: MapIterable
      Calls the procedure with each value of the map.
           Set<String> result = UnifiedSet.newSet();
           MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
           map.forEachValue(new CollectionAddProcedure<String>(result));
           Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
       
      Specified by:
      forEachValue in interface MapIterable<K,V>
      Overrides:
      forEachValue in class AbstractMapIterable<K,V>
    • forEachWithIndex

      public void forEachWithIndex(ObjectIntProcedure<? super V> objectIntProcedure)
      Description copied from interface: InternalIterable
      Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

      Example using a Java 8 lambda:

       people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
       

      Example using an anonymous inner class:

       people.forEachWithIndex(new ObjectIntProcedure<Person>()
       {
           public void value(Person person, int index)
           {
               LOGGER.info("Index: " + index + " person: " + person.getName());
           }
       });
       
      Specified by:
      forEachWithIndex in interface InternalIterable<K>
      Overrides:
      forEachWithIndex in class AbstractMapIterable<K,V>
    • forEachWith

      public <P> void forEachWith(Procedure2<? super V,? super P> procedure, P parameter)
      Description copied from interface: InternalIterable
      The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

      Example using a Java 8 lambda:

       people.forEachWith((Person person, Person other) ->
           {
               if (person.isRelatedTo(other))
               {
                    LOGGER.info(person.getName());
               }
           }, fred);
       

      Example using an anonymous inner class:

       people.forEachWith(new Procedure2<Person, Person>()
       {
           public void value(Person person, Person other)
           {
               if (person.isRelatedTo(other))
               {
                    LOGGER.info(person.getName());
               }
           }
       }, fred);
       
      Specified by:
      forEachWith in interface InternalIterable<K>
      Overrides:
      forEachWith in class AbstractMapIterable<K,V>
    • collect

      public <K2, V2> ImmutableMap<K2,V2> collect(Function2<? super K,? super V,Pair<K2,V2>> function)
      Description copied from interface: MapIterable
      For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.
       MapIterable<String, String> collected =
           peopleByCity.collect((City city, Person person) -> Pair.of(city.getCountry(), person.getAddress().getCity()));
       
      Specified by:
      collect in interface ImmutableMap<K,V>
      Specified by:
      collect in interface ImmutableMapIterable<K,V>
      Specified by:
      collect in interface MapIterable<K,V>
      Specified by:
      collect in interface UnsortedMapIterable<K,V>
      Overrides:
      collect in class AbstractImmutableMap<K,V>
    • collectValues

      public <R> ImmutableMap<K,R> collectValues(Function2<? super K,? super V,? extends R> function)
      Description copied from interface: MapIterable
      For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.
       MapIterable<City, String> collected =
           peopleByCity.collectValues((City city, Person person) -> person.getFirstName() + " " + person.getLastName());
       
      Specified by:
      collectValues in interface ImmutableMap<K,V>
      Specified by:
      collectValues in interface ImmutableMapIterable<K,V>
      Specified by:
      collectValues in interface MapIterable<K,V>
      Specified by:
      collectValues in interface UnsortedMapIterable<K,V>
      Overrides:
      collectValues in class AbstractImmutableMap<K,V>
    • detect

      public Pair<K,V> detect(Predicate2<? super K,? super V> predicate)
      Description copied from interface: MapIterable
      Return the first key and value of the map for which the predicate evaluates to true when they are given as arguments. The predicate will only be evaluated until such pair is found or until all the keys and values of the map have been used as arguments. That is, there may be keys and values of the map that are never used as arguments to the predicate. The result is null if predicate does not evaluate to true for any key/value combination.
       Pair<City, Person> detected =
           peopleByCity.detect((City city, Person person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
       
      Specified by:
      detect in interface MapIterable<K,V>
      Overrides:
      detect in class AbstractImmutableMap<K,V>
    • select

      public ImmutableMap<K,V> select(Predicate2<? super K,? super V> predicate)
      Description copied from interface: MapIterable
      For each key and value of the map the predicate is evaluated, if the result of the evaluation is true, that key and value are returned in a new map.
       MapIterable<City, Person> selected =
           peopleByCity.select((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
       
      Specified by:
      select in interface ImmutableMap<K,V>
      Specified by:
      select in interface ImmutableMapIterable<K,V>
      Specified by:
      select in interface MapIterable<K,V>
      Specified by:
      select in interface UnsortedMapIterable<K,V>
      Overrides:
      select in class AbstractImmutableMap<K,V>
    • reject

      public ImmutableMap<K,V> reject(Predicate2<? super K,? super V> predicate)
      Description copied from interface: MapIterable
      For each key and value of the map the predicate is evaluated, if the result of the evaluation is false, that key and value are returned in a new map.
       MapIterable<City, Person> rejected =
           peopleByCity.reject((city, person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
       
      Specified by:
      reject in interface ImmutableMap<K,V>
      Specified by:
      reject in interface ImmutableMapIterable<K,V>
      Specified by:
      reject in interface MapIterable<K,V>
      Specified by:
      reject in interface UnsortedMapIterable<K,V>
      Overrides:
      reject in class AbstractImmutableMap<K,V>
    • filter

      private ImmutableMap<K,V> filter(Predicate2<? super K,? super V> predicate)
    • getOnly

      public V getOnly()
      Description copied from interface: RichIterable
      Returns the element if the iterable has exactly one element. Otherwise, throw IllegalStateException.
      Specified by:
      getOnly in interface RichIterable<K>
      Overrides:
      getOnly in class AbstractMapIterable<K,V>
      Returns:
      an element of an iterable.
    • writeReplace

      private Object writeReplace()