All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.exigen.ie.constrainer.IntBoolExpConst Maven / Gradle / Ivy

package com.exigen.ie.constrainer;

///////////////////////////////////////////////////////////////////////////////
/*
 * Copyright Exigen Group 1998, 1999, 2000
 * 320 Amboy Ave., Metuchen, NJ, 08840, USA, www.exigengroup.com
 *
 * The copyright to the computer program(s) herein
 * is the property of Exigen Group, USA. All rights reserved.
 * The program(s) may be used and/or copied only with
 * the written permission of Exigen Group
 * or in accordance with the terms and conditions
 * stipulated in the agreement/contract under which
 * the program(s) have been supplied.
 */
///////////////////////////////////////////////////////////////////////////////

/**
 * IntBoolExp wraps a boolean value (that is reffered to as "boolean_const"
 * in this documentation) into object that is to be used like constant
 * expression of IntBoolExp type.
 */
public class IntBoolExpConst extends IntExpConst implements IntBoolExp
{
  /**
   * Constructs an IntBoolExpConst and initializes "boolean_const" (Wrapped
   * boolean value) with value.
   */
  public IntBoolExpConst(Constrainer c, boolean value)
  {
    super(c, value ? 1:0);
  }
  /**
   * Acts like a following constructor:
   * new IntBoolExpConst(c,value)
   */
  public static IntBoolExpConst getIntBoolExpConst(Constrainer c, boolean value)
  {
  //    return new IntBoolExpConst(constrainer(),value);
    return (IntBoolExpConst)c.expressionFactory().getExpression(IntBoolExpConst.class,
                                                                new Object[]{c,new Boolean(value)},
                                                                new Class[]{Constrainer.class, boolean.class});
  }
  /**
   *
   * @return (boolean_const == 0)
   */
  final public boolean isFalse()
  {
    return _const == 0;
  }
  /**
   *
   * @return (boolean_const == 0)
   */
  final public boolean isTrue()
  {
    return _const == 1;
  }
  /**
   *
   * @throws Failure if "boolean_const" is equal to true
   */
  final public void setFalse() throws Failure
  {
    setMax(0);
  }
  /**
   *
   * @throws Failure if "boolean_const" is equal to false
   */
  final public void setTrue() throws Failure
  {
    setMin(1);
  }
  /**
   *
   * @return (IntBoolExp)(!isTrue())
   * @see #isTrue()
   */
  final public IntBoolExp not()
  {
    return getIntBoolExpConst(constrainer(),!isTrue());
  }
  /**
   *
   * @return  (IntBoolExp)(isTrue() ? this : exp)
   */
  final public IntBoolExp or(IntBoolExp exp)
  {
    return isTrue() ? this : exp;
  }
   /**
    * @return  (IntBoolExp)(isTrue() ? this : getIntBoolExpConst(constrainer(),value))
    * @see #getIntBoolExpConst(Constrainer, boolean)
    * @see #isTrue()
    */
  final public IntBoolExp or(boolean value)
  {
    return isTrue() ? (IntBoolExp)this
                    : getIntBoolExpConst(constrainer(),value);
  }
  /**
   * @return (IntBoolExp)(isTrue() ? exp : this)
   * @see #isTrue()
   */
  final public IntBoolExp and(IntBoolExp exp)
  {
    return isTrue() ? exp : this;
  }
  /**
   * @return (IntBoolExp)(isTrue() ? getIntBoolExpConst(constrainer(),value) : this)
   * @see #getIntBoolExpConst(Constrainer, boolean)
   * @see #isTrue()
   */
  final public IntBoolExp and(boolean value)
  {
    return isTrue() ? (IntBoolExp)getIntBoolExpConst(constrainer(),value)
                    : this;
  }
  /**
   *
   * @return this.not().or(exp)
   * @see #not()
   * @see #or(IntBoolExp)
   */
  final public IntBoolExp implies(IntBoolExp exp)
  {
    return not().or(exp);
  }
  /**
   *
   * @return this.not().or(value)
   * @see #not()
   * @see #or(boolean)
   */
  final public IntBoolExp implies(boolean value)
  {
    return not().or(value);
  }
  /**
   *
   * @return (Constraint)(isTrue())
   */
  final public Constraint asConstraint()
  {
    return new ConstraintConst(constrainer(),isTrue());
  }

} // ~IntBoolExpImpl




© 2015 - 2024 Weber Informatics LLC | Privacy Policy