View Javadoc
1   package com.exsoinn.util.epf;
2   
3   import com.exsoinn.util.DnbBusinessObject;
4   
5   import java.util.*;
6   
7   /**
8    * Created by QuijadaJ on 5/3/2017.
9    */
10  public final class SearchResult implements Map<String, Context>, DnbBusinessObject {
11  
12      private final Map<String, Context> m;
13  
14      private SearchResult(Map<String, Context> pResult) {
15          /*
16           * Defensively copying passed in Map to enforce immutability.
17           */
18          m = new HashMap<>(pResult);
19      }
20  
21      public Context firstResult() {
22          if (null == m || m.isEmpty()) {
23              return null;
24          }
25          return m.entrySet().iterator().next().getValue();
26      }
27  
28      public static SearchResult emptySearchResult() {
29          return new SearchResult(Collections.emptyMap());
30      }
31  
32      public static SearchResult createSearchResult(Map<String, Context> pResult) {
33          return new SearchResult(pResult);
34      }
35  
36      @Override
37      public int size() {
38          return m.size();
39      }
40  
41      @Override
42      public boolean isEmpty() {
43          return m.isEmpty();
44      }
45  
46      @Override
47      public boolean containsKey(Object pKey) {
48          return m.containsKey(pKey);
49      }
50  
51      @Override
52      public boolean containsValue(Object pValue) {
53          return m.containsValue(pValue);
54      }
55  
56      @Override
57      public Context get(Object pKey) {
58          return m.get(pKey);
59      }
60  
61      @Override
62      public Context put(String pKey, Context pValue) {
63          throw new UnsupportedOperationException();
64      }
65  
66      @Override
67      public Context remove(Object pKey) {
68          throw new UnsupportedOperationException();
69      }
70  
71      @Override
72      public void putAll(Map<? extends String, ? extends Context> pMap) {
73          throw new UnsupportedOperationException();
74      }
75  
76      @Override
77      public void clear() {
78          throw new UnsupportedOperationException();
79      }
80  
81      @Override
82      public Set<String> keySet() {
83          return new HashSet<>(m.keySet());
84      }
85  
86      @Override
87      public Collection<Context> values() {
88          return new ArrayList<>(m.values());
89      }
90  
91      @Override
92      public Set<Entry<String, Context>> entrySet() {
93          return new HashSet<>(m.entrySet());
94      }
95  
96      @Override
97      public String toString() {
98          return m.toString();
99      }
100 
101 
102 }