1 package org.pojomatic.formatter;
2
3 import java.lang.reflect.AnnotatedElement;
4 import java.util.Arrays;
5
6
7
8
9
10
11
12
13
14 @Deprecated
15 public class DefaultPropertyFormatter implements PropertyFormatter {
16
17 @Override
18 public void initialize(AnnotatedElement element) {
19
20 }
21
22 @Override
23 public String format(Object value) {
24 if (value == null) {
25 return "null";
26 }
27 else if (value.getClass().isArray()) {
28 Class<?> componentClass = value.getClass().getComponentType();
29 if (componentClass.isPrimitive()) {
30 if (Boolean.TYPE == componentClass) {
31 return Arrays.toString((boolean[]) value);
32 }
33 if (Character.TYPE == componentClass) {
34 StringBuilder builder = new StringBuilder().append('[');
35 boolean seenOne = false;
36 for (char c: ((char[]) value)) {
37 if(seenOne) {
38 builder.append(", ");
39 }
40 else {
41 seenOne = true;
42 }
43 builder.append('\'');
44 if (Character.isISOControl(c)) {
45 builder.append("0x").append(Integer.toHexString(c));
46 }
47 else {
48 builder.append(c);
49 }
50 builder.append('\'');
51 }
52 return builder.append(']').toString();
53 }
54 if (Byte.TYPE == componentClass) {
55 return Arrays.toString((byte[]) value);
56 }
57 if (Short.TYPE == componentClass) {
58 return Arrays.toString((short[]) value);
59 }
60 if (Integer.TYPE == componentClass) {
61 return Arrays.toString((int[]) value);
62 }
63 if (Long.TYPE == componentClass) {
64 return Arrays.toString((long[]) value);
65 }
66 if (Float.TYPE == componentClass) {
67 return Arrays.toString((float[]) value);
68 }
69 if (Double.TYPE == componentClass) {
70 return Arrays.toString((double[]) value);
71 }
72 else {
73 throw new IllegalStateException("unexpected primitive array base type: " + componentClass);
74 }
75 }
76 else {
77 return Arrays.deepToString((Object[]) value);
78 }
79 }
80 else {
81 return value.toString();
82 }
83 }
84
85 }