1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.prometheus.maps;
18
19 import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
20 import io.github.tonywasher.joceanus.metis.field.MetisFieldItem;
21 import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
22 import io.github.tonywasher.joceanus.metis.list.MetisListKey;
23 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
24
25 import java.util.LinkedHashMap;
26 import java.util.Map;
27
28
29
30
31 public class PrometheusMapsDataSetTouch
32 implements MetisFieldItem {
33
34
35
36 private static final MetisFieldSet<PrometheusMapsDataSetTouch> FIELD_DEFS = MetisFieldSet.newFieldSet(PrometheusMapsDataSetTouch.class);
37
38
39
40
41 static {
42 FIELD_DEFS.declareLocalField(PrometheusMapsResource.MAPS_TOUCHMAP, PrometheusMapsDataSetTouch::getTouchMap);
43 }
44
45
46
47
48 private final Map<MetisListKey, PrometheusMapsListTouch> theListMap;
49
50
51
52
53 PrometheusMapsDataSetTouch() {
54 theListMap = new LinkedHashMap<>();
55 }
56
57 @Override
58 public MetisFieldSetDef getDataFieldSet() {
59 return FIELD_DEFS;
60 }
61
62 @Override
63 public String formatObject(final OceanusDataFormatter pFormatter) {
64 return PrometheusMapsDataSetTouch.class.getSimpleName();
65 }
66
67
68
69
70
71
72 private Map<MetisListKey, PrometheusMapsListTouch> getTouchMap() {
73 return theListMap;
74 }
75
76
77
78
79
80
81
82 void recordTouch(final PrometheusDataItem pTouchedItem,
83 final PrometheusDataItem pTouchingItem) {
84
85 MetisListKey myKey = pTouchedItem.getItemType();
86 PrometheusMapsListTouch myMap = theListMap.computeIfAbsent(myKey,
87 PrometheusMapsListTouch::new);
88 myMap.recordTouchedBy(pTouchedItem, pTouchingItem);
89
90
91 myKey = pTouchingItem.getItemType();
92 myMap = theListMap.computeIfAbsent(myKey,
93 PrometheusMapsListTouch::new);
94 myMap.recordTouches(pTouchedItem, pTouchingItem);
95 }
96
97
98
99
100
101
102
103 boolean isTouched(final PrometheusDataItem pItem) {
104 final PrometheusMapsListTouch myMap = theListMap.get(pItem.getItemType());
105 return myMap != null && myMap.isTouched(pItem);
106 }
107
108
109
110
111 void resetMap() {
112 theListMap.clear();
113 }
114 }