1 16 package org.apache.commons.lang.builder; 17 18 import java.io.Serializable ; 19 import java.lang.reflect.Array ; 20 import java.util.Collection ; 21 import java.util.Map ; 22 23 import org.apache.commons.lang.ClassUtils; 24 import org.apache.commons.lang.ObjectUtils; 25 import org.apache.commons.lang.SystemUtils; 26 27 68 public abstract class ToStringStyle implements Serializable { 69 70 73 public static final ToStringStyle DEFAULT_STYLE = new DefaultToStringStyle(); 74 75 78 public static final ToStringStyle MULTI_LINE_STYLE = new MultiLineToStringStyle(); 79 80 83 public static final ToStringStyle NO_FIELD_NAMES_STYLE = new NoFieldNameToStringStyle(); 84 85 89 public static final ToStringStyle SHORT_PREFIX_STYLE = new ShortPrefixToStringStyle(); 90 91 94 public static final ToStringStyle SIMPLE_STYLE = new SimpleToStringStyle(); 95 96 99 private boolean useFieldNames = true; 100 101 104 private boolean useClassName = true; 105 106 109 private boolean useShortClassName = false; 110 111 114 private boolean useIdentityHashCode = true; 115 116 119 private String contentStart = "["; 120 121 124 private String contentEnd = "]"; 125 126 129 private String fieldNameValueSeparator = "="; 130 131 134 private boolean fieldSeparatorAtStart = false; 135 136 139 private boolean fieldSeparatorAtEnd = false; 140 141 144 private String fieldSeparator = ","; 145 146 149 private String arrayStart = "{"; 150 151 154 private String arraySeparator = ","; 155 156 159 private boolean arrayContentDetail = true; 160 161 164 private String arrayEnd = "}"; 165 166 170 private boolean defaultFullDetail = true; 171 172 175 private String nullText = "<null>"; 176 177 180 private String sizeStartText = "<size="; 181 182 185 private String sizeEndText = ">"; 186 187 190 private String summaryObjectStartText = "<"; 191 192 195 private String summaryObjectEndText = ">"; 196 197 199 202 protected ToStringStyle() { 203 super(); 204 } 205 206 208 217 public void appendSuper(StringBuffer buffer, String superToString) { 218 appendToString(buffer, superToString); 219 } 220 221 230 public void appendToString(StringBuffer buffer, String toString) { 231 if (toString != null) { 232 int pos1 = toString.indexOf(contentStart) + contentStart.length(); 233 int pos2 = toString.lastIndexOf(contentEnd); 234 if (pos1 != pos2 && pos1 >= 0 && pos2 >= 0) { 235 String data = toString.substring(pos1, pos2); 236 if (fieldSeparatorAtStart) { 237 removeLastFieldSeparator(buffer); 238 } 239 buffer.append(data); 240 appendFieldSeparator(buffer); 241 } 242 } 243 } 244 245 251 public void appendStart(StringBuffer buffer, Object object) { 252 if (object != null) { 253 appendClassName(buffer, object); 254 appendIdentityHashCode(buffer, object); 255 appendContentStart(buffer); 256 if (fieldSeparatorAtStart) { 257 appendFieldSeparator(buffer); 258 } 259 } 260 } 261 262 269 public void appendEnd(StringBuffer buffer, Object object) { 270 if (this.fieldSeparatorAtEnd == false) { 271 removeLastFieldSeparator(buffer); 272 } 273 appendContentEnd(buffer); 274 } 275 276 282 protected void removeLastFieldSeparator(StringBuffer buffer) { 283 int len = buffer.length(); 284 int sepLen = fieldSeparator.length(); 285 if (len > 0 && sepLen > 0 && len >= sepLen) { 286 boolean match = true; 287 for (int i = 0; i < sepLen; i++) { 288 if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) { 289 match = false; 290 break; 291 } 292 } 293 if (match) { 294 buffer.setLength(len - sepLen); 295 } 296 } 297 } 298 299 301 312 public void append(StringBuffer buffer, String fieldName, Object value, Boolean fullDetail) { 313 appendFieldStart(buffer, fieldName); 314 315 if (value == null) { 316 appendNullText(buffer, fieldName); 317 318 } else { 319 appendInternal(buffer, fieldName, value, isFullDetail(fullDetail)); 320 } 321 322 appendFieldEnd(buffer, fieldName); 323 } 324 325 344 protected void appendInternal(StringBuffer buffer, String fieldName, Object value, boolean detail) { 345 if (ReflectionToStringBuilder.isRegistered(value) 346 && !(value instanceof Number || value instanceof Boolean || value instanceof Character )) { 347 ObjectUtils.appendIdentityToString(buffer, value); 348 349 } else if (value instanceof Collection ) { 350 if (detail) { 351 appendDetail(buffer, fieldName, (Collection ) value); 352 } else { 353 appendSummarySize(buffer, fieldName, ((Collection ) value).size()); 354 } 355 356 } else if (value instanceof Map ) { 357 if (detail) { 358 appendDetail(buffer, fieldName, (Map ) value); 359 } else { 360 appendSummarySize(buffer, fieldName, ((Map ) value).size()); 361 } 362 363 } else if (value instanceof long[]) { 364 if (detail) { 365 appendDetail(buffer, fieldName, (long[]) value); 366 } else { 367 appendSummary(buffer, fieldName, (long[]) value); 368 } 369 370 } else if (value instanceof int[]) { 371 if (detail) { 372 appendDetail(buffer, fieldName, (int[]) value); 373 } else { 374 appendSummary(buffer, fieldName, (int[]) value); 375 } 376 377 } else if (value instanceof short[]) { 378 if (detail) { 379 appendDetail(buffer, fieldName, (short[]) value); 380 } else { 381 appendSummary(buffer, fieldName, (short[]) value); 382 } 383 384 } else if (value instanceof byte[]) { 385 if (detail) { 386 appendDetail(buffer, fieldName, (byte[]) value); 387 } else { 388 appendSummary(buffer, fieldName, (byte[]) value); 389 } 390 391 } else if (value instanceof char[]) { 392 if (detail) { 393 appendDetail(buffer, fieldName, (char[]) value); 394 } else { 395 appendSummary(buffer, fieldName, (char[]) value); 396 } 397 398 } else if (value instanceof double[]) { 399 if (detail) { 400 appendDetail(buffer, fieldName, (double[]) value); 401 } else { 402 appendSummary(buffer, fieldName, (double[]) value); 403 } 404 405 } else if (value instanceof float[]) { 406 if (detail) { 407 appendDetail(buffer, fieldName, (float[]) value); 408 } else { 409 appendSummary(buffer, fieldName, (float[]) value); 410 } 411 412 } else if (value instanceof boolean[]) { 413 if (detail) { 414 appendDetail(buffer, fieldName, (boolean[]) value); 415 } else { 416 appendSummary(buffer, fieldName, (boolean[]) value); 417 } 418 419 } else if (value.getClass().isArray()) { 420 if (detail) { 421 appendDetail(buffer, fieldName, (Object []) value); 422 } else { 423 appendSummary(buffer, fieldName, (Object []) value); 424 } 425 426 } else { 427 if (detail) { 428 appendDetail(buffer, fieldName, value); 429 } else { 430 appendSummary(buffer, fieldName, value); 431 } 432 } 433 } 434 435 444 protected void appendDetail(StringBuffer buffer, String fieldName, Object value) { 445 buffer.append(value); 446 } 447 448 456 protected void appendDetail(StringBuffer buffer, String fieldName, Collection coll) { 457 buffer.append(coll); 458 } 459 460 468 protected void appendDetail(StringBuffer buffer, String fieldName, Map map) { 469 buffer.append(map); 470 } 471 472 481 protected void appendSummary(StringBuffer buffer, String fieldName, Object value) { 482 buffer.append(summaryObjectStartText); 483 buffer.append(getShortClassName(value.getClass())); 484 buffer.append(summaryObjectEndText); 485 } 486 487 489 497 public void append(StringBuffer buffer, String fieldName, long value) { 498 appendFieldStart(buffer, fieldName); 499 appendDetail(buffer, fieldName, value); 500 appendFieldEnd(buffer, fieldName); 501 } 502 503 511 protected void appendDetail(StringBuffer buffer, String fieldName, long value) { 512 buffer.append(value); 513 } 514 515 517 525 public void append(StringBuffer buffer, String fieldName, int value) { 526 appendFieldStart(buffer, fieldName); 527 appendDetail(buffer, fieldName, value); 528 appendFieldEnd(buffer, fieldName); 529 } 530 531 539 protected void appendDetail(StringBuffer buffer, String fieldName, int value) { 540 buffer.append(value); 541 } 542 543 545 553 public void append(StringBuffer buffer, String fieldName, short value) { 554 appendFieldStart(buffer, fieldName); 555 appendDetail(buffer, fieldName, value); 556 appendFieldEnd(buffer, fieldName); 557 } 558 559 567 protected void appendDetail(StringBuffer buffer, String fieldName, short value) { 568 buffer.append(value); 569 } 570 571 573 581 public void append(StringBuffer buffer, String fieldName, byte value) { 582 appendFieldStart(buffer, fieldName); 583 appendDetail(buffer, fieldName, value); 584 appendFieldEnd(buffer, fieldName); 585 } 586 587 595 protected void appendDetail(StringBuffer buffer, String fieldName, byte value) { 596 buffer.append(value); 597 } 598 599 601 609 public void append(StringBuffer buffer, String fieldName, char value) { 610 appendFieldStart(buffer, fieldName); 611 appendDetail(buffer, fieldName, value); 612 appendFieldEnd(buffer, fieldName); 613 } 614 615 623 protected void appendDetail(StringBuffer buffer, String fieldName, char value) { 624 buffer.append(value); 625 } 626 627 629 637 public void append(StringBuffer buffer, String fieldName, double value) { 638 appendFieldStart(buffer, fieldName); 639 appendDetail(buffer, fieldName, value); 640 appendFieldEnd(buffer, fieldName); 641 } 642 643 651 protected void appendDetail(StringBuffer buffer, String fieldName, double value) { 652 buffer.append(value); 653 } 654 655 657 665 public void append(StringBuffer buffer, String fieldName, float value) { 666 appendFieldStart(buffer, fieldName); 667 appendDetail(buffer, fieldName, value); 668 appendFieldEnd(buffer, fieldName); 669 } 670 671 679 protected void appendDetail(StringBuffer buffer, String fieldName, float value) { 680 buffer.append(value); 681 } 682 683 685 693 public void append(StringBuffer buffer, String fieldName, boolean value) { 694 appendFieldStart(buffer, fieldName); 695 appendDetail(buffer, fieldName, value); 696 appendFieldEnd(buffer, fieldName); 697 } 698 699 707 protected void appendDetail(StringBuffer buffer, String fieldName, boolean value) { 708 buffer.append(value); 709 } 710 711 721 public void append(StringBuffer buffer, String fieldName, Object [] array, Boolean fullDetail) { 722 appendFieldStart(buffer, fieldName); 723 724 if (array == null) { 725 appendNullText(buffer, fieldName); 726 727 } else if (isFullDetail(fullDetail)) { 728 appendDetail(buffer, fieldName, array); 729 730 } else { 731 appendSummary(buffer, fieldName, array); 732 } 733 734 appendFieldEnd(buffer, fieldName); 735 } 736 737 739 748 protected void appendDetail(StringBuffer buffer, String fieldName, Object [] array) { 749 buffer.append(arrayStart); 750 for (int i = 0; i < array.length; i++) { 751 Object item = array[i]; 752 if (i > 0) { 753 buffer.append(arraySeparator); 754 } 755 if (item == null) { 756 appendNullText(buffer, fieldName); 757 758 } else { 759 appendInternal(buffer, fieldName, item, arrayContentDetail); 760 } 761 } 762 buffer.append(arrayEnd); 763 } 764 765 774 protected void reflectionAppendArrayDetail(StringBuffer buffer, String fieldName, Object array) { 775 buffer.append(arrayStart); 776 int length = Array.getLength(array); 777 for (int i = 0; i < length; i++) { 778 Object item = Array.get(array, i); 779 if (i > 0) { 780 buffer.append(arraySeparator); 781 } 782 if (item == null) { 783 appendNullText(buffer, fieldName); 784 785 } else { 786 appendInternal(buffer, fieldName, item, arrayContentDetail); 787 } 788 } 789 buffer.append(arrayEnd); 790 } 791 792 801 protected void appendSummary(StringBuffer buffer, String fieldName, Object [] array) { 802 appendSummarySize(buffer, fieldName, array.length); 803 } 804 805 807 817 public void append(StringBuffer buffer, String fieldName, long[] array, Boolean fullDetail) { 818 appendFieldStart(buffer, fieldName); 819 820 if (array == null) { 821 appendNullText(buffer, fieldName); 822 823 } else if (isFullDetail(fullDetail)) { 824 appendDetail(buffer, fieldName, array); 825 826 } else { 827 appendSummary(buffer, fieldName, array); 828 } 829 830 appendFieldEnd(buffer, fieldName); 831 } 832 833 842 protected void appendDetail(StringBuffer buffer, String fieldName, long[] array) { 843 buffer.append(arrayStart); 844 for (int i = 0; i < array.length; i++) { 845 if (i > 0) { 846 buffer.append(arraySeparator); 847 } 848 appendDetail(buffer, fieldName, array[i]); 849 } 850 buffer.append(arrayEnd); 851 } 852 853 862 protected void appendSummary(StringBuffer buffer, String fieldName, long[] array) { 863 appendSummarySize(buffer, fieldName, array.length); 864 } 865 866 868 878 public void append(StringBuffer buffer, String fieldName, int[] array, Boolean fullDetail) { 879 appendFieldStart(buffer, fieldName); 880 881 if (array == null) { 882 appendNullText(buffer, fieldName); 883 884 } else if (isFullDetail(fullDetail)) { 885 appendDetail(buffer, fieldName, array); 886 887 } else { 888 appendSummary(buffer, fieldName, array); 889 } 890 891 appendFieldEnd(buffer, fieldName); 892 } 893 894 903 protected void appendDetail(StringBuffer buffer, String fieldName, int[] array) { 904 buffer.append(arrayStart); 905 for (int i = 0; i < array.length; i++) { 906 if (i > 0) { 907 buffer.append(arraySeparator); 908 } 909 appendDetail(buffer, fieldName, array[i]); 910 } 911 buffer.append(arrayEnd); 912 } 913 914 923 protected void appendSummary(StringBuffer buffer, String fieldName, int[] array) { 924 appendSummarySize(buffer, fieldName, array.length); 925 } 926 927 929 939 public void append(StringBuffer buffer, String fieldName, short[] array, Boolean fullDetail) { 940 appendFieldStart(buffer, fieldName); 941 942 if (array == null) { 943 appendNullText(buffer, fieldName); 944 945 } else if (isFullDetail(fullDetail)) { 946 appendDetail(buffer, fieldName, array); 947 948 } else { 949 appendSummary(buffer, fieldName, array); 950 } 951 952 appendFieldEnd(buffer, fieldName); 953 } 954 955 964 protected void appendDetail(StringBuffer buffer, String fieldName, short[] array) { 965 buffer.append(arrayStart); 966 for (int i = 0; i < array.length; i++) { 967 if (i > 0) { 968 buffer.append(arraySeparator); 969 } 970 appendDetail(buffer, fieldName, array[i]); 971 } 972 buffer.append(arrayEnd); 973 } 974 975 984 protected void appendSummary(StringBuffer buffer, String fieldName, short[] array) { 985 appendSummarySize(buffer, fieldName, array.length); 986 } 987 988 990 1000 public void append(StringBuffer buffer, String fieldName, byte[] array, Boolean fullDetail) { 1001 appendFieldStart(buffer, fieldName); 1002 1003 if (array == null) { 1004 appendNullText(buffer, fieldName); 1005 1006 } else if (isFullDetail(fullDetail)) { 1007 appendDetail(buffer, fieldName, array); 1008 1009 } else { 1010 appendSummary(buffer, fieldName, array); 1011 } 1012 1013 appendFieldEnd(buffer, fieldName); 1014 } 1015 1016 1025 protected void appendDetail(StringBuffer buffer, String fieldName, byte[] array) { 1026 buffer.append(arrayStart); 1027 for (int i = 0; i < array.length; i++) { 1028 if (i > 0) { 1029 buffer.append(arraySeparator); 1030 } 1031 appendDetail(buffer, fieldName, array[i]); 1032 } 1033 buffer.append(arrayEnd); 1034 } 1035 1036 1045 protected void appendSummary(StringBuffer buffer, String fieldName, byte[] array) { 1046 appendSummarySize(buffer, fieldName, array.length); 1047 } 1048 1049 1051 1061 public void append(StringBuffer buffer, String fieldName, char[] array, Boolean fullDetail) { 1062 appendFieldStart(buffer, fieldName); 1063 1064 if (array == null) { 1065 appendNullText(buffer, fieldName); 1066 1067 } else if (isFullDetail(fullDetail)) { 1068 appendDetail(buffer, fieldName, array); 1069 1070 } else { 1071 appendSummary(buffer, fieldName, array); 1072 } 1073 1074 appendFieldEnd(buffer, fieldName); 1075 } 1076 1077 1086 protected void appendDetail(StringBuffer buffer, String fieldName, char[] array) { 1087 buffer.append(arrayStart); 1088 for (int i = 0; i < array.length; i++) { 1089 if (i > 0) { 1090 buffer.append(arraySeparator); 1091 } 1092 appendDetail(buffer, fieldName, array[i]); 1093 } 1094 buffer.append(arrayEnd); 1095 } 1096 1097 1106 protected void appendSummary(StringBuffer buffer, String fieldName, char[] array) { 1107 appendSummarySize(buffer, fieldName, array.length); 1108 } 1109 1110 1112 1122 public void append(StringBuffer buffer, String fieldName, double[] array, Boolean fullDetail) { 1123 appendFieldStart(buffer, fieldName); 1124 1125 if (array == null) { 1126 appendNullText(buffer, fieldName); 1127 1128 } else if (isFullDetail(fullDetail)) { 1129 appendDetail(buffer, fieldName, array); 1130 1131 } else { 1132 appendSummary(buffer, fieldName, array); 1133 } 1134 1135 appendFieldEnd(buffer, fieldName); 1136 } 1137 1138 1147 protected void appendDetail(StringBuffer buffer, String fieldName, double[] array) { 1148 buffer.append(arrayStart); 1149 for (int i = 0; i < array.length; i++) { 1150 if (i > 0) { 1151 buffer.append(arraySeparator); 1152 } 1153 appendDetail(buffer, fieldName, array[i]); 1154 } 1155 buffer.append(arrayEnd); 1156 } 1157 1158 1167 protected void appendSummary(StringBuffer buffer, String fieldName, double[] array) { 1168 appendSummarySize(buffer, fieldName, array.length); 1169 } 1170 1171 1173 1183 public void append(StringBuffer buffer, String fieldName, float[] array, Boolean fullDetail) { 1184 appendFieldStart(buffer, fieldName); 1185 1186 if (array == null) { 1187 appendNullText(buffer, fieldName); 1188 1189 } else if (isFullDetail(fullDetail)) { 1190 appendDetail(buffer, fieldName, array); 1191 1192 } else { 1193 appendSummary(buffer, fieldName, array); 1194 } 1195 1196 appendFieldEnd(buffer, fieldName); 1197 } 1198 1199 1208 protected void appendDetail(StringBuffer buffer, String fieldName, float[] array) { 1209 buffer.append(arrayStart); 1210 for (int i = 0; i < array.length; i++) { 1211 if (i > 0) { 1212 buffer.append(arraySeparator); 1213 } 1214 appendDetail(buffer, fieldName, array[i]); 1215 } 1216 buffer.append(arrayEnd); 1217 } 1218 1219 1228 protected void appendSummary(StringBuffer buffer, String fieldName, float[] array) { 1229 appendSummarySize(buffer, fieldName, array.length); 1230 } 1231 1232 1234 1244 public void append(StringBuffer buffer, String fieldName, boolean[] array, Boolean fullDetail) { 1245 appendFieldStart(buffer, fieldName); 1246 1247 if (array == null) { 1248 appendNullText(buffer, fieldName); 1249 1250 } else if (isFullDetail(fullDetail)) { 1251 appendDetail(buffer, fieldName, array); 1252 1253 } else { 1254 appendSummary(buffer, fieldName, array); 1255 } 1256 1257 appendFieldEnd(buffer, fieldName); 1258 } 1259 1260 1269 protected void appendDetail(StringBuffer buffer, String fieldName, boolean[] array) { 1270 buffer.append(arrayStart); 1271 for (int i = 0; i < array.length; i++) { 1272 if (i > 0) { 1273 buffer.append(arraySeparator); 1274 } 1275 appendDetail(buffer, fieldName, array[i]); 1276 } 1277 buffer.append(arrayEnd); 1278 } 1279 1280 1289 protected void appendSummary(StringBuffer buffer, String fieldName, boolean[] array) { 1290 appendSummarySize(buffer, fieldName, array.length); 1291 } 1292 1293 1295 1301 protected void appendClassName(StringBuffer buffer, Object object) { 1302 if (useClassName && object != null) { 1303 if (useShortClassName) { 1304 buffer.append(getShortClassName(object.getClass())); 1305 } else { 1306 buffer.append(object.getClass().getName()); 1307 } 1308 } 1309 } 1310 1311 1317 protected void appendIdentityHashCode(StringBuffer buffer, Object object) { 1318 if (this.isUseIdentityHashCode() && object!=null) { 1319 buffer.append('@'); 1320 buffer.append(Integer.toHexString(System.identityHashCode(object))); 1321 } 1322 } 1323 1324 1329 protected void appendContentStart(StringBuffer buffer) { 1330 buffer.append(contentStart); 1331 } 1332 1333 1338 protected void appendContentEnd(StringBuffer buffer) { 1339 buffer.append(contentEnd); 1340 } 1341 1342 1350 protected void appendNullText(StringBuffer buffer, String fieldName) { 1351 buffer.append(nullText); 1352 } 1353 1354 1359 protected void appendFieldSeparator(StringBuffer buffer) { 1360 buffer.append(fieldSeparator); 1361 } 1362 1363 1369 protected void appendFieldStart(StringBuffer buffer, String fieldName) { 1370 if (useFieldNames && fieldName != null) { 1371 buffer.append(fieldName); 1372 buffer.append(fieldNameValueSeparator); 1373 } 1374 } 1375 1376 1382 protected void appendFieldEnd(StringBuffer buffer, String fieldName) { 1383 appendFieldSeparator(buffer); 1384 } 1385 1386 1401 protected void appendSummarySize(StringBuffer buffer, String fieldName, int size) { 1402 buffer.append(sizeStartText); 1403 buffer.append(size); 1404 buffer.append(sizeEndText); 1405 } 1406 1407 1421 protected boolean isFullDetail(Boolean fullDetailRequest) { 1422 if (fullDetailRequest == null) { 1423 return defaultFullDetail; 1424 } 1425 return fullDetailRequest.booleanValue(); 1426 } 1427 1428 1437 protected String getShortClassName(Class cls) { 1438 return ClassUtils.getShortClassName(cls); 1439 } 1440 1441 1446 1451 protected boolean isUseClassName() { 1452 return useClassName; 1453 } 1454 1455 1460 protected void setUseClassName(boolean useClassName) { 1461 this.useClassName = useClassName; 1462 } 1463 1464 1466 1472 protected boolean isUseShortClassName() { 1473 return useShortClassName; 1474 } 1475 1476 1483 protected boolean isShortClassName() { 1484 return useShortClassName; 1485 } 1486 1487 1493 protected void setUseShortClassName(boolean useShortClassName) { 1494 this.useShortClassName = useShortClassName; 1495 } 1496 1497 1504 protected void setShortClassName(boolean shortClassName) { 1505 this.useShortClassName = shortClassName; 1506 } 1507 1508 1510 1515 protected boolean isUseIdentityHashCode() { 1516 return useIdentityHashCode; 1517 } 1518 1519 1524 protected void setUseIdentityHashCode(boolean useIdentityHashCode) { 1525 this.useIdentityHashCode = useIdentityHashCode; 1526 } 1527 1528 1530 1535 protected boolean isUseFieldNames() { 1536 return useFieldNames; 1537 } 1538 1539 1544 protected void setUseFieldNames(boolean useFieldNames) { 1545 this.useFieldNames = useFieldNames; 1546 } 1547 1548 1550 1556 protected boolean isDefaultFullDetail() { 1557 return defaultFullDetail; 1558 } 1559 1560 1566 protected void setDefaultFullDetail(boolean defaultFullDetail) { 1567 this.defaultFullDetail = defaultFullDetail; 1568 } 1569 1570 1572 1577 protected boolean isArrayContentDetail() { 1578 return arrayContentDetail; 1579 } 1580 1581 1586 protected void setArrayContentDetail(boolean arrayContentDetail) { 1587 this.arrayContentDetail = arrayContentDetail; 1588 } 1589 1590 1592 1597 protected String getArrayStart() { 1598 return arrayStart; 1599 } 1600 1601 1609 protected void setArrayStart(String arrayStart) { 1610 if (arrayStart == null) { 1611 arrayStart = ""; 1612 } 1613 this.arrayStart = arrayStart; 1614 } 1615 1616 1618 1623 protected String getArrayEnd() { 1624 return arrayEnd; 1625 } 1626 1627 1635 protected void setArrayEnd(String arrayEnd) { 1636 if (arrayEnd == null) { 1637 arrayEnd = ""; 1638 } 1639 this.arrayEnd = arrayEnd; 1640 } 1641 1642 1644 1649 protected String getArraySeparator() { 1650 return arraySeparator; 1651 } 1652 1653 1661 protected void setArraySeparator(String arraySeparator) { 1662 if (arraySeparator == null) { 1663 arraySeparator = ""; 1664 } 1665 this.arraySeparator = arraySeparator; 1666 } 1667 1668 1670 1675 protected String getContentStart() { 1676 return contentStart; 1677 } 1678 1679 1687 protected void setContentStart(String contentStart) { 1688 if (contentStart == null) { 1689 contentStart = ""; 1690 } 1691 this.contentStart = contentStart; 1692 } 1693 1694 1696 1701 protected String getContentEnd() { 1702 return contentEnd; 1703 } 1704 1705 1713 protected void setContentEnd(String contentEnd) { 1714 if (contentEnd == null) { 1715 contentEnd = ""; 1716 } 1717 this.contentEnd = contentEnd; 1718 } 1719 1720 1722 1727 protected String getFieldNameValueSeparator() { 1728 return fieldNameValueSeparator; 1729 } 1730 1731 1739 protected void setFieldNameValueSeparator(String fieldNameValueSeparator) { 1740 if (fieldNameValueSeparator == null) { 1741 fieldNameValueSeparator = ""; 1742 } 1743 this.fieldNameValueSeparator = fieldNameValueSeparator; 1744 } 1745 1746 1748 1753 protected String getFieldSeparator() { 1754 return fieldSeparator; 1755 } 1756 1757 1765 protected void setFieldSeparator(String fieldSeparator) { 1766 if (fieldSeparator == null) { 1767 fieldSeparator = ""; 1768 } 1769 this.fieldSeparator = fieldSeparator; 1770 } 1771 1772 1774 1781 protected boolean isFieldSeparatorAtStart() { 1782 return fieldSeparatorAtStart; 1783 } 1784 1785 1792 protected void setFieldSeparatorAtStart(boolean fieldSeparatorAtStart) { 1793 this.fieldSeparatorAtStart = fieldSeparatorAtStart; 1794 } 1795 1796 1798 1805 protected boolean isFieldSeparatorAtEnd() { 1806 return fieldSeparatorAtEnd; 1807 } 1808 1809 1816 protected void setFieldSeparatorAtEnd(boolean fieldSeparatorAtEnd) { 1817 this.fieldSeparatorAtEnd = fieldSeparatorAtEnd; 1818 } 1819 1820 1822 1827 protected String getNullText() { 1828 return nullText; 1829 } 1830 1831 1839 protected void setNullText(String nullText) { 1840 if (nullText == null) { 1841 nullText = ""; 1842 } 1843 this.nullText = nullText; 1844 } 1845 1846 1848 1856 protected String getSizeStartText() { 1857 return sizeStartText; 1858 } 1859 1860 1871 protected void setSizeStartText(String sizeStartText) { 1872 if (sizeStartText == null) { 1873 sizeStartText = ""; 1874 } 1875 this.sizeStartText = sizeStartText; 1876 } 1877 1878 1880 1888 protected String getSizeEndText() { 1889 return sizeEndText; 1890 } 1891 1892 1903 protected void setSizeEndText(String sizeEndText) { 1904 if (sizeEndText == null) { 1905 sizeEndText = ""; 1906 } 1907 this.sizeEndText = sizeEndText; 1908 } 1909 1910 1912 1920 protected String getSummaryObjectStartText() { 1921 return summaryObjectStartText; 1922 } 1923 1924 1935 protected void setSummaryObjectStartText(String summaryObjectStartText) { 1936 if (summaryObjectStartText == null) { 1937 summaryObjectStartText = ""; 1938 } 1939 this.summaryObjectStartText = summaryObjectStartText; 1940 } 1941 1942 1944 1952 protected String getSummaryObjectEndText() { 1953 return summaryObjectEndText; 1954 } 1955 1956 1967 protected void setSummaryObjectEndText(String summaryObjectEndText) { 1968 if (summaryObjectEndText == null) { 1969 summaryObjectEndText = ""; 1970 } 1971 this.summaryObjectEndText = summaryObjectEndText; 1972 } 1973 1974 1976 1982 private static final class DefaultToStringStyle extends ToStringStyle { 1983 1984 1989 private DefaultToStringStyle() { 1990 super(); 1991 } 1992 1993 1998 private Object readResolve() { 1999 return ToStringStyle.DEFAULT_STYLE; 2000 } 2001 2002 } 2003 2004 2006 2013 private static final class NoFieldNameToStringStyle extends ToStringStyle { 2014 2015 2020 private NoFieldNameToStringStyle() { 2021 super(); 2022 this.setUseFieldNames(false); 2023 } 2024 2025 2030 private Object readResolve() { 2031 return ToStringStyle.NO_FIELD_NAMES_STYLE; 2032 } 2033 2034 } 2035 2036 2038 2045 private static final class ShortPrefixToStringStyle extends ToStringStyle { 2046 2047 2052 private ShortPrefixToStringStyle() { 2053 super(); 2054 this.setUseShortClassName(true); 2055 this.setUseIdentityHashCode(false); 2056 } 2057 2058 2062 private Object readResolve() { 2063 return ToStringStyle.SHORT_PREFIX_STYLE; 2064 } 2065 2066 } 2067 2068 2075 private static final class SimpleToStringStyle extends ToStringStyle { 2076 2077 2082 private SimpleToStringStyle() { 2083 super(); 2084 this.setUseClassName(false); 2085 this.setUseIdentityHashCode(false); 2086 this.setUseFieldNames(false); 2087 this.setContentStart(""); 2088 this.setContentEnd(""); 2089 } 2090 2091 2095 private Object readResolve() { 2096 return ToStringStyle.SIMPLE_STYLE; 2097 } 2098 2099 } 2100 2101 2103 2109 private static final class MultiLineToStringStyle extends ToStringStyle { 2110 2111 2116 private MultiLineToStringStyle() { 2117 super(); 2118 this.setContentStart("["); 2119 this.setFieldSeparator(SystemUtils.LINE_SEPARATOR + " "); 2120 this.setFieldSeparatorAtStart(true); 2121 this.setContentEnd(SystemUtils.LINE_SEPARATOR + "]"); 2122 } 2123 2124 2129 private Object readResolve() { 2130 return ToStringStyle.MULTI_LINE_STYLE; 2131 } 2132 2133 } 2134 2135} 2136 | Popular Tags |