📄 tolist.java
字号:
package com.sri.oaa2.icl;
/**
* Objects of this class convert IclTerms to an IclList. Currently only
* does the conversion if IclTerm.isList() returns true for the term.
*/
public final class ToList implements OaaPrologVisitor
{
/// Our singleton instance
private static final ToList singleton = new ToList();
protected ToList()
{
}
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 node;
}
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 ToList object. This avoids multiple calls to the constructor.
* ToList is thread safe.
*/
public final static ToList getInstance()
{
return singleton;
}
/**
* Convert an IclTerm to an IclList, if possible. If not, return the given default.
*
* @param IclTerm t: the term to convert
* @param IclList def: the default to use
* @return IclList: the IclTerm as an IclList, or the default value
*/
public final IclList from(IclTerm t, IclList def)
{
if(t.isList()) {
return (IclList)t;
}
IclList l = (IclList)t.accept(this, null);
if(l == null) {
return def;
}
return l;
}
/**
* Convert an IclTerm to an IclList, if possible. If not, throw an UnsupportedOperationException.
*
* @param IclTerm t: the term to convert
* @return IclList: the term as an IclList
* @throws UnsupportedOperationException if no such conversion possible
*/
public final IclList from(IclTerm t) throws UnsupportedOperationException
{
if(t.isList()) {
return (IclList)t;
}
IclList l = (IclList)t.accept(this, null);
if(l == null) {
throw new UnsupportedOperationException("ToList not supported by " + OaaPrologParser._tokenNames[t.getType()]);
}
return l;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -