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 import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
25
26 import java.util.LinkedHashMap;
27 import java.util.Map;
28
29
30
31
32 public class PrometheusMapsListTouch
33 implements MetisFieldItem {
34
35
36
37 private static final MetisFieldSet<PrometheusMapsListTouch> FIELD_DEFS
38 = MetisFieldSet.newFieldSet(PrometheusMapsListTouch.class);
39
40
41
42
43 static {
44 FIELD_DEFS.declareLocalField(PrometheusDataResource.DATAITEM_TYPE, PrometheusMapsListTouch::getListKey);
45 FIELD_DEFS.declareLocalField(PrometheusMapsResource.MAPS_TOUCHMAP, PrometheusMapsListTouch::getTouchMap);
46 }
47
48
49
50
51 private final MetisListKey theListKey;
52
53
54
55
56 private final Map<Integer, PrometheusMapsItemTouch> theTouchMap;
57
58
59
60
61
62
63 PrometheusMapsListTouch(final MetisListKey pKey) {
64 theListKey = pKey;
65 theTouchMap = new LinkedHashMap<>();
66 }
67
68 @Override
69 public MetisFieldSetDef getDataFieldSet() {
70 return FIELD_DEFS;
71 }
72
73 @Override
74 public String formatObject(final OceanusDataFormatter pFormatter) {
75 return pFormatter.formatObject(theListKey);
76 }
77
78
79
80
81
82
83 private MetisListKey getListKey() {
84 return theListKey;
85 }
86
87
88
89
90
91
92 private Map<Integer, PrometheusMapsItemTouch> getTouchMap() {
93 return theTouchMap;
94 }
95
96
97
98
99
100
101
102 void recordTouchedBy(final PrometheusDataItem pTouchedItem,
103 final PrometheusDataItem pTouchingItem) {
104
105 final PrometheusMapsItemTouch myMap = theTouchMap.computeIfAbsent(pTouchedItem.getIndexedId(),
106 i -> new PrometheusMapsItemTouch(pTouchedItem));
107 myMap.touchedByItem(pTouchingItem);
108 }
109
110
111
112
113
114
115
116
117 void recordTouches(final PrometheusDataItem pTouchedItem,
118 final PrometheusDataItem pTouchingItem) {
119
120 final PrometheusMapsItemTouch myMap = theTouchMap.computeIfAbsent(pTouchingItem.getIndexedId(),
121 i -> new PrometheusMapsItemTouch(pTouchingItem));
122 myMap.touchesItem(pTouchedItem);
123 }
124
125
126
127
128
129
130
131 boolean isTouched(final PrometheusDataItem pItem) {
132 final PrometheusMapsItemTouch myMap = theTouchMap.get(pItem.getIndexedId());
133 return myMap != null && myMap.isTouched();
134 }
135 }