- java.lang.Object
-
- io.fixprotocol.md.util.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 Summary
Constructors Constructor Description AssociativeSet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(String v1, String v2)Add values to this AssociativeSetbooleanaddAll(String[][] values)Add values to this AssociativeSetvoidclear()Stringget(String v1)Access an association by the first keyStringgetOrDefault(String v1, String defaultValue)Access an association by the first keyStringgetSecond(String v2)Access an association by the second keyStringgetSecondOrDefault(String v2, String defaultValue)Access an association by the second keyintsize()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.
-
-
-
Method Detail
-
add
public boolean add(String v1, String v2)
Add values to this AssociativeSet- Parameters:
v1- first key valuev2- second key value- Returns:
trueif 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:
trueif 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
nullif not found
-
getOrDefault
public String getOrDefault(String v1, String defaultValue)
Access an association by the first key- Parameters:
v1- value to searchdefaultValue- value to return if no association found- Returns:
- the second value of an association or
defaultValueif 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
nullif not found
-
getSecondOrDefault
public String getSecondOrDefault(String v2, String defaultValue)
Access an association by the second key- Parameters:
v2- value to searchdefaultValue- value to return if no association found- Returns:
- the first value of an association or
defaultValueif not found
-
size
public int size()
-
-