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

📄 tofunctor.java

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

/**
 * Used to get a functor from an IclTerm, if possible.  The most efficient way to do
 * this is to do something like:
 * <code>
 * IclTerm t;
 * String functor = null;
 * ...
 * if((t != null) && 
 *    t.isStruct()) {
 *   functor = ((IclStruct)t).getFunctor();
 * }
 * </code>
 */
public final class ToFunctor implements OaaPrologVisitor
{
  /// Our singleton
  private static final ToFunctor singleton = new ToFunctor();

  /**
   * Users must use getInstance()
   */
  protected ToFunctor() 
  {
  }

  public final Object visit(IclTerm node, Object data) 
  {
    return null;
  }
  
  public final Object visit(IclStruct node, Object data) 
  {
    return node.getFunctor();
  }
  
  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 null;
  }
  
  public final Object visit(IclFloat node, Object data) 
  {
    return null;
  }
  
  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 ToFunctor object.  It's thread safe.
   */
  public static final ToFunctor getInstance() 
  {
    return singleton;
  }

  /**
   * Convert a term to a functor, using the given default if no conversion possible.
   *
   * @param IclTerm t: the term to convert
   * @param String def: the default to use if no conversion possible
   * @return String: the functor
   */
  public final String from(IclTerm t, String def) 
  {
    String s = (String)t.accept(this, null);
    if(s == null) {
      s = def;
    }
    return s;
  }

  /**
   * Convert a term to a functor, throwing an exception if no conversion possible.
   *
   * @param IclTerm t: the term to convert
   * @return String: the functor
   * @throws UnsupportedOperationException if no conversion possible
   */
  public final String from(IclTerm t) throws UnsupportedOperationException
  {
    String s = (String)t.accept(this, null);
    if(s == null) {
      throw new UnsupportedOperationException("ToFunctor not supported by " + OaaPrologParser._tokenNames[t.getType()]);
    }
    return s;
  }
}

⌨️ 快捷键说明

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