/*
 * Copyright (c) 2005, Regents of the University of California
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.  
 *
 * * Neither the name of the University of California, Berkeley nor
 *   the names of its contributors may be used to endorse or promote
 *   products derived from this software without specific prior 
 *   written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package blog.distrib;

import blog.model.Clause;

/**
 * EqualsCPD class is a convenience hack to represent the situation when the
 * value of the right-hand side of a {@link Clause} depends on a function
 * application rather than on a CPD.
 */
public class EqualsCPD implements CondProbDistrib {
  /**
   * An instance of EqualsCPD.
   */
  public static final EqualsCPD CPD = new EqualsCPD();

  /**
   * @param params
   *          A single-element object array. If the first element is non-null,
   *          set this element as the value that this deterministic distribution
   *          takes on.
   * 
   * @see blog.distrib.CondProbDistrib#setParams(java.util.List)
   */
  @Override
  public void setParams(Object[] params) {
    if (params.length != 1) {
      throw new IllegalArgumentException("expecting one parameter");
    }
    setParams(params[0]);
  }

  /**
   * @param value
   *          If non-null, this is the value that this deterministic
   *          distribution should take on.
   */
  public void setParams(Object value) {
    if (value != null) {
      this.value = value;
      this.hasValue = true;
      this.finiteSupport = null;
    }
  }

  private void checkHasParams() {
    if (!this.hasValue) {
      throw new IllegalArgumentException(
          "have not provided value for EqualsCPD");
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#getProb(java.lang.Object)
   */
  @Override
  public double getProb(Object value) {
    checkHasParams();
    return value.equals(this.value) ? 1 : 0;
  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#getLogProb(java.lang.Object)
   */
  @Override
  public double getLogProb(Object value) {
    checkHasParams();
    return value.equals(this.value) ? 0 : Double.NEGATIVE_INFINITY;
  }

  /*
   * (non-Javadoc)
   * 
   * @see blog.distrib.CondProbDistrib#sampleVal()
   */
  @Override
  public Object sampleVal() {
    checkHasParams();
    return value;
  }

  @Override
  public Object[] getFiniteSupport() {
    if (finiteSupport == null) {
      checkHasParams();
      finiteSupport = new Object[1];
      finiteSupport[0] = value;
    }
    return finiteSupport;
  }

  private Object value;
  private boolean hasValue;
  private Object[] finiteSupport = null;
}

@@ -1661,34 +1661,8 @@
 b;%0A%0A
-import blog.model.Clause;%0A
 %0A/**
@@ -1780,22 +1780,14 @@
 f a 
-%7B@link 
 Clause
-%7D
  dep

Remove import blog.model.Clause.