fixes:
- Return null NPE in selectFirst() if list is empty (pr-5)
- Fix Moxie toolkit download URL (pr-6)
+ - Be more careful with primitive numeric type rollovers
changes: ~
additions:
- Add syntax for IN and NOT IN (pr-7)
- Add support for nested AND/OR conditions (pr-8)
dependencyChanges: ~
contributors:
+ - James Moger
- Kazunobu Raita
- Sotaro Suzuki
}
public class Utils {\r
\r
public static final AtomicLong COUNTER = new AtomicLong(0);\r
- \r
+\r
public static final AtomicInteger AS_COUNTER = new AtomicInteger(0);\r
\r
private static final boolean MAKE_ACCESSIBLE = true;\r
\r
private static final int BUFFER_BLOCK_SIZE = 4 * 1024;\r
- \r
+\r
public static synchronized int nextAsCount() {\r
// prevent negative values and use a threadsafe counter\r
int count = AS_COUNTER.incrementAndGet();\r
if (count == Integer.MAX_VALUE) {\r
count = 0;\r
- AS_COUNTER.set(count); \r
+ AS_COUNTER.set(count);\r
}\r
return count;\r
}\r
public static <T> T newObject(Class<T> clazz) {\r
// must create new instances\r
if (clazz == int.class || clazz == Integer.class) {\r
- return (T) new Integer((int) COUNTER.getAndIncrement());\r
+ return (T) new Integer((int) (COUNTER.getAndIncrement() % Integer.MAX_VALUE));\r
} else if (clazz == String.class) {\r
return (T) ("" + COUNTER.getAndIncrement());\r
} else if (clazz == long.class || clazz == Long.class) {\r
return (T) new Long(COUNTER.getAndIncrement());\r
} else if (clazz == short.class || clazz == Short.class) {\r
- return (T) new Short((short) COUNTER.getAndIncrement());\r
+ return (T) new Short((short) (COUNTER.getAndIncrement() % Short.MAX_VALUE));\r
} else if (clazz == byte.class || clazz == Byte.class) {\r
- return (T) new Byte((byte) COUNTER.getAndIncrement());\r
+ return (T) new Byte((byte) (COUNTER.getAndIncrement() % Byte.MAX_VALUE));\r
} else if (clazz == float.class || clazz == Float.class) {\r
return (T) new Float(COUNTER.getAndIncrement());\r
} else if (clazz == double.class || clazz == Double.class) {\r
\r
/**\r
* Read a number of characters from a reader and close it.\r
- * \r
+ *\r
* @param in\r
* the reader\r
* @param length\r
\r
/**\r
* Read a number of bytes from a stream and close it.\r
- * \r
+ *\r
* @param in\r
* the stream\r
* @param length\r