wangzhibo
4 天以前 ae6f40460dcd56af6c5f60ba52c883854c3bac55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package nodomain.freeyourgadget.gadgetbridge.util;
 
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
 
public class GBToStringBuilder extends ToStringBuilder {
    public static final GBToStringStyle STYLE = new GBToStringStyle();
 
    private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US);
 
    public GBToStringBuilder(final Object object) {
        super(object, STYLE);
    }
 
    public static class GBToStringStyle extends ToStringStyle {
        public GBToStringStyle() {
            super();
 
            this.setUseShortClassName(true);
            this.setUseIdentityHashCode(false);
 
            this.setContentStart("{");
            this.setContentEnd("}");
 
            this.setArrayStart("[");
            this.setArrayEnd("]");
 
            this.setFieldSeparator(", ");
            this.setFieldNameValueSeparator("=");
 
            this.setNullText("null");
        }
 
        @Override
        public void append(final StringBuffer buffer, final String fieldName, final Object value, final Boolean fullDetail) {
            // omit nulls
            if (value != null) {
                if (value instanceof Date) {
                    super.append(buffer, fieldName, SDF.format(value), fullDetail);
                } else {
                    super.append(buffer, fieldName, value, fullDetail);
                }
            }
        }
    }
}