|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
JoinNodeInput.java | 50% | 72.7% | 83.3% | 71.4% |
|
1 | package org.drools.reteoo; | |
2 | ||
3 | /* | |
4 | * $Id: JoinNodeInput.java,v 1.20 2005/02/02 00:23:22 mproctor Exp $ | |
5 | * | |
6 | * Copyright 2001-2003 (C) The Werken Company. All Rights Reserved. | |
7 | * | |
8 | * Redistribution and use of this software and associated documentation | |
9 | * ("Software"), with or without modification, are permitted provided that the | |
10 | * following conditions are met: | |
11 | * | |
12 | * 1. Redistributions of source code must retain copyright statements and | |
13 | * notices. Redistributions must also contain a copy of this document. | |
14 | * | |
15 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
16 | * this list of conditions and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the distribution. | |
18 | * | |
19 | * 3. The name "drools" must not be used to endorse or promote products derived | |
20 | * from this Software without prior written permission of The Werken Company. | |
21 | * For written permission, please contact bob@werken.com. | |
22 | * | |
23 | * 4. Products derived from this Software may not be called "drools" nor may | |
24 | * "drools" appear in their names without prior written permission of The Werken | |
25 | * Company. "drools" is a trademark of The Werken Company. | |
26 | * | |
27 | * 5. Due credit should be given to The Werken Company. (http://werken.com/) | |
28 | * | |
29 | * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' | |
30 | * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
32 | * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE | |
33 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
36 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
37 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
39 | * POSSIBILITY OF SUCH DAMAGE. | |
40 | * | |
41 | */ | |
42 | ||
43 | import org.drools.AssertionException; | |
44 | import org.drools.RetractionException; | |
45 | ||
46 | /** | |
47 | * Input <code>TupleSinkImpl</code> for a <code>JoinNodeImpl</code>. | |
48 | * | |
49 | * @see JoinNode | |
50 | * | |
51 | * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter </a> | |
52 | */ | |
53 | class JoinNodeInput | |
54 | implements | |
55 | TupleSink | |
56 | { | |
57 | // ------------------------------------------------------------ | |
58 | // Constants | |
59 | // ------------------------------------------------------------ | |
60 | ||
61 | /** Left-side input. */ | |
62 | static final int LEFT = 41; | |
63 | ||
64 | /** Right-side input. */ | |
65 | static final int RIGHT = 42; | |
66 | ||
67 | // ------------------------------------------------------------ | |
68 | // Instance members | |
69 | // ------------------------------------------------------------ | |
70 | ||
71 | /** Join node. */ | |
72 | private final JoinNode joinNode; | |
73 | ||
74 | /** Side. */ | |
75 | private final int side; | |
76 | ||
77 | // ------------------------------------------------------------ | |
78 | // Constructors | |
79 | // ------------------------------------------------------------ | |
80 | ||
81 | /** | |
82 | * Construct. | |
83 | * | |
84 | * @param joinNode | |
85 | * Join node. | |
86 | * @param side | |
87 | * Side marker. | |
88 | */ | |
89 | 196 | JoinNodeInput(JoinNode joinNode, |
90 | int side) | |
91 | { | |
92 | 196 | this.joinNode = joinNode; |
93 | 196 | this.side = side; |
94 | } | |
95 | ||
96 | 0 | public String toString() |
97 | { | |
98 | 0 | if ( this.side == LEFT ) |
99 | { | |
100 | 0 | return "LEFT: " + getJoinNode( ).toString( ); |
101 | } | |
102 | else | |
103 | { | |
104 | 0 | return "RIGHT: " + getJoinNode( ).toString( ); |
105 | } | |
106 | } | |
107 | ||
108 | // ------------------------------------------------------------ | |
109 | // Instance methods | |
110 | // ------------------------------------------------------------ | |
111 | ||
112 | /** | |
113 | * Retrieve the side marker. | |
114 | * | |
115 | * @return The side marker. | |
116 | */ | |
117 | 2 | int getSide() |
118 | { | |
119 | 2 | return this.side; |
120 | } | |
121 | ||
122 | /** | |
123 | * Retrieve the destination join node. | |
124 | * | |
125 | * @return The join node. | |
126 | */ | |
127 | 3557 | JoinNode getJoinNode() |
128 | { | |
129 | 3557 | return this.joinNode; |
130 | } | |
131 | ||
132 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
133 | // org.drools.reteoo.impl.TupleSink | |
134 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
135 | ||
136 | /** | |
137 | * Assert a new <code>Tuple</code>. | |
138 | * | |
139 | * @param tuple | |
140 | * The <code>Tuple</code> being asserted. | |
141 | * @param workingMemory | |
142 | * The working memory seesion. | |
143 | * | |
144 | * @throws AssertionException | |
145 | * If an error occurs while asserting. | |
146 | */ | |
147 | 2095 | public void assertTuple(ReteTuple tuple, |
148 | WorkingMemoryImpl workingMemory) throws AssertionException | |
149 | { | |
150 | 2095 | if ( this.side == LEFT ) |
151 | { | |
152 | 1169 | getJoinNode( ).assertLeftTuple( tuple, |
153 | workingMemory ); | |
154 | } | |
155 | else | |
156 | { | |
157 | 926 | getJoinNode( ).assertRightTuple( tuple, |
158 | workingMemory ); | |
159 | } | |
160 | } | |
161 | ||
162 | /** | |
163 | * Retract tuples. | |
164 | * | |
165 | * @param key | |
166 | * The tuple key. | |
167 | * @param workingMemory | |
168 | * The working memory seesion. | |
169 | * | |
170 | * @throws RetractionException | |
171 | * If an error occurs while retracting. | |
172 | */ | |
173 | 1462 | public void retractTuples(TupleKey key, |
174 | WorkingMemoryImpl workingMemory) throws RetractionException | |
175 | { | |
176 | 1462 | getJoinNode( ).retractTuples( key, |
177 | workingMemory ); | |
178 | } | |
179 | ||
180 | } |
|