Skip to content

Commit

Permalink
Refactored the utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Feb 7, 2016
1 parent 8e48142 commit 9073f5d
Show file tree
Hide file tree
Showing 65 changed files with 877 additions and 809 deletions.
Expand Up @@ -25,6 +25,7 @@
import org.rapidoid.bytes.ByteBufferBytes;
import org.rapidoid.bytes.Bytes;
import org.rapidoid.bytes.BytesUtil;
import org.rapidoid.commons.Err;
import org.rapidoid.data.Range;
import org.rapidoid.data.Ranges;
import org.rapidoid.pool.Pool;
Expand Down Expand Up @@ -540,7 +541,7 @@ private int writePart(ByteBuffer src, int pos, int limit, int mode, byte[] bytes
break;

default:
throw U.notExpected();
throw Err.notExpected();
}

// restore buf positions
Expand Down
Expand Up @@ -22,9 +22,9 @@

import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.commons.Err;
import org.rapidoid.data.Range;
import org.rapidoid.data.Ranges;
import org.rapidoid.u.U;
import org.rapidoid.util.Constants;
import org.rapidoid.util.UTILS;
import org.rapidoid.wrap.IntWrap;
Expand Down Expand Up @@ -279,7 +279,7 @@ public static int find(Bytes bytes, int start, int limit, byte[] match, int offs
}

private static int findNoCase(Bytes bytes, int start, int limit, byte[] match, int offset, int length) {
throw U.notReady();
throw Err.notReady();
}

private static int findSensitive(Bytes bytes, int start, int limit, byte[] match, int offset, int length) {
Expand Down
21 changes: 11 additions & 10 deletions rapidoid-buffer/src/test/java/org/rapidoid/buffer/BufTest.java
Expand Up @@ -25,6 +25,7 @@
import org.rapidoid.annotation.Since;
import org.rapidoid.bytes.BytesUtil;
import org.rapidoid.commons.Rnd;
import org.rapidoid.commons.Str;
import org.rapidoid.data.Range;
import org.rapidoid.data.Ranges;
import org.rapidoid.u.U;
Expand Down Expand Up @@ -281,7 +282,7 @@ public void testScanUntilAndMatchPrefix() {
eq(range, 0, 2);

for (int i = 0; i < 10; i++) {
String s = U.mul("a", i);
String s = Str.mul("a", i);

eq(BytesUtil.scanUntilAndMatchPrefix(BytesUtil.from(s + ":"), range, COL, 0, i, NO_PREFIX), i + 1);
eq(range, 0, i);
Expand Down Expand Up @@ -350,22 +351,22 @@ public void testPutNumAsText() {
int n = U.num(num.substring(0, dig));

Buf buf = bufs.newBuf();
buf.append(U.mul(" ", dig + 2));
buf.append(Str.mul(" ", dig + 2));
buf.putNumAsText(1, n, true);
eq(buf.asText(), " " + n + " ");

Buf buf2 = bufs.newBuf();
buf2.append(U.mul(" ", dig + 3));
buf2.append(Str.mul(" ", dig + 3));
buf2.putNumAsText(1, -n, true);
eq(buf2.asText(), " " + (-n) + " ");

Buf buf3 = bufs.newBuf();
buf3.append(U.mul(" ", dig + 2));
buf3.append(Str.mul(" ", dig + 2));
buf3.putNumAsText(dig, n, false);
eq(buf3.asText(), " " + n + " ");

Buf buf4 = bufs.newBuf();
buf4.append(U.mul(" ", dig + 3));
buf4.append(Str.mul(" ", dig + 3));
buf4.putNumAsText(dig + 1, -n, false);
eq(buf4.asText(), " " + (-n) + " ");

Expand All @@ -375,14 +376,14 @@ public void testPutNumAsText() {
eq(buf5.asText(), " " + n);

Buf buf6 = bufs.newBuf();
buf6.append(U.mul(" ", 20));
buf6.append(Str.mul(" ", 20));
buf6.putNumAsText(15, n, false);
eq(buf6.asText(), U.mul(" ", 16 - dig) + n + U.mul(" ", 4));
eq(buf6.asText(), Str.mul(" ", 16 - dig) + n + Str.mul(" ", 4));

Buf buf7 = bufs.newBuf();
buf7.append(U.mul(" ", 20));
buf7.append(Str.mul(" ", 20));
buf7.putNumAsText(5, n, true);
eq(buf7.asText(), U.mul(" ", 5) + n + U.mul(" ", 15 - dig));
eq(buf7.asText(), Str.mul(" ", 5) + n + Str.mul(" ", 15 - dig));
}
}

Expand All @@ -397,7 +398,7 @@ public void testDeleteAfter() {

for (int j = 0; j < 5; j++) {
size += add;
buf.append(U.mul(" ", add));
buf.append(Str.mul(" ", add));
eq(buf.size(), size);
}

Expand Down
Expand Up @@ -23,7 +23,7 @@
import org.junit.Test;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.u.U;
import org.rapidoid.commons.Err;

@Authors("Nikolche Mihajlovski")
@Since("2.0.0")
Expand Down Expand Up @@ -66,7 +66,7 @@ public void shouldExpandAndShrink() {
break;

default:
throw U.notExpected();
throw Err.notExpected();
}
}

Expand Down
Expand Up @@ -127,7 +127,7 @@ public void testPerformance() {
cache.set(key + i, i, 10000, callback);
}

U.wait(latch);
UTILS.wait(latch);
UTILS.endMeasure(total, "SET ops");

total = 10000;
Expand All @@ -144,7 +144,7 @@ public void onDone(Object result, Throwable error) throws Exception {
cache.get(key + i, callback);
}

U.wait(rlatch);
UTILS.wait(rlatch);
UTILS.endMeasure(total, "GET ops");
}

Expand Down
13 changes: 7 additions & 6 deletions rapidoid-commons/src/main/java/org/rapidoid/beany/BeanProp.java
Expand Up @@ -24,6 +24,7 @@
import org.rapidoid.annotation.Since;
import org.rapidoid.cls.Cls;
import org.rapidoid.cls.TypeKind;
import org.rapidoid.commons.Err;
import org.rapidoid.u.U;
import org.rapidoid.var.Var;

Expand Down Expand Up @@ -208,7 +209,7 @@ public void set(Object target, Object value) {
break;

default:
throw U.notExpected();
throw Err.notExpected();
}
}

Expand Down Expand Up @@ -240,7 +241,7 @@ public void reset(Object target) {
break;

default:
throw U.notExpected();
throw Err.notExpected();
}
}

Expand Down Expand Up @@ -280,7 +281,7 @@ private void primitiveReset(Object target) {
break;

default:
throw U.notExpected();
throw Err.notExpected();
}

}
Expand Down Expand Up @@ -325,7 +326,7 @@ private void normalSet(Object target, Object value) {
setter.setAccessible(true);
setter.invoke(target, Cls.convert(value, setter.getParameterTypes()[0]));
} else if (getter != null) {
throw U.notExpected();
throw Err.notExpected();
}
} catch (Exception e) {
throw U.rte("Cannot set %s %s.%s = %s (%s)", e, getType(), getDeclaringType(), getName(), value,
Expand Down Expand Up @@ -373,7 +374,7 @@ public int getTypeArgsCount() {

@Override
public Class<?> getTypeArg(int index) {
U.bounds(index, 0, getTypeArgsCount() - 1);
Err.bounds(index, 0, getTypeArgsCount() - 1);
return Cls.clazz(genericType.getActualTypeArguments()[index]);
}

Expand Down Expand Up @@ -409,7 +410,7 @@ public int getRawTypeArgsCount() {

@Override
public Class<?> getRawTypeArg(int index) {
U.bounds(index, 0, getRawTypeArgsCount() - 1);
Err.bounds(index, 0, getRawTypeArgsCount() - 1);
return Cls.clazz(rawGenericType.getActualTypeArguments()[index]);
}

Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.cls.Cls;
import org.rapidoid.commons.Coll;
import org.rapidoid.lambda.Lmbd;
import org.rapidoid.lambda.Mapper;
import org.rapidoid.u.U;
Expand All @@ -45,9 +46,9 @@ public class BeanProperties implements Iterable<Prop> {

public final List<String> names;

public final ConcurrentMap<String, Object> extras = U.concurrentMap();
public final ConcurrentMap<String, Object> extras = Coll.concurrentMap();

public final Map<PropertySelector, BeanProperties> selections = U
public final Map<PropertySelector, BeanProperties> selections = Coll
.autoExpandingMap(new Mapper<PropertySelector, BeanProperties>() {
@Override
public BeanProperties map(PropertySelector selector) throws Exception {
Expand Down
3 changes: 2 additions & 1 deletion rapidoid-commons/src/main/java/org/rapidoid/beany/Beany.java
Expand Up @@ -6,6 +6,7 @@
import org.rapidoid.cls.Cls;
import org.rapidoid.cls.Proxies;
import org.rapidoid.cls.TypeKind;
import org.rapidoid.commons.Coll;
import org.rapidoid.commons.Dates;
import org.rapidoid.lambda.Mapper;
import org.rapidoid.log.Log;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class Beany {

private static final String SETTER = "^set[A-Z].*";

protected static final Map<Class<?>, BeanProperties> BEAN_PROPERTIES = U
protected static final Map<Class<?>, BeanProperties> BEAN_PROPERTIES = Coll
.autoExpandingMap(new Mapper<Class<?>, BeanProperties>() {

@Override
Expand Down
12 changes: 7 additions & 5 deletions rapidoid-commons/src/main/java/org/rapidoid/cls/Cls.java
Expand Up @@ -20,7 +20,9 @@
* #L%
*/

import org.rapidoid.commons.Coll;
import org.rapidoid.commons.Dates;
import org.rapidoid.commons.Err;
import org.rapidoid.u.U;
import org.rapidoid.var.Var;
import org.rapidoid.var.Vars;
Expand Down Expand Up @@ -502,7 +504,7 @@ public static <T> T convert(String value, Class<T> toType) {
switch (targetKind) {

case NULL:
throw U.notExpected();
throw Err.notExpected();

case BOOLEAN:
case BOOLEAN_OBJ:
Expand Down Expand Up @@ -559,7 +561,7 @@ public static <T> T convert(String value, Class<T> toType) {
return (T) UUID.fromString(value);

default:
throw U.notExpected();
throw Err.notExpected();
}
}

Expand Down Expand Up @@ -588,7 +590,7 @@ public static <T> T convert(Object value, Class<T> toType) {
switch (targetKind) {

case NULL:
throw U.notExpected();
throw Err.notExpected();

case BOOLEAN:
case BOOLEAN_OBJ:
Expand Down Expand Up @@ -678,7 +680,7 @@ public static <T> T convert(Object value, Class<T> toType) {
}

default:
throw U.notExpected();
throw Err.notExpected();
}
}

Expand Down Expand Up @@ -791,7 +793,7 @@ public static <T> T newInstance(Class<T> clazz) {
} else if (clazz == Map.class) {
return (T) U.map();
} else if (clazz == ConcurrentMap.class) {
return (T) U.concurrentMap();
return (T) Coll.concurrentMap();
} else if (clazz == Var.class) {
return (T) Vars.var("<new>", null);
} else if (clazz == Object.class) {
Expand Down
Expand Up @@ -40,7 +40,7 @@ public static boolean contains(Object arrOrColl, Object value) {
Collection<?> coll = (Collection<?>) arrOrColl;
return coll.contains(value);
} else {
throw U.illegalArg("Expected array or collection, but found: %s", U.str(arrOrColl));
throw Err.illegalArg("Expected array or collection, but found: %s", U.str(arrOrColl));
}
}

Expand All @@ -56,7 +56,7 @@ public static Object include(Object arrOrColl, Object item) {
}
return coll;
} else {
throw U.illegalArg("Expected array or collection!");
throw Err.illegalArg("Expected array or collection!");
}
}

Expand All @@ -73,7 +73,7 @@ public static Object exclude(Object arrOrColl, Object item) {
}
return coll;
} else {
throw U.illegalArg("Expected array or collection!");
throw Err.illegalArg("Expected array or collection!");
}
}

Expand Down

0 comments on commit 9073f5d

Please sign in to comment.