OSDN Git Service

imported from subversion repository
[xerial/xerial-core.git] / src / main / java / org / xerial / lens / relation / LNode.java
1 /*--------------------------------------------------------------------------\r
2  *  Copyright 2009 Taro L. Saito\r
3  *\r
4  *  Licensed under the Apache License, Version 2.0 (the "License");\r
5  *  you may not use this file except in compliance with the License.\r
6  *  You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *  Unless required by applicable law or agreed to in writing, software\r
11  *  distributed under the License is distributed on an "AS IS" BASIS,\r
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *  See the License for the specific language governing permissions and\r
14  *  limitations under the License.\r
15  *--------------------------------------------------------------------------*/\r
16 //--------------------------------------\r
17 // XerialJ\r
18 //\r
19 // LNode.java\r
20 // Since: May 14, 2009 11:36:59 AM\r
21 //\r
22 // $URL: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core/src/main/java/org/xerial/lens/relation/LNode.java $\r
23 // $Author: leo $\r
24 //--------------------------------------\r
25 package org.xerial.lens.relation;\r
26 \r
27 /**\r
28  * Light-weight node that holds only a node ID and node value.\r
29  * \r
30  * @author leo\r
31  * \r
32  */\r
33 public class LNode extends NodeBase<LNode>\r
34 {\r
35     private final static long INVALID_ID = -1;\r
36     private final static String NULL_TEXT = null;\r
37 \r
38     public final long nodeID;\r
39     public final String nodeValue;\r
40 \r
41     public LNode(long nodeID, String nodeValue)\r
42     {\r
43         this.nodeID = nodeID;\r
44         this.nodeValue = nodeValue;\r
45     }\r
46 \r
47     /**\r
48      * Builder class for {@link Node}\r
49      * \r
50      * @author leo\r
51      * \r
52      */\r
53     public static class NodeBuilder\r
54     {\r
55         private long nodeID = INVALID_ID;\r
56         private String nodeValue = NULL_TEXT;\r
57 \r
58         public NodeBuilder()\r
59         {}\r
60 \r
61         public NodeBuilder(Node node)\r
62         {\r
63             this.nodeID = node.nodeID;\r
64             this.nodeValue = node.nodeValue;\r
65         }\r
66 \r
67         public NodeBuilder nodeID(long nodeID)\r
68         {\r
69             this.nodeID = nodeID;\r
70             return this;\r
71         }\r
72 \r
73         public NodeBuilder nodeValue(String nodeValue)\r
74         {\r
75             this.nodeValue = nodeValue;\r
76             return this;\r
77         }\r
78 \r
79         public LNode build()\r
80         {\r
81             return new LNode(nodeID, nodeValue);\r
82         }\r
83 \r
84     }\r
85 \r
86     @Override\r
87     public String toString()\r
88     {\r
89         StringBuilder buf = new StringBuilder();\r
90         buf.append(nodeID);\r
91         if (nodeValue != null)\r
92         {\r
93             buf.append(":");\r
94             buf.append(nodeValue);\r
95         }\r
96         return buf.toString();\r
97     }\r
98 \r
99 }\r