001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: ExpressionSet.java,v 1.17 2008/01/02 12:07:57 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.query;
008:
009: import java.util.*;
010:
011: import com.hp.hpl.jena.util.CollectionFactory;
012:
013: /**
014: ExpressionSet: represent a set of (boolean) expressions ANDed together.
015:
016: @author kers
017: */
018: public class ExpressionSet {
019: private Set expressions = CollectionFactory.createHashedSet();
020:
021: /**
022: Initialise an expression set with no members.
023: */
024: public ExpressionSet() {
025: }
026:
027: /**
028: Answer this expressionset after e has been anded into it.
029: @param e the expression to and into the set
030: @return this ExpressionSet
031: */
032: public ExpressionSet add(Expression e) {
033: expressions.add(e);
034: return this ;
035: }
036:
037: /**
038: Answer true iff this ExpressionSet is non-trivial (ie non-empty).
039: */
040: public boolean isComplex() {
041: return !expressions.isEmpty();
042: }
043:
044: // /**
045: // Evaluate this expression set, delivering true iff no member of the set evaluates
046: // to false.
047: //
048: // @param vv the mapping from variables to values
049: // @return true iff no member evaluates to false
050: // */
051: // public boolean evalBool( VariableValues vv )
052: // {
053: // Iterator it = expressions.iterator();
054: // while (it.hasNext())
055: // if (((Expression) it.next()).evalBool( vv ) == false) return false;
056: // return true;
057: // }
058:
059: /**
060: Answer a ValuatorSet which contains exactly the valuators for each
061: Expression in this ExpressionSet, prepared against the VariableIndexes vi.
062: */
063: public ValuatorSet prepare(VariableIndexes vi) {
064: ValuatorSet result = new ValuatorSet();
065: Iterator it = expressions.iterator();
066: while (it.hasNext())
067: result.add(((Expression) it.next()).prepare(vi));
068: return result;
069: }
070:
071: /**
072: Answer an iterator over all the Expressions in this ExpressionSet.
073: */
074: public Iterator iterator() {
075: return expressions.iterator();
076: }
077:
078: /**
079: Answer a string representing this ExpressionSet for human consumption.
080: */
081: public String toString() {
082: return expressions.toString();
083: }
084: }
085:
086: /*
087: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
088: All rights reserved.
089:
090: Redistribution and use in source and binary forms, with or without
091: modification, are permitted provided that the following conditions
092: are met:
093:
094: 1. Redistributions of source code must retain the above copyright
095: notice, this list of conditions and the following disclaimer.
096:
097: 2. Redistributions in binary form must reproduce the above copyright
098: notice, this list of conditions and the following disclaimer in the
099: documentation and/or other materials provided with the distribution.
100:
101: 3. The name of the author may not be used to endorse or promote products
102: derived from this software without specific prior written permission.
103:
104: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
105: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
106: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
107: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
108: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
109: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
110: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
111: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
112: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
113: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114: */
|