001    /*
002    // $Id: //open/mondrian/src/main/mondrian/rolap/StarPredicate.java#4 $
003    // This software is subject to the terms of the Common Public License
004    // Agreement, available at the following URL:
005    // http://www.opensource.org/licenses/cpl.html.
006    // Copyright (C) 2007-2007 Julian Hyde
007    // All Rights Reserved.
008    // You must accept the terms of that agreement to use this software.
009    */
010    package mondrian.rolap;
011    
012    import mondrian.rolap.sql.SqlQuery;
013    
014    import java.util.List;
015    
016    /**
017     * Condition which constrains a set of values of a single
018     * {@link mondrian.rolap.RolapStar.Column} or a set of columns.
019     *
020     * <p>For example, the predicate
021     * <code>Range([Time].[1997].[Q3], [Time].[1998].[Q2])</code>
022     * constrains the <code>year</code> and <code>quarter</code> columns:
023     *
024     * <blockquote><code>
025     * &nbsp;&nbsp;((year = 1997 and quarter >= 'Q3')<br/>
026     * &nbsp;&nbsp;&nbsp;&nbsp;or (year > 1997))<br/>
027     * and ((year = 1998 and quarter <= 'Q2')<br/>
028     * &nbsp;&nbsp;&nbsp;&nbsp;or (year < 1998))</code></blockquote>
029     *
030     * @author jhyde
031     * @version $Id: //open/mondrian/src/main/mondrian/rolap/StarPredicate.java#4 $
032     * @since Jan 15, 2007
033     */
034    public interface StarPredicate {
035        /**
036         * Returns a list of constrained columns.
037         *
038         * @return List of constrained columns
039         */
040        public List<RolapStar.Column> getConstrainedColumnList();
041    
042        /**
043         * Returns a bitmap of constrained columns to speed up comparison
044         * @return bitmap representing all constraining columns.
045         */
046        public BitKey getConstrainedColumnBitKey();
047    
048        /**
049         * Appends a description of this predicate to a <code>StringBuilder</code>.
050         * For example:<ul>
051         * <li>=any</li>
052         * <li>=5</li>
053         * <li>in (2, 4, 6)</li>
054         * </ul>
055         *
056         * @param buf Builder to append to
057         */
058        public abstract void describe(StringBuilder buf);
059    
060        /**
061         * Evaluates a constraint against a list of values.
062         *
063         * <p>If one of the values is {@link #WILDCARD}, returns true if constraint is
064         * true for all possible values of that column.
065         *
066         * @param valueList List of values, one for each constrained column
067         * @return Whether constraint holds for given set of values
068         */
069        public boolean evaluate(List<Object> valueList);
070    
071        /**
072         * Returns whether this Predicate has the same constraining effect as the
073         * other constraint. This is weaker than {@link Object#equals(Object)}: it
074         * is possible for two different members to constrain the same column in the
075         * same way.
076         *
077         * @param that Other predicate
078         * @return whether the other predicate is equivalent
079         */
080        boolean equalConstraint(StarPredicate that);
081    
082        /**
083         * Returns the logical inverse of this Predicate. The result is a Predicate
084         * which holds whenever this predicate holds but the other does not.
085         *
086         * @pre predicate != null
087         * @param predicate Predicate
088         * @return Combined predicate
089         */
090        StarPredicate minus(StarPredicate predicate);
091    
092        /**
093         * Returns this union of this Predicate with another. The result is a
094         * Predicate which holds whenever either predicate holds.
095         *
096         * @pre predicate != null
097         * @param predicate Predicate
098         * @return Combined predicate
099         */
100        StarPredicate or(StarPredicate predicate);
101    
102        /**
103         * Returns this intersection of this Predicate with another. The result is a
104         * Predicate which holds whenever both predicates hold.
105         *
106         * @pre predicate != null
107         * @param predicate Predicate
108         * @return Combined predicate
109         */
110        StarPredicate and(StarPredicate predicate);
111    
112        /**
113         * Wildcard value for {@link #evaluate(java.util.List)}.
114         */
115        Object WILDCARD = new Object();
116    
117        void toSql(SqlQuery sqlQuery, StringBuilder buf);
118    }
119    
120    // End StarPredicate.java