Return everything but the first attribute if multi-valued, or null if single-valued.
(InstanceScope scope, Object v)
| 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 |