re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / TagData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.resources.data;
22
23 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30 public class TagData extends GraphNode {
31
32         private String name;
33
34         protected TagData(NodeTypeEnum label) {
35                 super(label);
36         }
37
38         public TagData(String name) {
39                 super(NodeTypeEnum.Tag);
40                 this.name = name;
41         }
42
43         public TagData() {
44                 super(NodeTypeEnum.Tag);
45         }
46
47         public TagData(Map<String, Object> properties) {
48                 super(NodeTypeEnum.Tag);
49                 setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
50         }
51
52         @Override
53         public Map<String, Object> toGraphMap() {
54                 Map<String, Object> map = new HashMap<>();
55                 addIfExists(map, GraphPropertiesDictionary.NAME, name);
56                 return map;
57         }
58
59         public String getName() {
60                 return name;
61         }
62
63         public void setName(String name) {
64                 this.name = name;
65         }
66
67         @Override
68         public String toString() {
69                 return "Tag [Name=" + name + "]";
70         }
71
72         @Override
73         public int hashCode() {
74                 final int prime = 31;
75                 int result = 1;
76                 result = prime * result + ((name == null) ? 0 : name.hashCode());
77                 return result;
78         }
79
80         @Override
81         public boolean equals(Object obj) {
82                 if (this == obj) {
83                         return true;
84                 }
85                 if (obj == null) {
86                         return false;
87                 }
88                 if (getClass() != obj.getClass()) {
89                         return false;
90                 }
91                 TagData other = (TagData) obj;
92                 if (name == null) {
93                         if (other.getClass() != null) {
94                                 return false;
95                         }
96                 } else if (!name.equals(other.getName())) {
97                         return false;
98                 }
99                 return true;
100         }
101
102         @Override
103         public String getUniqueIdKey() {
104                 return GraphPropertiesDictionary.NAME.getProperty();
105         }
106
107         @Override
108         public String getUniqueId() {
109                 return name;
110         }
111
112 }