Permalink
Browse files

Add f:toString() to beautify arrays in results

  • Loading branch information...
1 parent 84e74b8 commit 30d642155c79f9bd18b2e774ebdec091d588b48a @nealeu nealeu committed Jul 11, 2011
@@ -46,4 +46,36 @@ public static String toCssRGBColor(float value) {
public static <T> float reverseScore(Result<T> result, String matcher) {
return result.getScore().getReverseScore(matcher);
}
+
+ /**
+ * A little help for things like Arrays
+ * @param object
+ * @return formatted string representation
+ */
+ public static String toString(Object object) {
+ if (object instanceof Object[]) {
+ Object[] array = (Object[]) object;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < array.length; i++) {
+ sb.append(array[i].toString());
+ if (i < array.length - 1) {
+ sb.append(", ");
+ }
+ }
+ return sb.toString();
+ }
+ else if (object instanceof float[]) {
+ float[] array = (float[]) object;
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < array.length; i++) {
+ sb.append(array[i]);
+ if (i < array.length - 1) {
+ sb.append(", ");
+ }
+ }
+ return sb.toString();
+ }
+
+ return object.toString();
+ }
}
@@ -28,6 +28,12 @@
</function>
<function>
+ <name>toString</name>
+ <function-class>org.fuzzydb.samples.Utils</function-class>
+ <function-signature>java.lang.String toString(java.lang.Object)</function-signature>
+ </function>
+
+ <function>
<name>round</name>
<function-class>java.lang.Math</function-class>
<function-signature>int round(float)</function-signature>
@@ -32,7 +32,7 @@
</c:forEach>
<div style="padding: 15px 2px">Attributes:
<c:forEach items="${result.item.attributes}" var="item">
- <div>${item.key}: ${item.value}</div>
+ <div>${item.key}: ${f:toString(item.value)}</div>
</c:forEach>
</div>
</div>

0 comments on commit 30d6421

Please sign in to comment.