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)
| 1080 | */ |
| 1081 | |
| 1082 | public Object length(Object v) { |
| 1083 | if ( v==null ) return 0; |
| 1084 | int i = 1; // we have at least one of something. Iterator and arrays might be empty. |
| 1085 | if ( v instanceof Map ) i = ((Map<?, ?>)v).size(); |
| 1086 | else if ( v instanceof Collection ) i = ((Collection<?>)v).size(); |
| 1087 | else if ( v instanceof Object[] ) i = ((Object[])v).length; |
| 1088 | else if ( v.getClass().isArray() ) i = Array.getLength(v); |
| 1089 | else if ( v instanceof Iterable || v instanceof Iterator ) { |
| 1090 | Iterator<?> it = v instanceof Iterable ? ((Iterable<?>)v).iterator() : (Iterator<?>)v; |
| 1091 | i =0; |
| 1092 | while ( it.hasNext() ) { |
| 1093 | it.next(); |
| 1094 | i++; |
| 1095 | } |
| 1096 | } |
| 1097 | return i; |
| 1098 | } |
| 1099 | |
| 1100 | protected String toString(STWriter out, InstanceScope scope, Object value) { |
| 1101 | if ( value!=null ) { |
no test coverage detected