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.prometheus.data.PrometheusDataItem;
23
24 import java.util.LinkedHashMap;
25 import java.util.Map;
26
27
28
29
30 public class PrometheusMapsItemTouch
31 implements MetisFieldItem {
32
33
34
35 private static final MetisFieldSet<PrometheusMapsItemTouch> FIELD_DEFS
36 = MetisFieldSet.newFieldSet(PrometheusMapsItemTouch.class);
37
38
39
40
41 static {
42 FIELD_DEFS.declareLocalField(PrometheusMapsResource.MAPS_ITEM, PrometheusMapsItemTouch::getItem);
43 FIELD_DEFS.declareLocalField(PrometheusMapsResource.TOUCH_TOUCHEDBY, PrometheusMapsItemTouch::getTouchedByMap);
44 FIELD_DEFS.declareLocalField(PrometheusMapsResource.TOUCH_TOUCHES, PrometheusMapsItemTouch::getTouchesMap);
45 }
46
47
48
49
50 private final PrometheusDataItem theItem;
51
52
53
54
55 private final Map<PrometheusMapsItemId, PrometheusDataItem> theTouchedBy;
56
57
58
59
60 private final Map<PrometheusMapsItemId, PrometheusDataItem> theTouches;
61
62
63
64
65
66
67 PrometheusMapsItemTouch(final PrometheusDataItem pItem) {
68 theItem = pItem;
69 theTouchedBy = new LinkedHashMap<>();
70 theTouches = new LinkedHashMap<>();
71 }
72
73 @Override
74 public MetisFieldSetDef getDataFieldSet() {
75 return FIELD_DEFS;
76 }
77
78 @Override
79 public String formatObject(final OceanusDataFormatter pFormatter) {
80 return theItem.formatObject(pFormatter);
81 }
82
83
84
85
86
87
88 private PrometheusDataItem getItem() {
89 return theItem;
90 }
91
92
93
94
95
96
97 private Map<PrometheusMapsItemId, PrometheusDataItem> getTouchedByMap() {
98 return theTouchedBy;
99 }
100
101
102
103
104
105
106 private Map<PrometheusMapsItemId, PrometheusDataItem> getTouchesMap() {
107 return theTouches;
108 }
109
110
111
112
113
114
115 void touchedByItem(final PrometheusDataItem pItem) {
116 final PrometheusMapsItemId myId = new PrometheusMapsItemId(pItem);
117 theTouchedBy.put(myId, pItem);
118 }
119
120
121
122
123
124
125 void touchesItem(final PrometheusDataItem pItem) {
126 final PrometheusMapsItemId myId = new PrometheusMapsItemId(pItem);
127 theTouches.put(myId, pItem);
128 }
129
130
131
132
133
134
135 boolean isTouched() {
136 return !theTouchedBy.isEmpty();
137 }
138 }