MCPcopy Index your code
hub / github.com/antlr/codebuff / trunc

Method trunc

output/java8/1.4.13/Interpreter.java:991–1009  ·  view source on GitHub ↗

Return all but the last element. trunc( x )==null if x is single-valued.

(InstanceScope scope, Object v)

Source from the content-addressed store, hash-verified

989 /** Return all but the last element. <code>trunc(<i>x</i>)==null</code> if <code><i>x</i></code> is single-valued. */
990
991 public Object trunc(InstanceScope scope, Object v) {
992 if ( v==null ) return null;
993 if ( v instanceof List ) { // optimize list case
994 List<?> elems = (List<?>)v;
995 if ( elems.size()<=1) return null;
996 return elems.subList(0, elems.size()-1);
997 }
998 v = convertAnythingIteratableToIterator(scope, v);
999 if ( v instanceof Iterator ) {
1000 List<Object> a = new ArrayList<Object>();
1001 Iterator<?> it = (Iterator<?>)v;
1002 while ( it.hasNext() ) {
1003 Object o = it.next();
1004 if ( it.hasNext() ) a.add(o); // only add if not last one
1005 }
1006 return a;
1007 }
1008 return null; // trunc(x)==null when x single-valued attribute
1009 }
1010
1011 /** Return a new list without {@code null} values. */
1012

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