001 /* 002 // $Id: //open/mondrian/src/main/mondrian/rolap/agg/LiteralStarPredicate.java#3 $ 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) 2006-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.agg; 011 012 import mondrian.rolap.StarPredicate; 013 import mondrian.rolap.RolapStar; 014 import mondrian.rolap.StarColumnPredicate; 015 import mondrian.rolap.sql.SqlQuery; 016 017 import java.util.Collection; 018 import java.util.List; 019 020 /** 021 * A constraint which always returns true or false. 022 * 023 * @author jhyde 024 * @version $Id: //open/mondrian/src/main/mondrian/rolap/agg/LiteralStarPredicate.java#3 $ 025 * @since Nov 2, 2006 026 */ 027 public class LiteralStarPredicate extends AbstractColumnPredicate { 028 private final boolean value; 029 030 public static final LiteralStarPredicate TRUE = 031 new LiteralStarPredicate(null, true); 032 public static final LiteralStarPredicate FALSE = 033 new LiteralStarPredicate(null, false); 034 035 /** 036 * Creates a LiteralStarPredicate. 037 * 038 * @param column Constrained column 039 * @param value Truth value 040 */ 041 public LiteralStarPredicate(RolapStar.Column column, boolean value) { 042 super(column); 043 this.value = value; 044 } 045 046 047 public int hashCode() { 048 return value ? 2 : 1; 049 } 050 051 public boolean equals(Object obj) { 052 if (obj instanceof LiteralStarPredicate) { 053 LiteralStarPredicate that = 054 (LiteralStarPredicate) obj; 055 return this.value == that.value; 056 } else { 057 return false; 058 } 059 } 060 061 public boolean evaluate(List<Object> valueList) { 062 assert valueList.isEmpty(); 063 return value; 064 } 065 066 public boolean equalConstraint(StarPredicate that) { 067 throw new UnsupportedOperationException(); 068 } 069 070 public String toString() { 071 return Boolean.toString(value); 072 } 073 074 public void values(Collection<Object> collection) { 075 } 076 077 public boolean evaluate(Object value) { 078 return this.value; 079 } 080 081 public void describe(StringBuilder buf) { 082 buf.append("=any"); 083 } 084 085 public Overlap intersect( 086 StarColumnPredicate predicate) { 087 return new Overlap(value, null, 0f); 088 } 089 090 public boolean mightIntersect(StarPredicate other) { 091 // FALSE intersects nothing 092 // TRUE intersects everything except FALSE 093 if (!value) { 094 return false; 095 } else if (other instanceof LiteralStarPredicate) { 096 return ((LiteralStarPredicate) other).value; 097 } else { 098 return true; 099 } 100 } 101 102 public StarColumnPredicate minus(StarPredicate predicate) { 103 assert predicate != null; 104 if (value) { 105 // We have no 'not' operator, so there's no shorter way to represent 106 // "true - constraint". 107 return new MinusStarPredicate(this, (StarColumnPredicate) predicate); 108 } else { 109 // "false - constraint" is "false" 110 return this; 111 } 112 } 113 114 public StarColumnPredicate cloneWithColumn(RolapStar.Column column) { 115 return this; 116 } 117 118 public boolean getValue() { 119 return value; 120 } 121 122 public void toSql(SqlQuery sqlQuery, StringBuilder buf) { 123 // e.g. "true" 124 buf.append(value); 125 } 126 } 127 128 // End LiteralStarPredicate.java