re base code
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / datamodel / NameIdPair.java
1 package org.openecomp.sdc.be.datamodel;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Objects;
6 import java.util.Set;
7
8 public class NameIdPair extends HashMap<String, Object> {
9
10     public static final String OPTIONS = "options";
11     public static final String NAME = "name";
12     public static final String ID = "id";
13     public static final String OWNER_ID = "ownerId";
14
15     public NameIdPair(String name, String id) {
16         this(name, id, null);
17     }
18
19     public NameIdPair(String name, String id, String ownerId) {
20         super();
21         setId(id);
22         setName(name);
23         if (!Objects.isNull(ownerId)) {
24             setOwnerId(ownerId);
25         }
26
27     }
28
29     public NameIdPair(NameIdPair nameIdPair) {
30         super(nameIdPair);
31     }
32
33     public String getName() {
34         return get(NAME).toString();
35     }
36
37     public void setName(String name) {
38         super.put(NAME, name);
39     }
40
41     public String getId() {
42         return get(ID).toString();
43     }
44
45     public void setId(String id) {
46         super.put(ID, id);
47     }
48
49     public String getOwnerId() {
50         return get(OWNER_ID).toString();
51     }
52
53     public void setOwnerId(String ownerId) {
54         put(OWNER_ID, ownerId);
55     }
56
57     public Set<NameIdPairWrapper> getWrappedData() {
58         return (Set<NameIdPairWrapper>) super.get(OPTIONS);
59     }
60
61     public void setWrappedData(Set<NameIdPairWrapper> data) {
62         super.put(OPTIONS, data);
63     }
64
65     public void addWrappedData(NameIdPairWrapper nameIdPairWrapper) {
66         if (get(OPTIONS) == null) {
67             setWrappedData(new HashSet<>());
68         }
69         getWrappedData().add(nameIdPairWrapper);
70     }
71
72     @Override
73     public boolean equals(Object o) {
74         if (this == o) return true;
75         if (!(o instanceof NameIdPair)) return false;
76         NameIdPair that = (NameIdPair) o;
77         return Objects.equals(getId(), that.getId());
78     }
79
80     @Override
81     public int hashCode() {
82         return Objects.hash(getId());
83     }
84
85     public static final NameIdPair create(String name, String id) {
86         return new NameIdPair(name, id);
87     }
88
89
90 }