MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / deepToStringImpl

Method deepToStringImpl

Ports/CLDC11/src/java/util/Arrays.java:3785–3835  ·  view source on GitHub ↗
(Object[] array, Object[] origArrays,
            StringBuffer sb)

Source from the content-addressed store, hash-verified

3783 ///
3784 /// - #deepToString(Object[])
3785 private static String deepToStringImpl(Object[] array, Object[] origArrays,
3786 StringBuffer sb) {
3787 if (array == null) {
3788 return "null"; //$NON-NLS-1$
3789 }
3790 if (array.length == 0) {
3791 return "[]"; //$NON-NLS-1$
3792 }
3793
3794 if (sb == null) {
3795 sb = new StringBuffer(2 + array.length * 5);
3796 }
3797 sb.append('[');
3798
3799 for (int i = 0; i < array.length; i++) {
3800 if (i != 0) {
3801 sb.append(", "); //$NON-NLS-1$
3802 }
3803 // establish current element
3804 Object elem = array[i];
3805 if (elem == null) {
3806 // element is null
3807 sb.append("null"); //$NON-NLS-1$
3808 } else {
3809 // get the Class of the current element
3810 Class<?> elemClass = elem.getClass();
3811 if (elemClass.isArray()) {
3812 // element is an array type
3813
3814 // get the declared Class of the array (element)
3815 //Class<?> elemElemClass = elemClass.getComponentType();
3816 // element is an Object[], so we assert that
3817 if (deepToStringImplContains(origArrays, elem)) {
3818 sb.append("[...]"); //$NON-NLS-1$
3819 } else {
3820 Object[] newArray = (Object[]) elem;
3821 Object[] newOrigArrays = new Object[origArrays.length + 1];
3822 System.arraycopy(origArrays, 0, newOrigArrays, 0,
3823 origArrays.length);
3824 newOrigArrays[origArrays.length] = newArray;
3825 // make the recursive call to this method
3826 deepToStringImpl(newArray, newOrigArrays, sb);
3827 }
3828 } else { // element is NOT an array, just an Object
3829 sb.append(array[i]);
3830 }
3831 }
3832 }
3833 sb.append(']');
3834 return sb.toString();
3835 }
3836
3837 /// Utility method used to assist the implementation of
3838 /// `#deepToString(Object[])`.

Callers 1

deepToStringMethod · 0.95

Calls 6

getClassMethod · 0.95
arraycopyMethod · 0.95
appendMethod · 0.65
toStringMethod · 0.65
isArrayMethod · 0.45

Tested by

no test coverage detected