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