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.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.ArrayList;
25  import java.util.List;
26  
27  /**
28   * InstanceMap Elements.
29   */
30  public interface PrometheusMapsInstanceElement
31          extends MetisFieldItem {
32      /**
33       * Obtain the list of items.
34       *
35       * @return the list
36       */
37      List<PrometheusDataItem> getList();
38  
39      /**
40       * Instance Element Item.
41       */
42      class PrometheusMapsInstanceElementItem
43              implements PrometheusMapsInstanceElement {
44          /**
45           * Report fields.
46           */
47          private static final MetisFieldSet<PrometheusMapsInstanceElementItem> FIELD_DEFS
48                  = MetisFieldSet.newFieldSet(PrometheusMapsInstanceElementItem.class);
49  
50          /*
51           * Declare Fields.
52           */
53          static {
54              FIELD_DEFS.declareLocalField(PrometheusMapsResource.MAPS_ITEM, PrometheusMapsInstanceElementItem::getItem);
55          }
56  
57          /**
58           * The item.
59           */
60          private final PrometheusDataItem theItem;
61  
62          /**
63           * Constructor.
64           *
65           * @param pItem the item
66           */
67          PrometheusMapsInstanceElementItem(final PrometheusDataItem pItem) {
68              theItem = pItem;
69          }
70  
71          @Override
72          public MetisFieldSetDef getDataFieldSet() {
73              return FIELD_DEFS;
74          }
75  
76          @Override
77          public String formatObject(final OceanusDataFormatter pFormatter) {
78              return pFormatter.formatObject(theItem);
79          }
80  
81          /**
82           * Obtain the item.
83           *
84           * @return the item
85           */
86          PrometheusDataItem getItem() {
87              return theItem;
88          }
89  
90          @Override
91          public List<PrometheusDataItem> getList() {
92              /* Obtain the item as a list */
93              final List<PrometheusDataItem> myList = new ArrayList<>();
94              myList.add(theItem);
95              return myList;
96          }
97      }
98  
99      /**
100      * Instance Element List.
101      */
102     class PrometheusMapsInstanceElementList
103             implements PrometheusMapsInstanceElement {
104         /**
105          * Report fields.
106          */
107         private static final MetisFieldSet<PrometheusMapsInstanceElementList> FIELD_DEFS
108                 = MetisFieldSet.newFieldSet(PrometheusMapsInstanceElementList.class);
109 
110         /*
111          * Declare Fields.
112          */
113         static {
114             FIELD_DEFS.declareLocalField(PrometheusMapsResource.MAPS_ITEMLIST, PrometheusMapsInstanceElementList::getList);
115         }
116 
117         /**
118          * The list.
119          */
120         private final List<PrometheusDataItem> theList;
121 
122         /**
123          * Constructor.
124          *
125          * @param pPrevious the previous element
126          * @param pItem     the item
127          */
128         PrometheusMapsInstanceElementList(final PrometheusMapsInstanceElement pPrevious,
129                                           final PrometheusDataItem pItem) {
130             /* Create the new list */
131             theList = new ArrayList<>(pPrevious.getList());
132             theList.add(pItem);
133         }
134 
135         @Override
136         public MetisFieldSetDef getDataFieldSet() {
137             return FIELD_DEFS;
138         }
139 
140         @Override
141         public String formatObject(final OceanusDataFormatter pFormatter) {
142             return PrometheusMapsInstanceElementList.class.getSimpleName();
143         }
144 
145         @Override
146         public List<PrometheusDataItem> getList() {
147             return theList;
148         }
149     }
150 }