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