View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
21   */
22  package org.primefaces.extensions.component.orgchart;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * <code>orgchart</code> component.
29   *
30   * @author @jxmai / last modified by $Author$
31   * @version $Revision$
32   * @since 6.3
33   */
34  public class DefaultOrgChartNode implements OrgChartNode {
35  
36      private String id;
37  
38      private String name;
39  
40      private String title;
41  
42      private String className;
43  
44      private Object nodeData;
45  
46      private List<OrgChartNode> children = new ArrayList<>();
47  
48      private int childCount;
49  
50      private OrgChartNode parent;
51  
52      public DefaultOrgChartNode() {
53          super();
54      }
55  
56      public DefaultOrgChartNode(final String name, final String title) {
57          super();
58          this.name = name;
59          this.title = title;
60      }
61  
62      public DefaultOrgChartNode(final String id, final String name, final String title) {
63          super();
64          this.id = id;
65          this.name = name;
66          this.title = title;
67      }
68  
69      public DefaultOrgChartNode(final String id, final String name, final String title, final Object nodeData) {
70          super();
71          this.id = id;
72          this.name = name;
73          this.title = title;
74          this.nodeData = nodeData;
75      }
76  
77      @Override
78      public String toString() {
79          return "DefaultOrgChartNode [id=" + id + ", name=" + name + ", nodeData=" + nodeData + "]";
80      }
81  
82      @Override
83      public int hashCode() {
84          final int prime = 31;
85          int result = 1;
86          result = prime * result + (id == null ? 0 : id.hashCode());
87          result = prime * result + (name == null ? 0 : name.hashCode());
88          result = prime * result + (nodeData == null ? 0 : nodeData.hashCode());
89          return result;
90      }
91  
92      @Override
93      public boolean equals(final Object obj) {
94          if (this == obj) {
95              return true;
96          }
97          if (obj == null) {
98              return false;
99          }
100         if (getClass() != obj.getClass()) {
101             return false;
102         }
103         final DefaultOrgChartNode other = (DefaultOrgChartNode) obj;
104         if (id == null) {
105             if (other.id != null) {
106                 return false;
107             }
108         }
109         else if (!id.equals(other.id)) {
110             return false;
111         }
112         if (name == null) {
113             if (other.name != null) {
114                 return false;
115             }
116         }
117         else if (!name.equals(other.name)) {
118             return false;
119         }
120         if (nodeData == null) {
121             if (other.nodeData != null) {
122                 return false;
123             }
124         }
125         else if (!nodeData.equals(other.nodeData)) {
126             return false;
127         }
128         return true;
129     }
130 
131     @Override
132     public String getId() {
133         return id;
134     }
135 
136     @Override
137     public void setId(final String id) {
138         this.id = id;
139     }
140 
141     @Override
142     public String getName() {
143         return name;
144     }
145 
146     @Override
147     public void setName(final String name) {
148         this.name = name;
149     }
150 
151     @Override
152     public String getTitle() {
153         return title;
154     }
155 
156     @Override
157     public void setTitle(final String title) {
158         this.title = title;
159     }
160 
161     @Override
162     public List<OrgChartNode> getChildren() {
163         return children;
164     }
165 
166     @Override
167     public void setChildren(final List<OrgChartNode> children) {
168         this.children = children;
169     }
170 
171     @Override
172     public OrgChartNode getParent() {
173         return parent;
174     }
175 
176     @Override
177     public void setParent(final OrgChartNode parent) {
178         this.parent = parent;
179     }
180 
181     @Override
182     public void addChild(final OrgChartNode child) {
183         children.add(child);
184     }
185 
186     @Override
187     public void clearChildren() {
188         children.clear();
189     }
190 
191     @Override
192     public void clearParent() {
193         parent = null;
194     }
195 
196     public Object getNodeData() {
197         return nodeData;
198     }
199 
200     public void setNodeData(final Object nodeData) {
201         this.nodeData = nodeData;
202     }
203 
204     @Override
205     public String getClassName() {
206         return className;
207     }
208 
209     @Override
210     public void setClassName(final String className) {
211         this.className = className;
212     }
213 
214     @Override
215     public int getChildCount() {
216         childCount = getChildren().size();
217         return childCount;
218     }
219 
220 }