Return everything but the first attribute if multi-valued, or null if single-valued.
(InstanceScope scope, Object v)
| 1018 | */ |
| 1019 | |
| 1020 | public Object rest(InstanceScope scope, Object v) { |
| 1021 | if ( v==null ) return null; |
| 1022 | if ( v instanceof List) { // optimize list case |
| 1023 | List<?> elems = (List<?>)v; |
| 1024 | if ( elems.size()<= 1) return null; |
| 1025 | return elems.subList(1, elems.size()); |
| 1026 | } |
| 1027 | v = convertAnythingIteratableToIterator(scope, v); |
| 1028 | if ( v instanceof Iterator) { |
| 1029 | List<Object> a = new ArrayList<Object>(); |
| 1030 | Iterator<?> it = (Iterator<?>)v; |
| 1031 | if ( !it.hasNext() ) return null; // if not even one value return null |
| 1032 | it.next(); // ignore first value |
| 1033 | while ( it.hasNext() ) { |
| 1034 | Object o = it.next(); |
| 1035 | a.add(o); |
| 1036 | } |
| 1037 | return a; |
| 1038 | } |
| 1039 | return null; // rest of single-valued attribute is null |
| 1040 | } |
| 1041 | |
| 1042 | /** Return all but the last element. <code>trunc(<i>x</i>)==null</code> if <code><i>x</i></code> is single-valued. */ |
| 1043 |