Module md.grammar

Class AssociativeSet


  • public class AssociativeSet
    extends Object
    Association of a pair of values supports lookup by either value. Each value in an association must be unique. Not thread-safe.
    Author:
    Don Mendelson
    • Constructor Detail

      • AssociativeSet

        public AssociativeSet()
    • Method Detail

      • add

        public boolean add​(String v1,
                           String v2)
        Add values to this AssociativeSet
        Parameters:
        v1 - first key value
        v2 - second key value
        Returns:
        true if this set did not already contain the specified element
      • addAll

        public boolean addAll​(String[][] values)
        Add values to this AssociativeSet
        Parameters:
        values - a array of two-element arrays
        Returns:
        true if this set did not already contain the specified elements
      • clear

        public void clear()
      • get

        public String get​(String v1)
        Access an association by the first key
        Parameters:
        v1 - value to search
        Returns:
        the second value of an association or null if not found
      • getOrDefault

        public String getOrDefault​(String v1,
                                   String defaultValue)
        Access an association by the first key
        Parameters:
        v1 - value to search
        defaultValue - value to return if no association found
        Returns:
        the second value of an association or defaultValue if not found
      • getSecond

        public String getSecond​(String v2)
        Access an association by the second key
        Parameters:
        v2 - value to search
        Returns:
        the first value of an association or null if not found
      • getSecondOrDefault

        public String getSecondOrDefault​(String v2,
                                         String defaultValue)
        Access an association by the second key
        Parameters:
        v2 - value to search
        defaultValue - value to return if no association found
        Returns:
        the first value of an association or defaultValue if not found
      • size

        public int size()
      • values

        public List<Object[]> values()
        Returns all values in the set Returned as array of Object because it is not possible to create generic arrays in Java.
        Returns:
        a List of two-element array containing key values