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)
| 996 | */ |
| 997 | |
| 998 | public Object last(InstanceScope scope, Object v) { |
| 999 | if ( v==null ) return null; |
| 1000 | if ( v instanceof List) return ((List<?>)v).get(((List<?>)v).size()-1); |
| 1001 | else if ( v.getClass().isArray() ) { |
| 1002 | return Array.get(v, Array.getLength(v)-1); |
| 1003 | } |
| 1004 | Object last = v; |
| 1005 | v = convertAnythingIteratableToIterator(scope, v); |
| 1006 | if ( v instanceof Iterator) { |
| 1007 | Iterator<?> it = (Iterator<?>)v; |
| 1008 | while ( it.hasNext() ) { |
| 1009 | last = it.next(); |
| 1010 | } |
| 1011 | } |
| 1012 | return last; |
| 1013 | } |
| 1014 | |
| 1015 | /** |
| 1016 | * Return everything but the first attribute if multi-valued, or |