本文整理汇总了Java中gnu.lists.Pair类的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pair类属于gnu.lists包,在下文中一共展示了Pair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rewrite
import gnu.lists.Pair; //导入依赖的package包/类
@Override
public Expression rewrite (Object obj, final Translator tr) {
if (Translator.listLength(obj) != 1)
return tr.syntaxError("'scan' requires a single argument");
Translator.ScanContext savedScanContext = tr.getScanContext();
if (savedScanContext == null)
tr.error('e', "'scan' not in a '...'- context");
try {
tr.setScanContext(null);
Expression scanExp = tr.rewrite_car((Pair) obj, false);
Declaration paramDecl =
savedScanContext.getLambda().addParameter(null);
savedScanContext.addSeqExpression(scanExp);
return new ReferenceExp(paramDecl);
} finally {
tr.setScanContext(savedScanContext);
}
}
示例2: evaluate
import gnu.lists.Pair; //导入依赖的package包/类
public Object evaluate(Object clauses, Translator tr) {
while (clauses instanceof Pair) {
Pair pclauses = (Pair) clauses;
Object clause = pclauses.getCar();
clauses = pclauses.getCdr();
if (! (clause instanceof Pair))
tr.errorWithPosition("cond-expand clauses is not a list",
pclauses);
Pair pclause = (Pair) clause;
Object test = Translator.stripSyntax(pclause.getCar());
if ((test == elseSymbol && clauses == LList.Empty)
|| evaluateConditionCar(pclause, tr))
return pclause.getCdr();
}
tr.errorIfNonEmpty(clauses);
return LList.Empty;
}
示例3: createMessageForGetAndEvalScripts
import gnu.lists.Pair; //导入依赖的package包/类
private String createMessageForGetAndEvalScripts(LList urlsOrScripts) {
if (urlsOrScripts.isEmpty()) {
return "";
}
Pair p = (Pair) urlsOrScripts;
String e = (String) p.getCar();
if (e.startsWith("http:") || e.startsWith("/")) {
return String
.format("$.getScript($.inArray('%s', loadedScripts)==-1?'%s':null)"
+ ".always(function(script, textStatus) {"
+ "%s" + "});"
+ "if($.inArray('%s', loadedScripts)==-1){loadedScripts.push('%s');}",
e, e,
createMessageForGetAndEvalScripts((LList) p.getCdr()), e, e);
} else {
return e + System.lineSeparator()
+ createMessageForGetAndEvalScripts((LList) p.getCdr());
}
}
示例4: deepCopyLList
import gnu.lists.Pair; //导入依赖的package包/类
private static Serializable deepCopyLList(LList obj) {
Object rest = obj;
List<Serializable> l = new ArrayList<>();
while (true) {
if (rest == LList.Empty)
break;
if (rest instanceof Pair) {
Pair pair = (Pair) rest;
l.add(deepCopy(pair.getCar()));
rest = pair.getCdr();
} else {
l.add(deepCopy(rest));
break;
}
}
return (Serializable) l;
}
示例5: llistToLiteral
import gnu.lists.Pair; //导入依赖的package包/类
private static String llistToLiteral(ToExpressionStyle style, LList obj) {
if (obj == null) {
return "#!null";
}
Object rest = obj;
StringBuffer sbuf = new StringBuffer(100);
sbuf.append("(list ");
for (int i = 0;;) {
if (rest == LList.Empty)
break;
if (i > 0)
sbuf.append(' ');
if (rest instanceof Pair) {
Pair pair = (Pair) rest;
sbuf.append(toLiteral(style, pair.getCar()));
rest = pair.getCdr();
} else {
sbuf.append(". ");
sbuf.append(toLiteral(style, rest));
break;
}
i++;
}
sbuf.append(')');
return sbuf.toString();
}
示例6: proc
import gnu.lists.Pair; //导入依赖的package包/类
private static void proc(LList args, Map<Keyword, Object> argsMap) {
if (!(args instanceof Pair)) {
return;
}
Pair p = (Pair) args;
Object car = p.getCar();
LList cdr = ((LList) p.getCdr());
if (car instanceof Keyword) {
argsMap.put((Keyword) car, ((Pair) cdr).getCar());
} else {
argsMap.put(Keyword.make("rest"), new ArrayList<Object>(Arrays.asList(args.toArray())));
return;
}
proc((LList) ((Pair) cdr).getCdr(), argsMap);
}
示例7: procAttrsForInsert
import gnu.lists.Pair; //导入依赖的package包/类
protected void procAttrsForInsert(ActorObject target, int roundnum, List<String> attrNames,
List<Object> vals) {
RoundHistory r = target.getHistory().getRoundHistory(roundnum);
for (Pair pair : target.getAttributeAndFieldNamePairs()) {
Symbol key = (Symbol) pair.getCdr();
attrNames.add(key.toString());
Serializable val = r.get(key);
if (IntNum.class.isAssignableFrom(val.getClass())) {
vals.add(((IntNum) val).intValue());
} else if (DFloNum.class.isAssignableFrom(val.getClass())) {
vals.add(((DFloNum) val).doubleValue());
} else if (Number.class.isAssignableFrom(val.getClass())) {
vals.add(val);
} else {
vals.add(val.toString());
}
}
}
示例8: toArray
import gnu.lists.Pair; //导入依赖的package包/类
/**
* Return this YailList as an array.
*/
@Override
public Object[] toArray() {
if (cdr instanceof Pair) {
return ((Pair) cdr).toArray();
} else if (cdr instanceof LList) {
return ((LList) cdr).toArray();
} else {
throw new YailRuntimeError("YailList cannot be represented as an array", "YailList Error.");
}
}
示例9: toString
import gnu.lists.Pair; //导入依赖的package包/类
/**
* Return a String representation of this YailList.
*/
@Override
public String toString() {
if (cdr instanceof Pair) {
return ((Pair) cdr).toString();
} else if (cdr instanceof LList) {
return ((LList) cdr).toString();
} else {
throw new RuntimeException("YailList cannot be represented as a String");
}
}
示例10: readVector
import gnu.lists.Pair; //导入依赖的package包/类
public static FVector readVector(LispReader lexer, InPort port, int count, char close, int sharingIndex)
throws java.io.IOException, SyntaxException
{
char saveReadState = ' ';
if (port instanceof InPort)
{
saveReadState = ((InPort) port).readState;
((InPort) port).readState = close == ']' ? '[' : '(';
}
int startLine = port.getLineNumber();
int startColumn = port.getColumnNumber()-1;
try
{
FVector result = new FVector();
lexer.bindSharedObject(sharingIndex, result);
ReadTable rtable = ReadTable.getCurrent();
Pair head = new Pair(null, LList.Empty);
Pair last = head;
for (;;)
{
int ch = lexer.read();
if (ch < 0)
lexer.eofError("unexpected EOF in vector starting here",
startLine + 1, startColumn);
if (ch == close)
break;
last = lexer.readValuesAndAppend(ch, rtable, last);
}
result.replaceAll(((LList) head.getCdr()).toArray());
result.setReadOnly();
return result;
}
finally
{
if (port instanceof InPort)
((InPort) port).readState = saveReadState;
}
}
示例11: setMenuHelper
import gnu.lists.Pair; //导入依赖的package包/类
/**
* Heavily inspired from gnu.jemacs.swing.SwingMenu
*/
private void setMenuHelper(Menu parent, LList list)
{
for (Iterator iter = list.iterator(); iter.hasNext();)
{
Object o = iter.next();
try
{
if (o == null)
{
continue;
}
else if (o instanceof Pair)
{
CharSequence menuName = (CharSequence) ((Pair) o).getCar();
MenuItem menuItem = SwtHelper.newMenuItem(parent, SWT.CASCADE, menuName.toString(), null);
Menu subMenu = SwtHelper.newMenu(menuItem);
setMenuHelper(subMenu, (LList) ((Pair) o).getCdr());
SwtHelper.setMenu(menuItem, subMenu);
}
else if (o instanceof FVector)
{
CharSequence menuItemName = (CharSequence) ((FVector) o).get(0);
Object command = ((FVector) o).get(1);
SwtHelper.newMenuItem(parent, SWT.DROP_DOWN, menuItemName.toString(), new MenuCommandHandler(command));
}
else if (o instanceof CharSequence)
{
SwtHelper.newMenuItem(parent, SWT.SEPARATOR, null, null);
}
}
catch (Exception e)
{
System.err.println("SwtFrame.setMenu - problem with " + o);
}
}
}
示例12: rewrite
import gnu.lists.Pair; //导入依赖的package包/类
public Expression rewrite (Object obj, Translator tr)
{
if (! (obj instanceof Pair))
return tr.syntaxError("invalid syntax for unwind-protect");
Pair pair = (Pair) obj;
return new TryExp(tr.rewrite(pair.getCar()), tr.rewrite_body(pair.getCdr()));
}
示例13: readVector
import gnu.lists.Pair; //导入依赖的package包/类
public static FVector readVector(LispReader lexer, InPort port, int count, char close, int sharingIndex)
throws java.io.IOException, SyntaxException
{
char saveReadState = ' ';
if (port instanceof InPort)
{
saveReadState = ((InPort) port).readState;
((InPort) port).readState = close == ']' ? '[' : '(';
}
int startLine = port.getLineNumber();
int startColumn = port.getColumnNumber()-1;
try
{
ConstVector result = new ConstVector();
lexer.bindSharedObject(sharingIndex, result);
ReadTable rtable = ReadTable.getCurrent();
Pair head = new Pair(null, LList.Empty);
Pair last = head;
for (;;)
{
int ch = lexer.read();
if (ch < 0)
lexer.eofError("unexpected EOF in vector starting here",
startLine + 1, startColumn);
if (ch == close)
break;
last = lexer.readValuesAndAppend(ch, rtable, last);
}
result.setDataBackDoor(((LList) head.getCdr()).toArray());
return result;
}
finally
{
if (port instanceof InPort)
((InPort) port).readState = saveReadState;
}
}
示例14: setMenuHelper
import gnu.lists.Pair; //导入依赖的package包/类
/**
* Heavily inspired from gnu.jemacs.swing.SwingMenu
*/
private void setMenuHelper(Menu parent, LList list)
{
for (Iterator iter = list.iterator(); iter.hasNext();)
{
Object o = iter.next();
try
{
if (o == null)
{
continue;
}
else if (o instanceof Pair)
{
CharSequence menuName = (CharSequence) ((Pair) o).car;
MenuItem menuItem = SwtHelper.newMenuItem(parent, SWT.CASCADE, menuName.toString(), null);
Menu subMenu = SwtHelper.newMenu(menuItem);
setMenuHelper(subMenu, (LList) ((Pair) o).cdr);
SwtHelper.setMenu(menuItem, subMenu);
}
else if (o instanceof FVector)
{
CharSequence menuItemName = (CharSequence) ((FVector) o).get(0);
Object command = ((FVector) o).get(1);
SwtHelper.newMenuItem(parent, SWT.DROP_DOWN, menuItemName.toString(), new MenuCommandHandler(command));
}
else if (o instanceof CharSequence)
{
SwtHelper.newMenuItem(parent, SWT.SEPARATOR, null, null);
}
}
catch (Exception e)
{
System.err.println("SwtFrame.setMenu - problem with " + o);
}
}
}
示例15: readVector
import gnu.lists.Pair; //导入依赖的package包/类
public static FVector readVector(LispReader lexer, LineBufferedReader port, int count, char close, int sharingIndex)
throws java.io.IOException, SyntaxException
{
char saveReadState = ' ';
if (port instanceof InPort)
{
saveReadState = ((InPort) port).readState;
((InPort) port).readState = close == ']' ? '[' : '(';
}
int startLine = port.getLineNumber();
int startColumn = port.getColumnNumber()-1;
try
{
ConstVector result = new ConstVector();
lexer.bindSharedObject(sharingIndex, result);
ReadTable rtable = ReadTable.getCurrent();
Pair head = new Pair(null, LList.Empty);
Pair last = head;
for (;;)
{
int ch = lexer.read();
if (ch < 0)
lexer.eofError("unexpected EOF in vector starting here",
startLine + 1, startColumn);
if (ch == close)
break;
last = lexer.readValuesAndAppend(ch, rtable, last);
}
result.setDataBackDoor(((LList) head.getCdr()).toArray());
return result;
}
finally
{
if (port instanceof InPort)
((InPort) port).readState = saveReadState;
}
}