Applying license changes to all files
[appc.git] / appc-dg / appc-dg-shared / appc-dg-dependency-model / src / main / java / org / openecomp / appc / dg / objects / Node.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.dg.objects;
26
27 import java.util.LinkedList;
28 import java.util.List;
29
30
31 public class Node<T> {
32     T child;
33     List<T> parents;
34
35     @Override
36     public int hashCode(){
37         return child.hashCode();
38     }
39
40     @Override
41     public boolean equals(Object object){
42         if(object == null){
43             return false;
44         }
45         if(!(object instanceof Node)){
46             return false;
47         }
48         Node node = (Node)object;
49         return this.child.equals(node.getChild());
50     }
51
52     public Node(T child){
53         this.child = child;
54         this.parents = new LinkedList<>();
55     }
56
57     public T getChild() {
58         return child;
59     }
60
61     public List<T> getParents() {
62         return parents;
63     }
64
65     public void addParent(T parent){
66         this.parents.add(parent);
67     }
68
69     @Override
70     public String toString() {
71         StringBuilder stringBuilder = new StringBuilder("Node : child = " + child + " , parents = ");
72         for(T parent:parents){
73             stringBuilder.append(parent).append(",");
74         }
75         return stringBuilder.toString();
76     }
77 }