org.snapscript.studio.agent.debug.ArrayStringBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-agent Show documentation
Show all versions of snap-agent Show documentation
Dynamic scripting for the JVM
package org.snapscript.studio.agent.debug;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.snapscript.core.Context;
import org.snapscript.core.scope.instance.Instance;
import org.snapscript.core.type.Type;
import org.snapscript.core.convert.proxy.ProxyWrapper;
public class ArrayStringBuilder {
private final Context context;
private final int limit;
public ArrayStringBuilder(Context context, int limit) {
this.context = context;
this.limit = limit;
}
public String toString(byte[] array) {
if (array != null) {
byte[] copy = new byte[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(int[] array) {
if (array != null) {
int[] copy = new int[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(long[] array) {
if (array != null) {
long[] copy = new long[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(short[] array) {
if (array != null) {
short[] copy = new short[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(double[] array) {
if (array != null) {
double[] copy = new double[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(float[] array) {
if (array != null) {
float[] copy = new float[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(char[] array) {
if (array != null) {
char[] copy = new char[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(boolean[] array) {
if (array != null) {
boolean[] copy = new boolean[array.length > limit ? limit : array.length];
System.arraycopy(array, 0, copy, 0, copy.length);
return Arrays.toString(copy);
}
return "null";
}
public String toString(Object[] array) {
Set done = new HashSet();
if (array != null) {
return toString(array, done);
}
return "null";
}
private String toString(Object[] array, Set