OSDN Git Service

add LogWriter interface to enable switch log format
[xerial/xerial-core.git] / src / main / java / org / xerial / lens / relation / NodeBase.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 // NodeBase.java\r
20 // Since: 2009/05/13 22:28:04\r
21 //\r
22 // $URL$\r
23 // $Author$\r
24 //--------------------------------------\r
25 package org.xerial.lens.relation;\r
26 \r
27 import org.xerial.core.XerialError;\r
28 import org.xerial.core.XerialErrorCode;\r
29 \r
30 /**\r
31  * \r
32  * Base implementation of the TreeNode\r
33  * \r
34  * @author leo\r
35  * \r
36  * @param <NodeType>\r
37  */\r
38 public abstract class NodeBase<NodeType> implements TupleElement<NodeType> {\r
39     protected NodeBase() {}\r
40 \r
41     public boolean isAtom() {\r
42         return true;\r
43     }\r
44 \r
45     public boolean isTuple() {\r
46         return false;\r
47     }\r
48 \r
49     /**\r
50      * Always return 1\r
51      * \r
52      * @return\r
53      */\r
54     public int size() {\r
55         return 1;\r
56     }\r
57 \r
58     public Tuple<NodeType> castToTuple() {\r
59         return null;\r
60     }\r
61 \r
62     public TupleElement<NodeType> get(TupleIndex index) {\r
63         if (index.size() == 0 && index.get(0) == 0)\r
64             return (TupleElement<NodeType>) this;\r
65         else\r
66             throw new XerialError(XerialErrorCode.INVALID_STATE);\r
67     }\r
68 \r
69     @SuppressWarnings("unchecked")\r
70     public NodeType getElement(TupleIndex index) {\r
71         if (!(index.size() == 1 && index.get(0) == 0))\r
72             throw new XerialError(XerialErrorCode.INVALID_STATE);\r
73         else\r
74             return (NodeType) this;\r
75     }\r
76 \r
77     @SuppressWarnings("unchecked")\r
78     public NodeType castToElement() {\r
79         return (NodeType) this;\r
80     }\r
81 \r
82     @SuppressWarnings("unchecked")\r
83     public void accept(TupleElementVisitor<NodeType> visitor) {\r
84         visitor.visitNode((NodeType) this);\r
85     }\r
86 \r
87 }