Beispiel #1
0
 /**
  * Indicates whether some other KVOpExpression is "equal to this one.
  *
  * @param o the reference object with which to compare.
  * @return <code>true</code> if this object is the same as the o argument; <code>false</code>
  *     otherwise.
  * @see #hashCode()
  */
 public boolean equals(Object o) {
   if (o == this) return (true);
   if (!(o instanceof KVOpExpression)) return (false);
   KVOpExpression other = (KVOpExpression) o;
   if (getName().compareTo(other.getName()) != 0 || op != other.getOp() || val != other.getValue())
     return (false);
   return (true);
 }
Beispiel #2
0
 /**
  * Returns the supplied string as an expression.
  *
  * <p>This utility function attempts to identify the supplied string as an expression. It tries in
  * turn each of the known sub-classes until finally, if none can be recognized, an exception is
  * thrown. This function is not immune to mistakenly mis-classifying an expression. It is the
  * responsibility of the concrete Exrpession classes to ensure that syntactic integrity is
  * maintained with respect to potential cases of mistaken identity.
  *
  * @param raw The candidate expression
  * @throws IllegalArgumentException If no valid expression can be found
  */
 static Expression valueOf(String raw) throws IllegalArgumentException {
   Expression exp = null;
   /*
    * TODO It would be better if subclasses registered,
    * but this hard coded list will do until such a time
    */
   if ((exp = KVOpExpression.valueOf(raw)) == null)
     if ((exp = KVExpression.valueOf(raw)) == null) exp = KExpression.valueOf(raw);
   if (exp == null) throw new IllegalArgumentException("unrecognized expression: " + raw);
   return (exp);
 }
Beispiel #3
0
 /**
  * Return true if the supplied expression "contradicts" this expression. If the supplied
  * expression is not of the same type, then it cannot contradict it. If the names are different
  * then there can be no contradiction.
  *
  * <p>Contradiction occurs if the operator is the same or if they aren't the same and the operator
  * is < or > and the values aren't simultanteously achievable.
  *
  * @param o Expression to examine for contradiction.
  */
 public boolean contradicts(Expression o) {
   if (!(o instanceof KVOpExpression)) return (false);
   KVOpExpression other = (KVOpExpression) o;
   if (getName().compareTo(other.getName()) != 0) return (false);
   if (getOp() != other.getOp()) {
     if (getOp() != NT && other.getOp() != NT) {
       if (getOp() == GT) {
         if (getValue() < other.getValue()) return (false);
       } else {
         if (getValue() > other.getValue()) return (false);
       }
     } else return (false);
   }
   return (true);
 }