Added oparent to sdc main
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / datamodel / NameIdPair.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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.openecomp.sdc.be.datamodel;
22
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Objects;
26 import java.util.Set;
27
28 public class NameIdPair extends HashMap<String, Object> {
29
30     public static final String OPTIONS = "options";
31     public static final String NAME = "name";
32     public static final String ID = "id";
33     public static final String OWNER_ID = "ownerId";
34
35     public NameIdPair(String name, String id) {
36         this(name, id, null);
37     }
38
39     public NameIdPair(String name, String id, String ownerId) {
40         super();
41         setId(id);
42         setName(name);
43         if (!Objects.isNull(ownerId)) {
44             setOwnerId(ownerId);
45         }
46
47     }
48
49     public NameIdPair(NameIdPair nameIdPair) {
50         super(nameIdPair);
51     }
52
53     public String getName() {
54         return get(NAME).toString();
55     }
56
57     public void setName(String name) {
58         super.put(NAME, name);
59     }
60
61     public String getId() {
62         return get(ID).toString();
63     }
64
65     public void setId(String id) {
66         super.put(ID, id);
67     }
68
69     public String getOwnerId() {
70         return get(OWNER_ID).toString();
71     }
72
73     public void setOwnerId(String ownerId) {
74         put(OWNER_ID, ownerId);
75     }
76
77     public Set<NameIdPairWrapper> getWrappedData() {
78         return (Set<NameIdPairWrapper>) super.get(OPTIONS);
79     }
80
81     public void setWrappedData(Set<NameIdPairWrapper> data) {
82         super.put(OPTIONS, data);
83     }
84
85     public void addWrappedData(NameIdPairWrapper nameIdPairWrapper) {
86         if (get(OPTIONS) == null) {
87             setWrappedData(new HashSet<>());
88         }
89         getWrappedData().add(nameIdPairWrapper);
90     }
91
92     @Override
93     public boolean equals(Object o) {
94         if (this == o) return true;
95         if (!(o instanceof NameIdPair)) return false;
96         NameIdPair that = (NameIdPair) o;
97         return Objects.equals(getId(), that.getId());
98     }
99
100     @Override
101     public int hashCode() {
102         return Objects.hash(getId());
103     }
104
105     public static final NameIdPair create(String name, String id) {
106         return new NameIdPair(name, id);
107     }
108
109
110 }