View Javadoc
1 package org.drools.reteoo.impl; 2 3 /* 4 $Id: ReteTuple.java,v 1.3 2002/08/01 18:47:33 bob Exp $ 5 6 Copyright 2002 (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 10 that the following conditions are met: 11 12 1. Redistributions of source code must retain copyright 13 statements and notices. Redistributions must also contain a 14 copy of this document. 15 16 2. Redistributions in binary form must reproduce the 17 above copyright notice, this list of conditions and the 18 following disclaimer in the documentation and/or other 19 materials provided with the distribution. 20 21 3. The name "drools" must not be used to endorse or promote 22 products derived from this Software without prior written 23 permission of The Werken Company. For written permission, 24 please contact bob@werken.com. 25 26 4. Products derived from this Software may not be called "drools" 27 nor may "drools" appear in their names without prior written 28 permission of The Werken Company. "drools" is a registered 29 trademark of The Werken Company. 30 31 5. Due credit should be given to The Werken Company. 32 (http://drools.werken.com/). 33 34 THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS 35 ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 36 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 37 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 38 THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 39 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 40 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 41 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 42 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 43 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 44 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 45 OF THE POSSIBILITY OF SUCH DAMAGE. 46 47 */ 48 49 import org.drools.spi.Tuple; 50 import org.drools.rule.Declaration; 51 52 import java.util.Map; 53 import java.util.HashMap; 54 import java.util.Set; 55 import java.util.HashSet; 56 57 /*** Base Rete-OO <code>Tuple</code> implementation. 58 * 59 * @see Tuple 60 * 61 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a> 62 */ 63 public class ReteTuple implements Tuple 64 { 65 // ------------------------------------------------------------ 66 // Instance members 67 // ------------------------------------------------------------ 68 69 /*** Key colums for this tuple. */ 70 private TupleKey keyColumns; 71 72 /*** Other columns in this tuple. */ 73 private Map otherColumns; 74 75 // ------------------------------------------------------------ 76 // Constructors 77 // ------------------------------------------------------------ 78 79 /*** Construct. 80 */ 81 public ReteTuple() 82 { 83 this.keyColumns = new TupleKey(); 84 this.otherColumns = new HashMap(); 85 } 86 87 /*** Copy constructor. 88 * 89 * @param that The tuple to copy. 90 */ 91 ReteTuple(ReteTuple that) 92 { 93 this.keyColumns = new TupleKey( that.keyColumns ); 94 this.otherColumns = new HashMap( that.otherColumns ); 95 } 96 97 /*** Construct a simple 1-column tuple. 98 * 99 * @param declaration The column declaration. 100 * @param value The column value. 101 */ 102 ReteTuple(Declaration declaration, 103 Object value) 104 { 105 this(); 106 putKeyColumn( declaration, 107 value ); 108 } 109 110 // ------------------------------------------------------------ 111 // Instance methods 112 // ------------------------------------------------------------ 113 114 /*** Set a key column's value. 115 * 116 * @param declaration The column declaration. 117 * @param value The value. 118 */ 119 public void putKeyColumn(Declaration declaration, 120 Object value) 121 { 122 this.keyColumns.put( declaration, 123 value ); 124 } 125 126 /*** Add all columns from another tuple. 127 * 128 * @param that The column source tuple. 129 */ 130 public void putAll(ReteTuple that) 131 { 132 this.keyColumns.putAll( that.keyColumns ); 133 this.otherColumns.putAll( that.otherColumns ); 134 } 135 136 /*** Set an other column's value. 137 * 138 * @param declaration The column declaration. 139 * @param value The value. 140 */ 141 public void putOtherColumn(Declaration declaration, 142 Object value) 143 { 144 this.otherColumns.put( declaration, 145 value ); 146 } 147 148 /*** Retrieve the key for this tuple. 149 * 150 * @return The key. 151 */ 152 TupleKey getKey() 153 { 154 return this.keyColumns; 155 } 156 157 /*** Retrieve the other columns for this tuple. 158 * 159 * @return The other columns. 160 */ 161 Map getOtherColumns() 162 { 163 return this.otherColumns; 164 } 165 166 /*** Determine if this tuple depends upon 167 * a specified object. 168 * 169 * @param object The object to test. 170 * 171 * @return <code>true</code> if this tuple depends upon 172 * the specified object, otherwise <code>false</code>. 173 */ 174 boolean dependsOn(Object object) 175 { 176 return this.keyColumns.containsRootFactObject( object ); 177 } 178 179 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 180 // org.drools.spi.Tuple 181 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 182 183 /*** Retrieve the value of a particular declaration column. 184 * 185 * @param declaration The declaration. 186 * 187 * @return The value. 188 */ 189 public Object get(Declaration declaration) 190 { 191 if ( this.keyColumns.containsDeclaration( declaration ) ) 192 { 193 return this.keyColumns.get( declaration ); 194 } 195 196 return this.otherColumns.get( declaration ); 197 } 198 199 /*** Retrieve all declarations participating in this tuple. 200 * 201 * @return Set of all declarations. 202 */ 203 public Set getDeclarations() 204 { 205 Set decls = new HashSet( this.keyColumns.size() 206 + this.otherColumns.size() ); 207 208 decls.addAll( this.keyColumns.getDeclarations() ); 209 decls.addAll( this.otherColumns.keySet() ); 210 211 return decls; 212 } 213 214 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 215 // java.lang.Object 216 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 217 218 /*** Produce a debug string. 219 * 220 * @return The debug string. 221 */ 222 public String toString() 223 { 224 return "[ReteTuple: key=" + this.keyColumns + "; others=" + this.otherColumns + "]"; 225 } 226 }

This page was automatically generated by Maven