1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that represents all node info from the database
|
4
|
* Copyright: 2000 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Matt Jones
|
7
|
*
|
8
|
* '$Author: daigle $'
|
9
|
* '$Date: 2010-04-14 11:31:03 -0700 (Wed, 14 Apr 2010) $'
|
10
|
* '$Revision: 5311 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
|
27
|
package edu.ucsb.nceas.metacat;
|
28
|
|
29
|
import org.apache.log4j.Logger;
|
30
|
|
31
|
/**
|
32
|
* A utility class that encapsulates a node and its data
|
33
|
*/
|
34
|
public class NodeRecord {
|
35
|
private long _nodeid = -1;
|
36
|
private long _parentnodeid = -1;
|
37
|
private long _nodeindex = -1;
|
38
|
private String _nodename = null;
|
39
|
private String _nodeprefix = null;
|
40
|
private String _nodetype = null;
|
41
|
private String _nodedata = null;
|
42
|
private float _nodedatanumerical = -1;
|
43
|
private Logger logMetacat = Logger.getLogger(NodeRecord.class);
|
44
|
|
45
|
/**
|
46
|
* Constructor
|
47
|
*/
|
48
|
public NodeRecord(long nodeid, long parentnodeid, long nodeindex,
|
49
|
String nodetype, String nodename, String nodeprefix,
|
50
|
String nodedata) {
|
51
|
setNodeId(nodeid);
|
52
|
setParentNodeId(parentnodeid);
|
53
|
setNodeIndex(nodeindex);
|
54
|
setNodeName(nodename);
|
55
|
setNodePrefix(nodeprefix);
|
56
|
setNodeType(nodetype);
|
57
|
setNodeData(nodedata);
|
58
|
}
|
59
|
|
60
|
public NodeRecord(long nodeid, long parentnodeid, long nodeindex, String nodetype,
|
61
|
String nodename, String nodeprefix, String nodedata, float nodedatanumerical) {
|
62
|
setNodeId(nodeid);
|
63
|
setParentNodeId(parentnodeid);
|
64
|
setNodeIndex(nodeindex);
|
65
|
setNodeName(nodename);
|
66
|
setNodePrefix(nodeprefix);
|
67
|
setNodeType(nodetype);
|
68
|
setNodeData(nodedata);
|
69
|
setNodeDataNumerical(nodedatanumerical);
|
70
|
}
|
71
|
|
72
|
/** Get functions */
|
73
|
public long getNodeId()
|
74
|
{
|
75
|
return _nodeid;
|
76
|
}
|
77
|
|
78
|
public long getParentNodeId()
|
79
|
{
|
80
|
return _parentnodeid;
|
81
|
}
|
82
|
|
83
|
public long getNodeIndex()
|
84
|
{
|
85
|
return _nodeindex;
|
86
|
}
|
87
|
|
88
|
public String getNodeName()
|
89
|
{
|
90
|
return _nodename;
|
91
|
}
|
92
|
|
93
|
public String getNodeType()
|
94
|
{
|
95
|
return _nodetype;
|
96
|
}
|
97
|
|
98
|
public String getNodePrefix()
|
99
|
{
|
100
|
return _nodeprefix;
|
101
|
}
|
102
|
|
103
|
public String getNodeData()
|
104
|
{
|
105
|
return _nodedata;
|
106
|
}
|
107
|
|
108
|
public float getNodeDataNumerical()
|
109
|
{
|
110
|
return _nodedatanumerical;
|
111
|
}
|
112
|
|
113
|
/** Setter methods **/
|
114
|
|
115
|
/**
|
116
|
* A method used to set the node id of the current node
|
117
|
*
|
118
|
* @param id the new value of the id
|
119
|
*/
|
120
|
public void setNodeId (long id) {
|
121
|
_nodeid = id;
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* A method used to set the node parent id of the current node
|
126
|
*
|
127
|
* @param parentid the new value of the parent id
|
128
|
*/
|
129
|
public void setParentNodeId (long parentid) {
|
130
|
_parentnodeid = parentid;
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* A method used to set the node name of the current node
|
135
|
*
|
136
|
* @param name the new value of the node name
|
137
|
*/
|
138
|
public void setNodeName (String name) {
|
139
|
if (name != null) {
|
140
|
_nodename = name.trim();
|
141
|
} else {
|
142
|
_nodename = null;
|
143
|
}
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* A method used to set the node prefix of the current node
|
148
|
*
|
149
|
* @param prefix the new value of the node prefix
|
150
|
*/
|
151
|
public void setNodePrefix (String prefix) {
|
152
|
if (prefix != null) {
|
153
|
_nodeprefix = prefix.trim();
|
154
|
} else {
|
155
|
_nodeprefix = null;
|
156
|
}
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* A method used to set the node index of the current node
|
161
|
*
|
162
|
* @param index the new value of the node index
|
163
|
*/
|
164
|
public void setNodeIndex (long index) {
|
165
|
_nodeindex = index;
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* A method used to set the node type of the current node
|
170
|
*
|
171
|
* @param type the new value of the node type
|
172
|
*/
|
173
|
public void setNodeType (String type) {
|
174
|
if (type != null) {
|
175
|
_nodetype = type.trim();
|
176
|
} else {
|
177
|
_nodetype = null;
|
178
|
}
|
179
|
}
|
180
|
|
181
|
/**
|
182
|
* A method used to set the node data of the current node
|
183
|
*
|
184
|
* @param data the new value of the node data
|
185
|
*/
|
186
|
public void setNodeData (String data) {
|
187
|
if (data != null) {
|
188
|
_nodedata = data.trim();
|
189
|
} else {
|
190
|
_nodedata = null;
|
191
|
}
|
192
|
}
|
193
|
|
194
|
/**
|
195
|
* A method used to set the numerical node data of the current node
|
196
|
*
|
197
|
* @param datanumerical the new value of the numerical node data
|
198
|
*/
|
199
|
public void setNodeDataNumerical (float datanumerical){
|
200
|
_nodedatanumerical = datanumerical;
|
201
|
}
|
202
|
|
203
|
/** Method compare two records */
|
204
|
public boolean contentEquals(NodeRecord record)
|
205
|
{
|
206
|
boolean flag = true;
|
207
|
logMetacat.info("First nodetype: " + _nodetype);
|
208
|
logMetacat.info("Second nodetype: " + record.getNodeType());
|
209
|
logMetacat.info("First nodename: " + _nodename);
|
210
|
logMetacat.info("Second nodename: " + record.getNodeName());
|
211
|
logMetacat.info("First nodeprefix: " + _nodeprefix);
|
212
|
logMetacat.info("Second nodeprefix: " + record.getNodePrefix());
|
213
|
logMetacat.info("First nodedata: " + _nodedata);
|
214
|
logMetacat.info("Second nodedata: " + record.getNodeData());
|
215
|
if ((_nodename == null && record.getNodeName() != null) ||
|
216
|
(_nodename != null && record.getNodeName() == null) ||
|
217
|
(_nodename != null && record.getNodeName() != null &&
|
218
|
!(_nodename).equals(record.getNodeName())))
|
219
|
{
|
220
|
//compare nodename
|
221
|
flag = false;
|
222
|
}
|
223
|
else if ((_nodetype == null && record.getNodeType() != null) ||
|
224
|
(_nodetype != null && record.getNodeType() == null) ||
|
225
|
(_nodetype != null && record.getNodeType() != null &&
|
226
|
!(_nodetype).equals(record.getNodeType())))
|
227
|
{
|
228
|
// compare node type
|
229
|
flag = false;
|
230
|
}
|
231
|
else if ((_nodeprefix == null && record.getNodePrefix() != null) ||
|
232
|
(_nodeprefix != null && record.getNodePrefix() == null) ||
|
233
|
(_nodeprefix != null && record.getNodePrefix() != null &&
|
234
|
!(_nodeprefix).equals(record.getNodePrefix())))
|
235
|
{
|
236
|
// compare node prefix
|
237
|
flag = false;
|
238
|
}
|
239
|
else if ((_nodedata == null && record.getNodeData() != null) ||
|
240
|
(_nodedata != null && record.getNodeData() == null) ||
|
241
|
(_nodedata != null && record.getNodeData() != null &&
|
242
|
!(_nodedata).equals(record.getNodeData())))
|
243
|
{
|
244
|
// compare node data
|
245
|
flag = false;
|
246
|
}
|
247
|
return flag;
|
248
|
|
249
|
}//contentEquals
|
250
|
}
|