fc57273951180f75453e802e53228f8c2c63ea6e
[policy/models.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.controlloop.actorserviceprovider.topic;
22
23 import lombok.EqualsAndHashCode;
24 import org.onap.policy.common.utils.coder.StandardCoderObject;
25
26 /**
27  * Selector key, which contains a hierarchical list of Strings and Integers that are used
28  * to extract the content of a field, typically from a {@link StandardCoderObject}.
29  */
30 @EqualsAndHashCode
31 public class SelectorKey {
32
33     /**
34      * Names and indices used to extract the field's value.
35      */
36     private final Object[] fieldIdentifiers;
37
38     /**
39      * Constructs the object.
40      *
41      * @param fieldIdentifiers names and indices used to extract the field's value
42      */
43     public SelectorKey(Object... fieldIdentifiers) {
44         this.fieldIdentifiers = fieldIdentifiers;
45     }
46
47     /**
48      * Extracts the given field from an object.
49      *
50      * @param object object from which to extract the field
51      * @return the extracted value, or {@code null} if the object does not contain the
52      *         field
53      */
54     public String extractField(StandardCoderObject object) {
55         return object.getString(fieldIdentifiers);
56     }
57 }