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