re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / graph / datatype / GraphRelation.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.dao.graph.datatype;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 public class GraphRelation extends GraphElement {
27
28         private RelationEndPoint from;
29         private RelationEndPoint to;
30         private String type;
31         private Map<String, Object> properties;
32
33         public GraphRelation() {
34                 super(GraphElementTypeEnum.Relationship);
35                 properties = new HashMap<>();
36         }
37
38         public GraphRelation(String type) {
39                 super(GraphElementTypeEnum.Relationship);
40                 properties = new HashMap<>();
41                 setType(type);
42         }
43
44         public RelationEndPoint getFrom() {
45                 return from;
46         }
47
48         public void setFrom(RelationEndPoint from) {
49                 this.from = from;
50         }
51
52         public RelationEndPoint getTo() {
53                 return to;
54         }
55
56         public void setTo(RelationEndPoint to) {
57                 this.to = to;
58         }
59
60         public String getType() {
61                 return type;
62         }
63
64         public void setType(String type) {
65                 this.type = type;
66         }
67
68         public void addProperty(String property, Object value) {
69                 if (property != null && !property.isEmpty() && value != null) {
70                         properties.put(property, value);
71                 }
72         }
73
74         public void addPropertis(Map<String, Object> props) {
75                 if(props != null) {
76                         properties.putAll(props);
77                 }
78         }
79
80         public void overwritePropertis(Map<String, Object> props) {
81                 properties = props;
82         }
83
84         public Object getProperty(String property) {
85                 return properties.get(property);
86         }
87
88         @Override
89         public Map<String, Object> toGraphMap() {
90                 return properties;
91         }
92
93         @Override
94         public String toString() {
95                 return "GraphRelation [from=" + from + ", to=" + to + ", type=" + type + ", properties=" + properties + "]";
96         }
97
98         @Override
99         public int hashCode() {
100                 final int prime = 31;
101                 int result = 1;
102                 result = prime * result + ((from == null) ? 0 : from.hashCode());
103                 result = prime * result + ((properties == null) ? 0 : properties.hashCode());
104                 result = prime * result + ((to == null) ? 0 : to.hashCode());
105                 result = prime * result + ((type == null) ? 0 : type.hashCode());
106                 return result;
107         }
108 }