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

Method rest

output/java8/1.4.16/Interpreter.java:994–1014  ·  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

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

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