Utils { public static int abs(int n) { return (n == Integer.MIN_VALUE) ? 0 : Math.abs(n); }  static List<T> sorted(Collection<T> collection); static String utf8(byte[] bytes); static byte[] utf8(String string); static long readUnsignedInt(ByteBuffer buffer); static long readUnsignedInt(ByteBuffer buffer, int index); static int readUnsignedIntLE(InputStream in); static byte[] toArrayLE(int val); static int readUnsignedIntLE(byte[] buffer, int offset); static void writeUnsignedInt(ByteBuffer buffer, long value); static void writeUnsignedInt(ByteBuffer buffer, int index, long value); static void writeUnsignedIntLE(OutputStream out, int value); static void writeUnsignedIntLE(byte[] buffer, int offset, int value); static int abs(int n); static long min(long first, long ... rest); static int utf8Length(CharSequence s); static byte[] toArray(ByteBuffer buffer); static byte[] toArray(ByteBuffer buffer, int offset, int size); static T notNull(T t); static void sleep(long ms); static T newInstance(Class<T> c); static T newInstance(String klass, Class<T> base); static int murmur2(final byte[] data); static String getHost(String address); static Integer getPort(String address); static String formatAddress(String host, Integer port); static String join(T[] strs, String seperator); static String join(Collection<T> list, String seperator); static Properties loadProps(String filename); static Map<String, String> propsToStringMap(Properties props); static String stackTrace(Throwable e); static Thread newThread(String name, Runnable runnable, boolean daemon); static Thread daemonThread(String name, Runnable runnable); static void croak(String message); static byte[] readBytes(ByteBuffer buffer, int offset, int length); static byte[] readBytes(ByteBuffer buffer); static String readFileAsString(String path, Charset charset); static String readFileAsString(String path); static ByteBuffer ensureCapacity(ByteBuffer existingBuffer, int newLength); @SafeVarargs static Set<T> mkSet(T... elems); @SafeVarargs static List<T> mkList(T... elems); static CharSequence mkString(Collection<T> coll, String separator); static void delete(File file); static List<T> safe(List<T> other); static ClassLoader getKafkaClassLoader(); static ClassLoader getContextOrKafkaClassLoader(); static void atomicMoveWithFallback(Path source, Path target); static void closeAll(Closeable... closeables); static final String NL; }
@Test public void testAbs() { assertEquals(0, Utils.abs(Integer.MIN_VALUE)); assertEquals(10, Utils.abs(-10)); assertEquals(10, Utils.abs(10)); assertEquals(0, Utils.abs(0)); assertEquals(1, Utils.abs(-1)); }