Return everything but the first attribute if multi-valued, or null if single-valued.
(InstanceScope scope, Object v)
| 965 | */ |
| 966 | |
| 967 | public Object rest(InstanceScope scope, Object v) { |
| 968 | if ( v==null ) return null; |
| 969 | if ( v instanceof List ) { // optimize list case |
| 970 | List<?> elems = (List<?>)v; |
| 971 | if ( elems.size()<=1) return null; |
| 972 | return elems.subList(1, elems.size()); |
| 973 | } |
| 974 | v = convertAnythingIteratableToIterator(scope, v); |
| 975 | if ( v instanceof Iterator ) { |
| 976 | List<Object> a = new ArrayList<Object>(); |
| 977 | Iterator<?> it = (Iterator<?>)v; |
| 978 | if ( !it.hasNext() ) return null; // if not even one value return null |
| 979 | it.next(); // ignore first value |
| 980 | while ( it.hasNext() ) { |
| 981 | Object o = it.next(); |
| 982 | a.add(o); |
| 983 | } |
| 984 | return a; |
| 985 | } |
| 986 | return null; // rest of single-valued attribute is null |
| 987 | } |
| 988 | |
| 989 | /** Return all but the last element. <code>trunc(<i>x</i>)==null</code> if <code><i>x</i></code> is single-valued. */ |
| 990 |