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 6012 leinfelder
import java.sql.Timestamp;
30
31 2663 sgarg
import org.apache.log4j.Logger;
32
33 388 jones
/**
34
 * A utility class that encapsulates a node and its data
35
 */
36
public class NodeRecord {
37 5311 daigle
  private long _nodeid = -1;
38
  private long _parentnodeid = -1;
39
  private long _nodeindex = -1;
40
  private String _nodename = null;
41
  private String _nodeprefix = null;
42
  private String _nodetype = null;
43
  private String _nodedata = null;
44
  private float _nodedatanumerical = -1;
45 6012 leinfelder
  private Timestamp _nodedatadate = null;
46
47 2663 sgarg
  private Logger logMetacat = Logger.getLogger(NodeRecord.class);
48 388 jones
49
  /**
50
   * Constructor
51
   */
52
  public NodeRecord(long nodeid, long parentnodeid, long nodeindex,
53 826 bojilova
                    String nodetype, String nodename, String nodeprefix,
54
                    String nodedata) {
55 5311 daigle
	    setNodeId(nodeid);
56
	    setParentNodeId(parentnodeid);
57
	    setNodeIndex(nodeindex);
58
	    setNodeName(nodename);
59
	    setNodePrefix(nodeprefix);
60
	    setNodeType(nodetype);
61
	    setNodeData(nodedata);
62 388 jones
  }
63 1501 tao
64 5311 daigle
  public NodeRecord(long nodeid, long parentnodeid, long nodeindex, String nodetype,
65 6012 leinfelder
			String nodename, String nodeprefix, String nodedata, float nodedatanumerical, Timestamp nodedatadate) {
66 5311 daigle
		setNodeId(nodeid);
67
		setParentNodeId(parentnodeid);
68
		setNodeIndex(nodeindex);
69
		setNodeName(nodename);
70
		setNodePrefix(nodeprefix);
71
		setNodeType(nodetype);
72
		setNodeData(nodedata);
73
		setNodeDataNumerical(nodedatanumerical);
74 6012 leinfelder
		setNodeDataDate(nodedatadate);
75 5311 daigle
	}
76 2762 sgarg
77 5311 daigle
  /** Get functions */
78 1501 tao
  public long getNodeId()
79
  {
80 5311 daigle
    return _nodeid;
81 1501 tao
  }
82
83
  public long getParentNodeId()
84
  {
85 5311 daigle
    return _parentnodeid;
86 1501 tao
  }
87
88
  public long getNodeIndex()
89
  {
90 5311 daigle
    return _nodeindex;
91 1501 tao
  }
92
93
  public String getNodeName()
94
  {
95 5311 daigle
    return _nodename;
96 1501 tao
  }
97
98
  public String getNodeType()
99
  {
100 5311 daigle
    return _nodetype;
101 1501 tao
  }
102
103
  public String getNodePrefix()
104
  {
105 5311 daigle
    return _nodeprefix;
106 1501 tao
  }
107
108
  public String getNodeData()
109
  {
110 5311 daigle
    return _nodedata;
111 1501 tao
  }
112 2762 sgarg
113
  public float getNodeDataNumerical()
114
  {
115 5311 daigle
    return _nodedatanumerical;
116 2762 sgarg
  }
117 3144 cjones
118 6012 leinfelder
  public Timestamp getNodeDataDate()
119
  {
120
    return _nodedatadate;
121
  }
122
123 3144 cjones
  /** Setter methods **/
124
125
  /**
126
   * A method used to set the node id of the current node
127
   *
128
   * @param id  the new value of the id
129
   */
130 5311 daigle
  public void setNodeId (long id) {
131
	  _nodeid = id;
132 3144 cjones
  }
133
134
  /**
135
   * A method used to set the node parent id of the current node
136
   *
137
   * @param parentid  the new value of the parent id
138
   */
139 5311 daigle
  public void setParentNodeId (long parentid) {
140
	  _parentnodeid = parentid;
141 3144 cjones
  }
142
143
  /**
144
   * A method used to set the node name of the current node
145
   *
146
   * @param name  the new value of the node name
147
   */
148 5311 daigle
  public void setNodeName (String name) {
149
	  if (name != null) {
150
		  _nodename = name.trim();
151
	  } else {
152
		  _nodename = null;
153
	  }
154 3144 cjones
  }
155
156
  /**
157
   * A method used to set the node prefix of the current node
158
   *
159
   * @param prefix  the new value of the node prefix
160
   */
161 5311 daigle
  public void setNodePrefix (String prefix) {
162
	  if (prefix != null) {
163
		  _nodeprefix = prefix.trim();
164
	  } else {
165
		  _nodeprefix = null;
166
	  }
167 3144 cjones
  }
168
169
  /**
170
   * A method used to set the node index of the current node
171
   *
172
   * @param index  the new value of the node index
173
   */
174 5311 daigle
  public void setNodeIndex (long index) {
175
	  _nodeindex = index;
176 3144 cjones
  }
177
178
  /**
179
   * A method used to set the node type of the current node
180
   *
181
   * @param type  the new value of the node type
182
   */
183 5311 daigle
  public void setNodeType (String type) {
184
	  if (type != null) {
185
		  _nodetype = type.trim();
186
	  } else {
187
		  _nodetype = null;
188
	  }
189 3144 cjones
  }
190
191
  /**
192
   * A method used to set the node data of the current node
193
   *
194
   * @param data  the new value of the node data
195
   */
196 5311 daigle
  public void setNodeData (String data) {
197
	  if (data != null) {
198
		  _nodedata = data.trim();
199
	  } else {
200
		  _nodedata = null;
201
	  }
202 3144 cjones
  }
203
204
  /**
205
   * A method used to set the numerical node data of the current node
206
   *
207
   * @param datanumerical  the new value of the numerical node data
208
   */
209
  public void setNodeDataNumerical (float datanumerical){
210 5311 daigle
    _nodedatanumerical = datanumerical;
211 3144 cjones
  }
212
213 6012 leinfelder
  public void setNodeDataDate(Timestamp datadate){
214
	    _nodedatadate = datadate;
215
	  }
216
217 1546 tao
  /** Method compare two records */
218
  public boolean contentEquals(NodeRecord record)
219
  {
220
    boolean flag = true;
221 5311 daigle
    logMetacat.info("First nodetype: " + _nodetype);
222
    logMetacat.info("Second nodetype: " + record.getNodeType());
223
    logMetacat.info("First nodename: " + _nodename);
224
    logMetacat.info("Second nodename: " + record.getNodeName());
225
    logMetacat.info("First nodeprefix: " + _nodeprefix);
226
    logMetacat.info("Second nodeprefix: " + record.getNodePrefix());
227
    logMetacat.info("First nodedata: " + _nodedata);
228
    logMetacat.info("Second nodedata: " + record.getNodeData());
229
    if ((_nodename == null && record.getNodeName() != null) ||
230
        (_nodename != null && record.getNodeName() == null) ||
231
        (_nodename != null && record.getNodeName() != null &&
232
        !(_nodename).equals(record.getNodeName())))
233 1546 tao
    {
234
      //compare nodename
235
      flag = false;
236
    }
237 5311 daigle
    else if ((_nodetype == null && record.getNodeType() != null) ||
238
             (_nodetype != null && record.getNodeType() == null) ||
239
             (_nodetype != null && record.getNodeType() != null &&
240
             !(_nodetype).equals(record.getNodeType())))
241 1546 tao
    {
242
      // compare node type
243
      flag = false;
244
    }
245 5311 daigle
    else if ((_nodeprefix == null && record.getNodePrefix() != null) ||
246
             (_nodeprefix != null && record.getNodePrefix() == null) ||
247
             (_nodeprefix != null && record.getNodePrefix() != null &&
248
             !(_nodeprefix).equals(record.getNodePrefix())))
249 1546 tao
    {
250
      // compare node prefix
251
      flag = false;
252
    }
253 5311 daigle
    else if ((_nodedata == null && record.getNodeData() != null) ||
254
             (_nodedata != null && record.getNodeData() == null) ||
255
             (_nodedata != null && record.getNodeData() != null &&
256
             !(_nodedata).equals(record.getNodeData())))
257 1546 tao
    {
258
      // compare node data
259
      flag = false;
260
    }
261
    return flag;
262
263
  }//contentEquals
264 388 jones
}