View Javadoc
1   /*
2    * Prometheus: Application Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
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.data.MetisDataResource;
21  import io.github.tonywasher.joceanus.metis.field.MetisFieldItem;
22  import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
23  import io.github.tonywasher.joceanus.metis.list.MetisListKey;
24  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataItem;
25  import io.github.tonywasher.joceanus.prometheus.data.PrometheusDataResource;
26  
27  import java.util.Objects;
28  
29  /**
30   * DataTouchMap itemId.
31   */
32  public class PrometheusMapsItemId
33          implements MetisFieldItem {
34      /**
35       * Report fields.
36       */
37      private static final MetisFieldSet<PrometheusMapsItemId> FIELD_DEFS
38              = MetisFieldSet.newFieldSet(PrometheusMapsItemId.class);
39  
40      /*
41       * Declare Fields.
42       */
43      static {
44          FIELD_DEFS.declareLocalField(PrometheusDataResource.DATAITEM_TYPE, PrometheusMapsItemId::getListKey);
45          FIELD_DEFS.declareLocalField(MetisDataResource.DATA_ID, PrometheusMapsItemId::getItemId);
46      }
47  
48      /**
49       * The listKey.
50       */
51      private final MetisListKey theListKey;
52  
53      /**
54       * The itemId.
55       */
56      private final Integer theItemId;
57  
58      /**
59       * Constructor.
60       *
61       * @param pItem the item
62       */
63      PrometheusMapsItemId(final PrometheusDataItem pItem) {
64          theListKey = pItem.getItemType();
65          theItemId = pItem.getIndexedId();
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) + ":" + theItemId;
76      }
77  
78      /**
79       * Obtain the listKey.
80       *
81       * @return the listKey
82       */
83      private MetisListKey getListKey() {
84          return theListKey;
85      }
86  
87      /**
88       * Obtain the itemId.
89       *
90       * @return the id
91       */
92      private Integer getItemId() {
93          return theItemId;
94      }
95  
96      @Override
97      public boolean equals(final Object pThat) {
98          if (!(pThat instanceof PrometheusMapsItemId)) {
99              return false;
100         }
101         final PrometheusMapsItemId myThat = (PrometheusMapsItemId) pThat;
102         return theItemId.equals(myThat.getItemId())
103                 && theListKey.equals(myThat.getListKey());
104     }
105 
106     @Override
107     public int hashCode() {
108         return Objects.hash(theListKey, theItemId);
109     }
110 }