[AAI-2175] Change aai champ container processes to run as non-root on the host
[aai/champ.git] / champ-lib / champ-core / src / main / java / org / onap / aai / champcore / model / ChampObjectIndex.java
1 /**
2  * ============LICENSE_START==========================================
3  * org.onap.aai
4  * ===================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ===================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *        http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  */
21 package org.onap.aai.champcore.model;
22
23 import java.util.List;
24 import java.util.Objects;
25 import org.onap.aai.champcore.model.fluent.index.CreateObjectIndexable;
26 import org.onap.aai.champcore.model.fluent.index.impl.CreateObjectIndexableImpl;
27
28 public final class ChampObjectIndex {
29
30         private final String name;
31         private final String type;
32         private final List<ChampField> fields;
33
34         public static CreateObjectIndexable create() {
35                 return new CreateObjectIndexableImpl();
36         }
37
38         private ChampObjectIndex() {
39                 throw new RuntimeException("Cannot call ChampObjectIndex() constructor");
40         }
41
42         private ChampObjectIndex(Builder builder) {
43                 this.name = builder.name;
44                 this.type = builder.type;
45                 this.fields = builder.fields;
46         }
47
48         public String getName() { return name; }
49         public String getType() { return type; }
50         public List<ChampField> getFields() { return fields; }
51
52         public static class Builder {
53                 private final String name;
54                 private final String type;
55                 private final List<ChampField> fields;
56
57                 public Builder(String name, String type, List<ChampField> fields) {
58                         this.name = name;
59                         this.type = type;
60                         this.fields = fields;
61                 }
62
63                 public ChampObjectIndex build() {
64                         return new ChampObjectIndex(this);
65                 }
66         }
67
68         @Override
69         public String toString() {
70                 return "{name: " + getName()
71                         + ", type: " + getType()
72                         + ", fields: " + getFields() + "}";
73         }
74
75         @Override
76         public boolean equals(Object object) {
77                 if (this == object) return true;
78                 
79                 if (object instanceof ChampObjectIndex) {
80                         final ChampObjectIndex objectIndex = (ChampObjectIndex) object;
81                         
82                         if ( getName().equals(objectIndex.getName()) && (getFields().hashCode() == objectIndex.getFields().hashCode()) ) {
83                             return true;
84                         }
85                 }
86                 
87                 return false;
88         }
89
90         @Override
91         public int hashCode() {
92                 return Objects.hash(getName(), getFields().hashCode());
93         }
94 }