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