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)
| 943 | */ |
| 944 | |
| 945 | public Object last(InstanceScope scope, Object v) { |
| 946 | if ( v==null ) return null; |
| 947 | if ( v instanceof List ) return ((List<?>)v).get(((List<?>)v).size()-1); |
| 948 | else if ( v.getClass().isArray() ) { |
| 949 | return Array.get(v, Array.getLength(v)-1); |
| 950 | } |
| 951 | Object last = v; |
| 952 | v = convertAnythingIteratableToIterator(scope, v); |
| 953 | if ( v instanceof Iterator ) { |
| 954 | Iterator<?> it = (Iterator<?>)v; |
| 955 | while ( it.hasNext() ) { |
| 956 | last = it.next(); |
| 957 | } |
| 958 | } |
| 959 | return last; |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Return everything but the first attribute if multi-valued, or |