Return the last attribute if multi-valued, or the attribute itself if single-valued. Unless it's a List or array, this is pretty slow as it iterates until the last element. This method is used for rendering expressions of the form .
(InstanceScope scope, Object v)
| 962 | */ |
| 963 | |
| 964 | public Object last(InstanceScope scope, Object v) { |
| 965 | if ( v==null ) return null; |
| 966 | if ( v instanceof List ) return ((List<?>)v).get(((List<?>)v).size()-1); |
| 967 | else if ( v.getClass().isArray() ) { |
| 968 | return Array.get(v, Array.getLength(v)-1); |
| 969 | } |
| 970 | Object last = v; |
| 971 | v = convertAnythingIteratableToIterator(scope, v); |
| 972 | if ( v instanceof Iterator ) { |
| 973 | Iterator<?> it = (Iterator<?>)v; |
| 974 | while ( it.hasNext() ) { |
| 975 | last = it.next(); |
| 976 | } |
| 977 | } |
| 978 | return last; |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * Return everything but the first attribute if multi-valued, or |