001 /*
002 // $Id: //open/mondrian-release/3.2/src/main/mondrian/rolap/StarColumnPredicate.java#1 $
003 // This software is subject to the terms of the Eclipse Public License v1.0
004 // Agreement, available at the following URL:
005 // http://www.eclipse.org/legal/epl-v10.html.
006 // Copyright (C) 2007-2009 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 java.util.Collection;
013
014 /**
015 * Refinement of {@link StarPredicate} which constrains precisely one column.
016 *
017 * @author jhyde
018 * @version $Id: //open/mondrian-release/3.2/src/main/mondrian/rolap/StarColumnPredicate.java#1 $
019 * @since Jan 15, 2007
020 */
021 public interface StarColumnPredicate extends StarPredicate {
022 /**
023 * Adds the values in this constraint to a collection.
024 *
025 * @param collection Collection to add values to
026 */
027 void values(Collection<Object> collection);
028
029 /**
030 * Returns whether this constraint would return <code>true</code> for a
031 * given value.
032 *
033 * @param value Value
034 * @return Whether predicate is true
035 */
036 boolean evaluate(Object value);
037
038 /**
039 * Returns the column constrained by this predicate.
040 *
041 * @return Column constrained by this predicate.
042 */
043 RolapStar.Column getConstrainedColumn();
044
045 /**
046 * Applies this predicate to a predicate from the axis of
047 * a segment, and tests for overlap. The result might be that there
048 * is no overlap, full overlap (so the constraint can be removed),
049 * or partial overlap (so the constraint will need to be replaced with
050 * a stronger constraint, say 'x > 10' is replaced with 'x > 20').
051 *
052 * @param predicate Predicate
053 * @return description of overlap between predicates, if any
054 */
055 Overlap intersect(StarColumnPredicate predicate);
056
057 /**
058 * Returns whether this predicate might intersect another predicate.
059 * That is, whether there might be a value which holds true for both
060 * constraints.
061 *
062 * @param other Other constraint
063 * @return Whether constraints intersect
064 */
065 boolean mightIntersect(StarPredicate other);
066
067 // override with stricter return type
068 StarColumnPredicate minus(StarPredicate predicate);
069
070 /**
071 * Returns this union of this Predicate with another.
072 *
073 * <p>Unlike {@link #or}, the other predicate must be on this column, and
074 * the result is a column predicate.
075 *
076 * @param predicate Another predicate on this column
077 * @return Union predicate on this column
078 */
079 StarColumnPredicate orColumn(StarColumnPredicate predicate);
080
081 /**
082 * This method is required because unfortunately some ColumnPredicate
083 * objects are created without a column.
084 *
085 * <p>We call this method to provide a fake column, then call
086 * {@link #toSql(mondrian.rolap.sql.SqlQuery, StringBuilder)}.
087 *
088 * <p>todo: remove this method when
089 * {@link mondrian.util.Bug#BugMondrian313Fixed bug MONDRIAN-313} and
090 * {@link mondrian.util.Bug#BugMondrian314Fixed bug MONDRIAN-314} are fixed.
091 */
092 StarColumnPredicate cloneWithColumn(RolapStar.Column column);
093
094 /**
095 * Returned by
096 * {@link mondrian.rolap.StarColumnPredicate#intersect},
097 * describes whether two predicates overlap, and if so, the remaining
098 * predicate.
099 */
100 public static class Overlap {
101 public final boolean matched;
102 public final StarColumnPredicate remaining;
103 public final float selectivity;
104
105 public Overlap(
106 boolean matched,
107 StarColumnPredicate remaining,
108 float selectivity)
109 {
110 this.matched = matched;
111 this.remaining = remaining;
112 this.selectivity = selectivity;
113 }
114 }
115 }
116
117 // End StarColumnPredicate.java