41 lines
950 B
Java
41 lines
950 B
Java
|
/*
|
||
|
* Copyright (c) 2011 Tony Garnock-Jones. All rights reserved.
|
||
|
*/
|
||
|
|
||
|
package hop;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
|
||
|
/**
|
||
|
*/
|
||
|
public class SexpList extends ArrayList<Object> {
|
||
|
public SexpBytes getBytes(int index) throws SexpSyntaxError {
|
||
|
Object x = get(index);
|
||
|
if (x != null && !(x instanceof SexpBytes)) {
|
||
|
throw new SexpSyntaxError("Unexpected non-bytes");
|
||
|
}
|
||
|
return (SexpBytes) get(index);
|
||
|
}
|
||
|
|
||
|
public SexpList getList(int index) throws SexpSyntaxError {
|
||
|
Object x = get(index);
|
||
|
if (x != null && !(x instanceof SexpList)) {
|
||
|
throw new SexpSyntaxError("Unexpected non-list");
|
||
|
}
|
||
|
return (SexpList) get(index);
|
||
|
}
|
||
|
|
||
|
public static SexpList empty() {
|
||
|
return new SexpList();
|
||
|
}
|
||
|
|
||
|
public static SexpList with(Object x) {
|
||
|
return empty().and(x);
|
||
|
}
|
||
|
|
||
|
public SexpList and(Object x) {
|
||
|
this.add(x);
|
||
|
return this;
|
||
|
}
|
||
|
}
|