2121import java .util .HashMap ;
2222import java .util .Iterator ;
2323import java .util .Map ;
24+ import java .util .Map .Entry ;
2425
2526import com .rusticisoftware .tincan .json .JSONBase ;
2627import com .rusticisoftware .tincan .json .Mapper ;
2930 * Language map
3031 */
3132@ NoArgsConstructor
32- public class LanguageMap extends JSONBase {
33+ public class LanguageMap extends JSONBase implements Iterable < Map . Entry < String , String >> {
3334 private final HashMap <String ,String > _map = new HashMap <String , String >();
3435
36+ private class LanguageMapIterator implements Iterator <Map .Entry <String , String >> {
37+ private Iterator <Map .Entry <String , String >> iterator ;
38+
39+ public LanguageMapIterator () {
40+ iterator = _map .entrySet ().iterator ();
41+ }
42+ @ Override
43+ public boolean hasNext () {
44+ return iterator .hasNext ();
45+ }
46+
47+ @ Override
48+ public Entry <String , String > next () {
49+ return iterator .next ();
50+ }
51+
52+ @ Override
53+ public void remove () throws UnsupportedOperationException {
54+ throw new UnsupportedOperationException (
55+ "LanguageMap iterator does not implement the remove method" );
56+ }
57+ }
3558 public LanguageMap (JsonNode jsonNode ) {
3659 this ();
3760
@@ -56,8 +79,38 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
5679 public String put (String key , String val ) {
5780 return this ._map .put (key , val );
5881 }
82+
83+ public String put (Map .Entry <String , String > entry ) {
84+ return this .put (entry .getKey (), entry .getValue ());
85+ }
5986
6087 public String get (String key ) {
6188 return this ._map .get (key );
6289 }
90+
91+ public boolean containsKey (String key ) {
92+ return this ._map .containsKey (key );
93+ }
94+
95+ public boolean containsValue (String value ) {
96+ return this ._map .containsValue (value );
97+ }
98+
99+ public Map .Entry <String , String > findFirstValue (String value ) {
100+ Map .Entry <String , String > retVal = null ;
101+ Iterator <Map .Entry <String ,String >> it = this .iterator ();
102+ while (it .hasNext ()) {
103+ Map .Entry <String , String > n = it .next ();
104+ if (n .getValue ().equalsIgnoreCase (value )) {
105+ retVal = n ;
106+ break ;
107+ }
108+ }
109+ return retVal ;
110+ }
111+
112+ @ Override
113+ public Iterator <Entry <String , String >> iterator () {
114+ return new LanguageMapIterator ();
115+ }
63116}
0 commit comments