Project

General

Profile

1 388 jones
/**
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$'
9
 *     '$Date$'
10
 * '$Revision$'
11 669 jones
 *
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 388 jones
 */
26
27
package edu.ucsb.nceas.metacat;
28
29 2663 sgarg
import org.apache.log4j.Logger;
30
31 388 jones
/**
32
 * A utility class that encapsulates a node and its data
33
 */
34
public class NodeRecord {
35 5311 daigle
  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 2663 sgarg
  private Logger logMetacat = Logger.getLogger(NodeRecord.class);
44 388 jones
45
  /**
46
   * Constructor
47
   */
48
  public NodeRecord(long nodeid, long parentnodeid, long nodeindex,
49 826 bojilova
                    String nodetype, String nodename, String nodeprefix,
50
                    String nodedata) {
51 5311 daigle
	    setNodeId(nodeid);
52
	    setParentNodeId(parentnodeid);
53
	    setNodeIndex(nodeindex);
54
	    setNodeName(nodename);
55
	    setNodePrefix(nodeprefix);
56
	    setNodeType(nodetype);
57
	    setNodeData(nodedata);
58 388 jones
  }
59 1501 tao
60 5311 daigle
  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 2762 sgarg
72 5311 daigle
  /** Get functions */
73 1501 tao
  public long getNodeId()
74
  {
75 5311 daigle
    return _nodeid;
76 1501 tao
  }
77
78
  public long getParentNodeId()
79
  {
80 5311 daigle
    return _parentnodeid;
81 1501 tao
  }
82
83
  public long getNodeIndex()
84
  {
85 5311 daigle
    return _nodeindex;
86 1501 tao
  }
87
88
  public String getNodeName()
89
  {
90 5311 daigle
    return _nodename;
91 1501 tao
  }
92
93
  public String getNodeType()
94
  {
95 5311 daigle
    return _nodetype;
96 1501 tao
  }
97
98
  public String getNodePrefix()
99
  {
100 5311 daigle
    return _nodeprefix;
101 1501 tao
  }
102
103
  public String getNodeData()
104
  {
105 5311 daigle
    return _nodedata;
106 1501 tao
  }
107 2762 sgarg
108
  public float getNodeDataNumerical()
109
  {
110 5311 daigle
    return _nodedatanumerical;
111 2762 sgarg
  }
112 3144 cjones
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 5311 daigle
  public void setNodeId (long id) {
121
	  _nodeid = id;
122 3144 cjones
  }
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 5311 daigle
  public void setParentNodeId (long parentid) {
130
	  _parentnodeid = parentid;
131 3144 cjones
  }
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 5311 daigle
  public void setNodeName (String name) {
139
	  if (name != null) {
140
		  _nodename = name.trim();
141
	  } else {
142
		  _nodename = null;
143
	  }
144 3144 cjones
  }
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 5311 daigle
  public void setNodePrefix (String prefix) {
152
	  if (prefix != null) {
153
		  _nodeprefix = prefix.trim();
154
	  } else {
155
		  _nodeprefix = null;
156
	  }
157 3144 cjones
  }
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 5311 daigle
  public void setNodeIndex (long index) {
165
	  _nodeindex = index;
166 3144 cjones
  }
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 5311 daigle
  public void setNodeType (String type) {
174
	  if (type != null) {
175
		  _nodetype = type.trim();
176
	  } else {
177
		  _nodetype = null;
178
	  }
179 3144 cjones
  }
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 5311 daigle
  public void setNodeData (String data) {
187
	  if (data != null) {
188
		  _nodedata = data.trim();
189
	  } else {
190
		  _nodedata = null;
191
	  }
192 3144 cjones
  }
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 5311 daigle
    _nodedatanumerical = datanumerical;
201 3144 cjones
  }
202
203 1546 tao
  /** Method compare two records */
204
  public boolean contentEquals(NodeRecord record)
205
  {
206
    boolean flag = true;
207 5311 daigle
    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 1546 tao
    {
220
      //compare nodename
221
      flag = false;
222
    }
223 5311 daigle
    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 1546 tao
    {
228
      // compare node type
229
      flag = false;
230
    }
231 5311 daigle
    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 1546 tao
    {
236
      // compare node prefix
237
      flag = false;
238
    }
239 5311 daigle
    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 1546 tao
    {
244
      // compare node data
245
      flag = false;
246
    }
247
    return flag;
248
249
  }//contentEquals
250 388 jones
}