List of usage examples for java.lang IllegalArgumentException IllegalArgumentException
public IllegalArgumentException()
IllegalArgumentException
with no detail message. From source file:Main.java
public static int prevPowerOf2(int n) { if (n <= 0) throw new IllegalArgumentException(); return Integer.highestOneBit(n); }
From source file:Main.java
private static int prevPowerOf2(int n) { if (n <= 0) { throw new IllegalArgumentException(); }//ww w . j a v a 2s . co m return Integer.highestOneBit(n); }
From source file:Main.java
public static void require(boolean requirement) { if (!requirement) throw new IllegalArgumentException(); }
From source file:Main.java
public static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); long factor = (long) Math.pow(10, places); value = value * factor;/*from w ww. j a v a2 s . com*/ long tmp = Math.round(value); return (double) tmp / factor; }
From source file:Main.java
private static byte[] byte2hex(byte[] b) { if ((b.length % 2) != 0) throw new IllegalArgumentException(); byte[] b2 = new byte[b.length / 2]; for (int n = 0; n < b.length; n += 2) { String item = new String(b, n, 2); b2[n / 2] = (byte) Integer.parseInt(item, 16); }// w ww. j a v a 2 s . com return b2; }
From source file:Main.java
public static int nextPowerOf2(int n) { if (n <= 0 || n > (1 << 30)) throw new IllegalArgumentException(); n -= 1;/* w w w.j av a 2 s . c om*/ n |= n >> 16; n |= n >> 8; n |= n >> 4; n |= n >> 2; n |= n >> 1; return n + 1; }
From source file:Main.java
public static String toString(Iterable<?> iterable) { if (iterable == null) throw new IllegalArgumentException(); StringBuilder sb = new StringBuilder(); for (Object value : iterable) { if (sb.length() > 0) { sb.append(", "); }/*from w ww .j ava 2 s.com*/ sb.append(value); } return sb.toString(); }
From source file:Main.java
public static String getDayFromNumber(int day) { if (day < 0 || day > 30) throw new IllegalArgumentException(); if (day <= 10) return String.valueOf(Character.toChars(1487 + day)); else if ((day >= 11 && day <= 14) || (day >= 16 && day <= 19)) { char yod = Character.toChars(1497)[0]; return String.valueOf(new char[] { yod, Character.toChars(1487 + (day - 10))[0] }); } else if (day == 15 || day == 16) { char tet = Character.toChars(1498)[0]; return String.valueOf(new char[] { tet, Character.toChars(1487 + (day - 9))[0] }); } else if (day == 20) { return String.valueOf(Character.toChars(1499)[0]); } else if (day >= 21 && day <= 29) { char chaf = Character.toChars(1499)[0]; return String.valueOf(chaf + Character.toChars(1487 + (day - 20))[0]); } else {//from w ww.j a v a2 s . co m return String.valueOf(Character.toChars(1500)[0]); } }
From source file:Main.java
public static int prevPowerOf2(final int n) { if (n <= 0) { throw new IllegalArgumentException(); }/*from w ww . j a v a2s . c o m*/ return Integer.highestOneBit(n); }
From source file:Main.java
public static int[] remove(int[] array, int index) { if (array == null || array.length == 0) { throw new IllegalArgumentException(); }// w ww .jav a 2s . c o m if (index > array.length || index <= 0) { throw new IllegalArgumentException(); } int[] dest = new int[array.length - 1]; System.arraycopy(array, 0, dest, 0, index - 1); System.arraycopy(array, index, dest, index - 1, array.length - index); return dest; }