Project

General

Profile

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: leinfelder $'
9
 *     '$Date: 2011-03-16 22:56:31 -0700 (Wed, 16 Mar 2011) $'
10
 * '$Revision: 6012 $'
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 java.sql.Timestamp;
30

    
31
import org.apache.log4j.Logger;
32

    
33
/**
34
 * A utility class that encapsulates a node and its data
35
 */
36
public class NodeRecord {
37
  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
  private Timestamp _nodedatadate = null;
46

    
47
  private Logger logMetacat = Logger.getLogger(NodeRecord.class);
48

    
49
  /**
50
   * Constructor
51
   */
52
  public NodeRecord(long nodeid, long parentnodeid, long nodeindex,
53
                    String nodetype, String nodename, String nodeprefix, 
54
                    String nodedata) {
55
	    setNodeId(nodeid);
56
	    setParentNodeId(parentnodeid);
57
	    setNodeIndex(nodeindex);
58
	    setNodeName(nodename);
59
	    setNodePrefix(nodeprefix);
60
	    setNodeType(nodetype);
61
	    setNodeData(nodedata);
62
  }
63
  
64
  public NodeRecord(long nodeid, long parentnodeid, long nodeindex, String nodetype,
65
			String nodename, String nodeprefix, String nodedata, float nodedatanumerical, Timestamp nodedatadate) {
66
		setNodeId(nodeid);
67
		setParentNodeId(parentnodeid);
68
		setNodeIndex(nodeindex);
69
		setNodeName(nodename);
70
		setNodePrefix(nodeprefix);
71
		setNodeType(nodetype);
72
		setNodeData(nodedata);
73
		setNodeDataNumerical(nodedatanumerical);
74
		setNodeDataDate(nodedatadate);
75
	}
76
  
77
  /** Get functions */
78
  public long getNodeId()
79
  {
80
    return _nodeid;
81
  }
82
  
83
  public long getParentNodeId()
84
  {
85
    return _parentnodeid;
86
  }
87
  
88
  public long getNodeIndex()
89
  {
90
    return _nodeindex;
91
  }
92
  
93
  public String getNodeName()
94
  {
95
    return _nodename;
96
  }
97
  
98
  public String getNodeType()
99
  {
100
    return _nodetype;
101
  }
102
  
103
  public String getNodePrefix()
104
  {
105
    return _nodeprefix;
106
  }
107
  
108
  public String getNodeData()
109
  {
110
    return _nodedata;
111
  }
112

    
113
  public float getNodeDataNumerical()
114
  {
115
    return _nodedatanumerical;
116
  }
117
  
118
  public Timestamp getNodeDataDate()
119
  {
120
    return _nodedatadate;
121
  }
122
  
123
  /** 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
  public void setNodeId (long id) {
131
	  _nodeid = id;
132
  }
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
  public void setParentNodeId (long parentid) {
140
	  _parentnodeid = parentid;
141
  }
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
  public void setNodeName (String name) {
149
	  if (name != null) {
150
		  _nodename = name.trim();
151
	  } else {
152
		  _nodename = null;
153
	  }
154
  }
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
  public void setNodePrefix (String prefix) {
162
	  if (prefix != null) {
163
		  _nodeprefix = prefix.trim(); 
164
	  } else {
165
		  _nodeprefix = null;
166
	  }
167
  }
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
  public void setNodeIndex (long index) {
175
	  _nodeindex = index;
176
  }
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
  public void setNodeType (String type) {
184
	  if (type != null) {
185
		  _nodetype = type.trim();
186
	  } else {
187
		  _nodetype = null;
188
	  }
189
  }
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
  public void setNodeData (String data) {
197
	  if (data != null) {
198
		  _nodedata = data.trim();
199
	  } else {
200
		  _nodedata = null;
201
	  }
202
  }
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
    _nodedatanumerical = datanumerical;
211
  }
212
  
213
  public void setNodeDataDate(Timestamp datadate){
214
	    _nodedatadate = datadate;
215
	  }
216
  
217
  /** Method compare two records */
218
  public boolean contentEquals(NodeRecord record)
219
  {
220
    boolean flag = true;
221
    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
    {
234
      //compare nodename
235
      flag = false;
236
    }
237
    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
    {
242
      // compare node type
243
      flag = false;
244
    }
245
    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
    {
250
      // compare node prefix
251
      flag = false;
252
    }
253
    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
    {
258
      // compare node data
259
      flag = false;
260
    }
261
    return flag;
262
    
263
  }//contentEquals
264
}
(49-49/65)