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

📄 todouble.java

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

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

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

  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 Double(node.toLongObject().doubleValue());
  }
  
  public final Object visit(IclFloat node, Object data) 
  {
    return node.toDoubleObject();
  }
  
  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 ToDouble object.  This avoids multiple calls to the constructor.
   * ToDouble is thread safe.
   */
  public final static ToDouble getInstance() 
  {
    return singleton;
  }

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

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

⌨️ 快捷键说明

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