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)
| 966 | */ |
| 967 | |
| 968 | public Object last(InstanceScope scope, Object v) { |
| 969 | if ( v==null ) return null; |
| 970 | if ( v instanceof List ) return ((List<?>)v).get(((List<?>)v).size()-1); |
| 971 | else if ( v.getClass().isArray() ) { |
| 972 | return Array.get(v, Array.getLength(v)-1); |
| 973 | } |
| 974 | Object last = v; |
| 975 | v = convertAnythingIteratableToIterator(scope, v); |
| 976 | if ( v instanceof Iterator ) { |
| 977 | Iterator<?> it = (Iterator<?>)v; |
| 978 | while ( it.hasNext() ) { |
| 979 | last = it.next(); |
| 980 | } |
| 981 | } |
| 982 | return last; |
| 983 | } |
| 984 | |
| 985 | /** |
| 986 | * Return everything but the first attribute if multi-valued, or |