MCPcopy Create free account
hub / github.com/antlr/codebuff / rest

Method rest

output/java8/1.4.14/Interpreter.java:986–1006  ·  view source on GitHub ↗

Return everything but the first attribute if multi-valued, or null if single-valued.

(InstanceScope scope, Object v)

Source from the content-addressed store, hash-verified

984 */
985
986 public Object rest(InstanceScope scope, Object v) {
987 if ( v==null ) return null;
988 if ( v instanceof List ) { // optimize list case
989 List<?> elems = (List<?>)v;
990 if ( elems.size()<=1) return null;
991 return elems.subList(1, elems.size());
992 }
993 v = convertAnythingIteratableToIterator(scope, v);
994 if ( v instanceof Iterator ) {
995 List<Object> a = new ArrayList<Object>();
996 Iterator<?> it = (Iterator<?>)v;
997 if ( !it.hasNext() ) return null; // if not even one value return null
998 it.next(); // ignore first value
999 while ( it.hasNext() ) {
1000 Object o = it.next();
1001 a.add(o);
1002 }
1003 return a;
1004 }
1005 return null; // rest of single-valued attribute is null
1006 }
1007
1008 /** Return all but the last element. <code>trunc(<i>x</i>)==null</code> if <code><i>x</i></code> is single-valued. */
1009

Callers 1

_execMethod · 0.95

Calls 6

sizeMethod · 0.65
nextMethod · 0.65
addMethod · 0.65
subListMethod · 0.45
hasNextMethod · 0.45

Tested by

no test coverage detected