Skip to content

Package: TypeSafeHashMultiMap

TypeSafeHashMultiMap

nameinstructionbranchcomplexitylinemethod
TypeSafeHashMultiMap(Map)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
TypeSafeHashMultiMap(Map, boolean)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
asMap()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
canEqual(Object)
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
containsKey(Key)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
entrySet()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
equals(Object)
M: 38 C: 0
0%
M: 12 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
forEach(BiConsumer)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
get(Key)
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
hashCode()
M: 20 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
iterator()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
keySet()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
size()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toString()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
values()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
with(Key, Object)
M: 0 C: 21
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * TheseFoolishThings: Miscellaneous utilities
5: * http://tidalwave.it/projects/thesefoolishthings
6: *
7: * Copyright (C) 2009 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src
23: * git clone https://github.com/tidalwave-it/thesefoolishthings-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.util.impl;
28:
29: import javax.annotation.Nonnegative;
30: import javax.annotation.Nonnull;
31: import javax.annotation.concurrent.Immutable;
32: import java.util.ArrayList;
33: import java.util.Collection;
34: import java.util.HashMap;
35: import java.util.Iterator;
36: import java.util.Map;
37: import java.util.Set;
38: import java.util.concurrent.CopyOnWriteArrayList;
39: import java.util.concurrent.CopyOnWriteArraySet;
40: import java.util.function.BiConsumer;
41: import java.io.Serializable;
42: import it.tidalwave.util.Key;
43: import it.tidalwave.util.TypeSafeMultiMap;
44: import lombok.EqualsAndHashCode;
45:
46: /***********************************************************************************************************************
47: *
48: * @author Fabrizio Giudici
49: *
50: **********************************************************************************************************************/
51:•@Immutable @EqualsAndHashCode
52: public class TypeSafeHashMultiMap implements TypeSafeMultiMap, Serializable
53: {
54: private static final long serialVersionUID = 759233572056L;
55:
56: @Nonnull
57: private final Map<Key<?>, Collection<?>> map;
58:
59: /*******************************************************************************************************************
60: *
61: *
62: ******************************************************************************************************************/
63: public TypeSafeHashMultiMap (@Nonnull final Map<Key<?>, Collection<?>> map)
64: {
65: this(new HashMap<>(), true);
66: this.map.putAll(map);
67: }
68:
69: /*******************************************************************************************************************
70: *
71: *
72: ******************************************************************************************************************/
73: /* package */ TypeSafeHashMultiMap (@Nonnull final Map<Key<?>, Collection<?>> map, final boolean dummy)
74: {
75: this.map = map;
76: }
77:
78: /*******************************************************************************************************************
79: *
80: * {@inheritDoc}
81: *
82: ******************************************************************************************************************/
83: @Override @Nonnull @SuppressWarnings("unchecked")
84: public <T> Collection<T> get (@Nonnull final Key<T> key)
85: {
86:• return containsKey(key) ? new CopyOnWriteArrayList<>((Collection<T>)map.get(key))
87: : new ArrayList<>();
88: }
89:
90: /*******************************************************************************************************************
91: *
92: * {@inheritDoc}
93: *
94: ******************************************************************************************************************/
95: @Override
96: public boolean containsKey (@Nonnull final Key<?> key)
97: {
98: return map.containsKey(key);
99: }
100:
101: /*******************************************************************************************************************
102: *
103: * {@inheritDoc}
104: *
105: ******************************************************************************************************************/
106: @Override @Nonnull
107: public <T> TypeSafeHashMultiMap with (@Nonnull final Key<T> key, @Nonnull final T value)
108: {
109: final Map<Key<?>, Collection<?>> map = asMap();
110: final Collection<T> values = get(key);
111: values.add(value);
112: map.put(key, values);
113: return new TypeSafeHashMultiMap(map);
114: }
115:
116: /*******************************************************************************************************************
117: *
118: * {@inheritDoc}
119: *
120: ******************************************************************************************************************/
121: @Override @Nonnull
122: public Set<Key<?>> keySet()
123: {
124: return new CopyOnWriteArraySet<>(map.keySet());
125: }
126:
127: /*******************************************************************************************************************
128: *
129: * {@inheritDoc}
130: *
131: ******************************************************************************************************************/
132: @Override @Nonnull
133: public Collection<Collection<?>> values()
134: {
135: return map.values();
136: }
137:
138: /*******************************************************************************************************************
139: *
140: * {@inheritDoc}
141: *
142: ******************************************************************************************************************/
143: @Override @Nonnull
144: public Set<Map.Entry<Key<?>, Collection<?>>> entrySet()
145: {
146: return map.entrySet();
147: }
148:
149: /*******************************************************************************************************************
150: *
151: * {@inheritDoc}
152: *
153: ******************************************************************************************************************/
154: @Override @Nonnull
155: public Iterator<Map.Entry<Key<?>, Collection<?>>> iterator()
156: {
157: return map.entrySet().iterator();
158: }
159:
160: /*******************************************************************************************************************
161: *
162: * {@inheritDoc}
163: *
164: ******************************************************************************************************************/
165: @Override @Nonnegative
166: public int size()
167: {
168: return map.size();
169: }
170:
171: /*******************************************************************************************************************
172: *
173: * {@inheritDoc}
174: *
175: ******************************************************************************************************************/
176: @Override @Nonnull
177: public Map<Key<?>, Collection<?>> asMap()
178: {
179: return new HashMap<>(map);
180: }
181:
182: /*******************************************************************************************************************
183: *
184: * {@inheritDoc}
185: *
186: ******************************************************************************************************************/
187: @Override
188: public void forEach (@Nonnull final BiConsumer<? super Key<?>, ? super Collection<?>> action)
189: {
190: map.forEach(action);
191: }
192:
193: /*******************************************************************************************************************
194: *
195: * {@inheritDoc}
196: *
197: ******************************************************************************************************************/
198: @Override @Nonnull
199: public String toString()
200: {
201: return map.toString();
202: }
203: }