⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tofloat.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
package com.sri.oaa2.icl;

public final class ToFloat implements OaaPrologVisitor
{
  /// Our singleton instance
  private static final ToFloat singleton = new ToFloat();

  /**
   * Use getInstance()
   */
  protected ToFloat() 
  {
  }

  public final Object visit(IclTerm node, Object data) 
  {
    return null;
  }
  
  public final Object visit(IclStruct node, Object data) 
  {
    return null;
  }
  
  public final Object visit(IclList node, Object data) 
  {
    return null;
  }
  
  public final Object visit(IclGroup node, Object data) 
  {
    return null;
  }
  
  public final Object visit(IclInt node, Object data) 
  {
    return new Float(node.toInteger().floatValue());
  }
  
  public final Object visit(IclFloat node, Object data) 
  {
    return node.toFloatObject();
  }
  
  public final Object visit(IclStr node, Object data) 
  {
    return null;
  }
  
  public final Object visit(IclVar node, Object data) 
  {
    return null;
  }

  /**
   * Get an instance of a ToFloat object.  This avoids multiple calls to the constructor.
   * ToFloat is thread safe.
   */
  public static final ToFloat getInstance() 
  {
    return singleton;
  }

  /**
   * Convert a Term to a float primitive.  If it cannot be converted, use the
   * given default
   *
   * @param IclTerm t: the term to convert
   * @param float def: the default value to return if no conversion possible
   * @return float: the IclTerm as a float, if possible
   */
  public final float from(IclTerm t, float def) 
  {
    Float f = (Float)t.accept(this, null);
    if(f == null) {
      return def;
    }
    return f.floatValue();
  }

  /**
   * Convert a Term to a float primitive.  If it cannot be converted, throw an
   * UnsupportedOperationException
   *
   * @param IclTerm t: the term to convert
   * @return float: the IclTerm as a float, if possible
   * @throws UnsupportedOperationException if the IclTerm cannot be converted
   */
  public final float from(IclTerm t) throws UnsupportedOperationException
  {
    Float i = (Float)t.accept(this, null);
    if(i == null) {
      throw new UnsupportedOperationException("ToFloat not supported by " + OaaPrologParser._tokenNames[t.getType()]);
    }
    return i.floatValue();
  }
}

⌨️ 快捷键说明

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