floatconstraint.java

来自「SRI international 发布的OAA框架软件」· Java 代码 · 共 66 行

JAVA
66
字号
/*
#=========================================================================
# Copyright 2003 SRI International.  All rights reserved.
#
# The material contained in this file is confidential and proprietary to SRI
# International and may not be reproduced, published, or disclosed to others
# without authorization from SRI International.
#
# DISCLAIMER OF WARRANTIES
#
# SRI International MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
# SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
# LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SRI International SHALL NOT BE
# LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
# OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
#=========================================================================
  Author : shardt
  Date: Aug 11, 2003
*/
package com.sri.oaa2.tools.oaatest;
import org.xml.sax.*;
import com.sri.oaa2.icl.*;


/** A Constraint object for which the "value" is a float object. */
abstract class FloatConstraint extends Constraint {
  FloatConstraint(Attributes attribs,Locator loc,String name) 
    throws ParseException {
    super(attribs,loc);
    this.name = name;
    String valS = getAttribute(attribs,"value",loc);
    try {
      value = Float.parseFloat(valS);
    }
    catch (NumberFormatException e) {
      throw new ParseException("value attribute must be a number",loc);
    }
  }

  public String toString() {
    return name + '(' + getVar().toString() + ',' + value + ')'; 
  }

  abstract protected boolean checkFloat(float actual);
  
  protected boolean checkValue(IclTerm actual) {
    // ICL object can be an IclInt or an IclFloat.
    if (actual instanceof IclInt) {
      return checkFloat(((IclInt)actual).toInteger().floatValue());
    }
    else if (actual instanceof IclFloat) {
      return checkFloat(((IclFloat)actual).toFloat());
    }
    return false;
  }
  
  // Package-visible for SelfTest
  float getValue() {
    return value;
  }
  
  private String name;
  private float value;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?