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)
| 1106 | */ |
| 1107 | |
| 1108 | public Object length(Object v) { |
| 1109 | if ( v==null ) return 0; |
| 1110 | int i = 1; // we have at least one of something. Iterator and arrays might be empty. |
| 1111 | if ( v instanceof Map) i = ((Map<?, ?>)v).size(); |
| 1112 | else if ( v instanceof Collection) i = ((Collection<?>)v).size(); |
| 1113 | else if ( v instanceof Object[] ) i = ((Object[])v).length; |
| 1114 | else if ( v.getClass().isArray() ) i = Array.getLength(v); |
| 1115 | else if ( v instanceof Iterable || v instanceof Iterator ) { |
| 1116 | Iterator<?> it = v instanceof Iterable? ((Iterable<?>)v).iterator() : (Iterator<?>)v; |
| 1117 | i =0; |
| 1118 | while ( it.hasNext() ) { |
| 1119 | it.next(); |
| 1120 | i++; |
| 1121 | } |
| 1122 | } |
| 1123 | return i; |
| 1124 | } |
| 1125 | |
| 1126 | protected String toString(STWriter out, InstanceScope scope, Object value) { |
| 1127 | if ( value !=null ) { |
no test coverage detected