Return the length of a multi-valued attribute or 1 if it is a single attribute. If v is null return 0. The implementation treats several common collections and arrays as special cases for speed.
(Object v)
| 1092 | */ |
| 1093 | |
| 1094 | public Object length(Object v) { |
| 1095 | if ( v==null ) return 0; |
| 1096 | int i = 1; // we have at least one of something. Iterator and arrays might be empty. |
| 1097 | if ( v instanceof Map) i = ((Map<?, ?>)v).size(); |
| 1098 | else if ( v instanceof Collection) i = ((Collection<?>)v).size(); |
| 1099 | else if ( v instanceof Object[] ) i = ((Object[])v).length; |
| 1100 | else if ( v.getClass().isArray() ) i = Array.getLength(v); |
| 1101 | else if ( v instanceof Iterable || v instanceof Iterator ) { |
| 1102 | Iterator<?> it = v instanceof Iterable ? ((Iterable<?>)v).iterator() : (Iterator<?>)v; |
| 1103 | i = 0; |
| 1104 | while ( it.hasNext() ) { |
| 1105 | it.next(); |
| 1106 | i++; |
| 1107 | } |
| 1108 | } |
| 1109 | return i; |
| 1110 | } |
| 1111 | |
| 1112 | protected String toString(STWriter out, InstanceScope scope, Object value) { |
| 1113 | if ( value !=null ) { |
no test coverage detected