Skip to content

Method: toString()

1: package de.fhdw.gaming.ipspiel23.c4.collections.impl;
2:
3: import java.util.Collection;
4: import java.util.Map;
5:
6: import de.fhdw.gaming.ipspiel23.c4.collections.IReadOnlyDictionary;
7:
8: /**
9: * The default implementation of {@link IReadOnlyDictionary}.
10: *
11: * @param <TKEY> The type of the keys.
12: * @param <TVALUE> The type of the values.
13: */
14: public class ReadOnlyDictionaryImpl<TKEY, TVALUE> implements IReadOnlyDictionary<TKEY, TVALUE> {
15:
16: /**
17: * The inner map that is wrapped by this instance.
18: */
19: private final Map<TKEY, TVALUE> inner;
20:
21: /**
22: * Creates a new instance of {@link ReadOnlyDictionaryImpl}.
23: *
24: * @param inner The inner map that is wrapped by this instance.
25: */
26: public ReadOnlyDictionaryImpl(final Map<TKEY, TVALUE> inner) {
27: this.inner = inner;
28: }
29:
30: @Override
31: public boolean containsKey(final TKEY key) {
32: return inner.containsKey(key);
33: }
34:
35: @Override
36: public TVALUE getValueOrDefault(final TKEY key) {
37: return inner.get(key);
38: }
39:
40: @Override
41: public int count() {
42: return inner.size();
43: }
44:
45: @Override
46: public Collection<TKEY> getKeys() {
47: return inner.keySet();
48: }
49:
50: @Override
51: public Collection<TVALUE> getValues() {
52: return inner.values();
53: }
54:
55: @Override
56: public String toString() {
57: // "ReadOnlyDictionaryImpl [map={Test=Test}]"
58: return String.format("%s [map=%s]", getClass().getSimpleName(), inner);
59: }
60: }