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

📄 tolong.java

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

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

  protected ToLong() 
  {
  }

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

  /**
   * Convert an IclTerm to a long, if possible.  If not, return the given default.
   *
   * @param IclTerm t: the term to convert
   * @param long def: the default to use
   * @return long: the IclTerm as a long, or the default value
   */
  public final long from(IclTerm t, long def) 
  {
    Long i = (Long)t.accept(this, null);
    if(i == null) {
      return def;
    }
    return i.longValue();
  }

  /**
   * Convert an IclTerm to an long, if possible.  If not, throw an UnsupportedOperationException.
   *
   * @param IclTerm t: the term to convert
   * @return long: the term as a long
   * @throws UnsupportedOperationException if no such conversion possible
   */
  public final long from(IclTerm t) throws UnsupportedOperationException
  {
    Long i = (Long)t.accept(this, null);
    if(i == null) {
      throw new UnsupportedOperationException("ToLong not supported by " + OaaPrologParser._tokenNames[t.getType()]);
    }
    return i.longValue();
  }  
}

⌨️ 快捷键说明

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