Skip to content

Commit

Permalink
Renamed U.readable to U.str.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Oct 27, 2015
1 parent 73ca62f commit bb41b2a
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 68 deletions.
Expand Up @@ -39,7 +39,7 @@ public static boolean contains(Object arrOrColl, Object value) {
Collection<?> coll = (Collection<?>) arrOrColl; Collection<?> coll = (Collection<?>) arrOrColl;
return coll.contains(value); return coll.contains(value);
} else { } else {
throw U.illegalArg("Expected array or collection, but found: %s", U.readable(arrOrColl)); throw U.illegalArg("Expected array or collection, but found: %s", U.str(arrOrColl));
} }
} }


Expand Down
4 changes: 2 additions & 2 deletions rapidoid-cls/src/main/java/org/rapidoid/cls/Cls.java
Expand Up @@ -660,7 +660,7 @@ public static <T> T convert(Object value, Class<T> toType) {
} else if (value instanceof char[]) { } else if (value instanceof char[]) {
return (T) new String((char[]) value); return (T) new String((char[]) value);
} else { } else {
return (T) U.readable(value); return (T) U.str(value);
} }


case OBJECT: case OBJECT:
Expand Down Expand Up @@ -829,7 +829,7 @@ public static <T> T newInstance(Class<T> clazz, Object... args) {
} }
} }


throw U.rte("Cannot find appropriate constructor for %s with args %s!", clazz, U.readable(args)); throw U.rte("Cannot find appropriate constructor for %s with args %s!", clazz, U.str(args));
} }


public static <T> T customizable(Class<T> clazz, Object... args) { public static <T> T customizable(Class<T> clazz, Object... args) {
Expand Down
2 changes: 1 addition & 1 deletion rapidoid-cls/src/main/java/org/rapidoid/cls/Proxies.java
Expand Up @@ -64,7 +64,7 @@ public Object invoke(Object target, Method method, Object[] args) throws Throwab
} }


public static <T> T implement(InvocationHandler handler, Class<?>... classes) { public static <T> T implement(InvocationHandler handler, Class<?>... classes) {
return implement(new InterceptorProxy(U.readable(classes)), handler, classes); return implement(new InterceptorProxy(U.str(classes)), handler, classes);
} }


public static <T> T implementInterfaces(Object target, InvocationHandler handler) { public static <T> T implementInterfaces(Object target, InvocationHandler handler) {
Expand Down
Expand Up @@ -98,7 +98,7 @@ public void str(Object content, int level, boolean inline, Object extra, OutputS
} }


indent(out, level, inline); indent(out, level, inline);
write(out, HTML.escape(U.readable(content))); write(out, HTML.escape(U.str(content)));
} }


protected void join(Collection<?> items, int level, boolean inline, Object extra, OutputStream out) { protected void join(Collection<?> items, int level, boolean inline, Object extra, OutputStream out) {
Expand Down
49 changes: 14 additions & 35 deletions rapidoid-u/src/main/java/org/rapidoid/util/U.java
Expand Up @@ -67,7 +67,7 @@ public class U {


private static final Object[] EMPTY_ARRAY = {}; private static final Object[] EMPTY_ARRAY = {};


public static String readable(Object obj) { public static String str(Object obj) {
if (obj == null) { if (obj == null) {
return "null"; return "null";
} else if (obj instanceof byte[]) { } else if (obj instanceof byte[]) {
Expand All @@ -87,21 +87,21 @@ public static String readable(Object obj) {
} else if (obj instanceof char[]) { } else if (obj instanceof char[]) {
return Arrays.toString((char[]) obj); return Arrays.toString((char[]) obj);
} else if (obj instanceof Object[]) { } else if (obj instanceof Object[]) {
return readable((Object[]) obj); return str((Object[]) obj);
} else { } else {
return String.valueOf(obj); return String.valueOf(obj);
} }
} }


public static String readable(Object[] objs) { public static String str(Object[] objs) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("["); sb.append("[");


for (int i = 0; i < objs.length; i++) { for (int i = 0; i < objs.length; i++) {
if (i > 0) { if (i > 0) {
sb.append(", "); sb.append(", ");
} }
sb.append(readable(objs[i])); sb.append(str(objs[i]));
} }


sb.append("]"); sb.append("]");
Expand All @@ -115,13 +115,13 @@ public static String format(String s, Object... args) {


public static String nice(String format, Object... args) { public static String nice(String format, Object... args) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
args[i] = readable(args[i]); args[i] = str(args[i]);
} }


return String.format(format, args); return String.format(format, args);
} }


public static String readable(Iterable<Object> coll) { public static String str(Iterable<Object> coll) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("["); sb.append("[");


Expand All @@ -132,15 +132,15 @@ public static String readable(Iterable<Object> coll) {
sb.append(", "); sb.append(", ");
} }


sb.append(readable(obj)); sb.append(str(obj));
first = false; first = false;
} }


sb.append("]"); sb.append("]");
return sb.toString(); return sb.toString();
} }


public static String readable(Iterator<?> it) { public static String str(Iterator<?> it) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("["); sb.append("[");


Expand All @@ -152,31 +152,14 @@ public static String readable(Iterator<?> it) {
first = false; first = false;
} }


sb.append(readable(it.next())); sb.append(str(it.next()));
} }


sb.append("]"); sb.append("]");


return sb.toString(); return sb.toString();
} }


public static String readableln(Object[] objs) {
StringBuilder sb = new StringBuilder();
sb.append("[");

for (int i = 0; i < objs.length; i++) {
if (i > 0) {
sb.append(",");
}
sb.append("\n ");
sb.append(readable(objs[i]));
}

sb.append("\n]");

return sb.toString();
}

public static String replaceText(String s, String[][] repls) { public static String replaceText(String s, String[][] repls) {
for (String[] repl : repls) { for (String[] repl : repls) {
s = s.replaceAll(Pattern.quote(repl[0]), repl[1]); s = s.replaceAll(Pattern.quote(repl[0]), repl[1]);
Expand All @@ -188,7 +171,7 @@ public static void print(Object... values) {
String text; String text;


if (values != null) { if (values != null) {
text = values.length == 1 ? readable(values[0]) : readable(values); text = values.length == 1 ? str(values[0]) : str(values);
} else { } else {
text = "null"; text = "null";
} }
Expand Down Expand Up @@ -626,21 +609,21 @@ public static boolean must(boolean expectedCondition, String message, long arg)


public static boolean must(boolean expectedCondition, String message, Object arg) { public static boolean must(boolean expectedCondition, String message, Object arg) {
if (!expectedCondition) { if (!expectedCondition) {
throw rte(message, readable(arg)); throw rte(message, str(arg));
} }
return true; return true;
} }


public static boolean must(boolean expectedCondition, String message, Object arg1, Object arg2) { public static boolean must(boolean expectedCondition, String message, Object arg1, Object arg2) {
if (!expectedCondition) { if (!expectedCondition) {
throw rte(message, readable(arg1), readable(arg2)); throw rte(message, str(arg1), str(arg2));
} }
return true; return true;
} }


public static boolean must(boolean expectedCondition, String message, Object arg1, Object arg2, Object arg3) { public static boolean must(boolean expectedCondition, String message, Object arg1, Object arg2, Object arg3) {
if (!expectedCondition) { if (!expectedCondition) {
throw rte(message, readable(arg1), readable(arg2), readable(arg3)); throw rte(message, str(arg1), str(arg2), str(arg3));
} }
return true; return true;
} }
Expand All @@ -651,7 +634,7 @@ public static IllegalArgumentException illegalArg(String message, Object... args


public static void secure(boolean condition, String msg) { public static void secure(boolean condition, String msg) {
if (!condition) { if (!condition) {
throw new SecurityException(readable(msg)); throw new SecurityException(str(msg));
} }
} }


Expand Down Expand Up @@ -767,10 +750,6 @@ public static String insert(String target, int atIndex, String insertion) {
return target.substring(0, atIndex) + insertion + target.substring(atIndex); return target.substring(0, atIndex) + insertion + target.substring(atIndex);
} }


public static String str(Object value) {
return String.valueOf(value);
}

public static int num(String s) { public static int num(String s) {
return Integer.parseInt(s); return Integer.parseInt(s);
} }
Expand Down
46 changes: 23 additions & 23 deletions rapidoid-u/src/test/java/org/rapidoid/util/UTest.java
Expand Up @@ -46,55 +46,55 @@ public class UTest extends TestCommons {


@Test @Test
public void testTextCollectionOfObject() { public void testTextCollectionOfObject() {
eq(U.readable(new ArrayList<Integer>()), "[]"); eq(U.str(new ArrayList<Integer>()), "[]");


List<String> lst = new ArrayList<String>(); List<String> lst = new ArrayList<String>();


lst.add("java"); lst.add("java");
lst.add("c"); lst.add("c");
lst.add("c++"); lst.add("c++");


eq(U.readable(lst), "[java, c, c++]"); eq(U.str(lst), "[java, c, c++]");
} }


@Test @Test
public void testTextObject() { public void testTextObject() {
eq(U.readable((Object) null), "null"); eq(U.str((Object) null), "null");


eq(U.readable(123), "123"); eq(U.str(123), "123");
eq(U.readable(1.23), "1.23"); eq(U.str(1.23), "1.23");


eq(U.readable(true), "true"); eq(U.str(true), "true");
eq(U.readable(false), "false"); eq(U.str(false), "false");


eq(U.readable(""), ""); eq(U.str(""), "");
eq(U.readable("abc"), "abc"); eq(U.str("abc"), "abc");


eq(U.readable(new byte[] { -50, 0, 9 }), "[-50, 0, 9]"); eq(U.str(new byte[] { -50, 0, 9 }), "[-50, 0, 9]");
eq(U.readable(new short[] { -500, 0, 9 }), "[-500, 0, 9]"); eq(U.str(new short[] { -500, 0, 9 }), "[-500, 0, 9]");
eq(U.readable(new int[] { 300000000, 70, 100 }), "[300000000, 70, 100]"); eq(U.str(new int[] { 300000000, 70, 100 }), "[300000000, 70, 100]");
eq(U.readable(new long[] { 3000000000000000000L, 1, -8900000000000000000L }), eq(U.str(new long[] { 3000000000000000000L, 1, -8900000000000000000L }),
"[3000000000000000000, 1, -8900000000000000000]"); "[3000000000000000000, 1, -8900000000000000000]");


eq(U.readable(new float[] { -30.40000000f, -1.587f, 89.3f }), "[-30.4, -1.587, 89.3]"); eq(U.str(new float[] { -30.40000000f, -1.587f, 89.3f }), "[-30.4, -1.587, 89.3]");
eq(U.readable(new double[] { -9987.1, -1.5, 8.3 }), "[-9987.1, -1.5, 8.3]"); eq(U.str(new double[] { -9987.1, -1.5, 8.3 }), "[-9987.1, -1.5, 8.3]");


eq(U.readable(new boolean[] { true }), "[true]"); eq(U.str(new boolean[] { true }), "[true]");


eq(U.readable(new char[] { 'k', 'o', 'h' }), "[k, o, h]"); eq(U.str(new char[] { 'k', 'o', 'h' }), "[k, o, h]");
eq(U.readable(new char[] { '-', '.', '+' }), "[-, ., +]"); eq(U.str(new char[] { '-', '.', '+' }), "[-, ., +]");
} }


@Test @Test
public void testTextObjectArray() { public void testTextObjectArray() {
eq(U.readable(new Object[] {}), "[]"); eq(U.str(new Object[] {}), "[]");
eq(U.readable(new Object[] { 1, new boolean[] { true, false }, 3 }), "[1, [true, false], 3]"); eq(U.str(new Object[] { 1, new boolean[] { true, false }, 3 }), "[1, [true, false], 3]");
eq(U.readable(new Object[] { new double[] { -9987.1 }, new char[] { 'a', '.' }, new int[] { 300, 70, 100 } }), eq(U.str(new Object[] { new double[] { -9987.1 }, new char[] { 'a', '.' }, new int[] { 300, 70, 100 } }),
"[[-9987.1], [a, .], [300, 70, 100]]"); "[[-9987.1], [a, .], [300, 70, 100]]");


eq(U.readable(new int[][] { { 1, 2 }, { 3, 4, 5 } }), "[[1, 2], [3, 4, 5]]"); eq(U.str(new int[][] { { 1, 2 }, { 3, 4, 5 } }), "[[1, 2], [3, 4, 5]]");


eq(U.readable(new String[][][] { { { "a" }, { "r" } }, { { "m" } } }), "[[[a], [r]], [[m]]]"); eq(U.str(new String[][][] { { { "a" }, { "r" } }, { { "m" } } }), "[[[a], [r]], [[m]]]");
} }


@Test @Test
Expand Down
2 changes: 1 addition & 1 deletion rapidoid-utils/src/main/java/org/rapidoid/util/D.java
Expand Up @@ -36,7 +36,7 @@ public static void print(Object... values) {
String text; String text;


if (values != null) { if (values != null) {
text = values.length == 1 ? U.readable(values[0]) : U.readable(values); text = values.length == 1 ? U.str(values[0]) : U.str(values);
} else { } else {
text = "null"; text = "null";
} }
Expand Down
2 changes: 1 addition & 1 deletion rapidoid-utils/src/main/java/org/rapidoid/util/Val.java
Expand Up @@ -45,7 +45,7 @@ public void set(T value) {


@Override @Override
public String toString() { public String toString() {
return U.readable(value); return U.str(value);
} }


} }
Expand Up @@ -39,7 +39,7 @@ public AbstractVar(String name) {


@Override @Override
public String toString() { public String toString() {
return U.readable(get()); return U.str(get());
} }


@Override @Override
Expand Down
Expand Up @@ -806,10 +806,10 @@ public static Object values(Object... values) {


for (Object value : values) { for (Object value : values) {
if (Arr.isArray(value) && !hasGUIElements(value)) { if (Arr.isArray(value) && !hasGUIElements(value)) {
value = U.readable(value); value = U.str(value);
} }
if (value == null || value instanceof Iterable<?>) { if (value == null || value instanceof Iterable<?>) {
value = U.readable(value); value = U.str(value);
} }
list.add(row(value)); list.add(row(value));
} }
Expand Down

0 comments on commit bb41b2a

Please sign in to comment.