List of usage examples for java.lang IllegalArgumentException IllegalArgumentException
public IllegalArgumentException(Throwable cause)
From source file:Main.java
public static Window getOwnerWindow(Component component) { if (component instanceof Window) { return (Window) component; }/*ww w.j av a 2 s. co m*/ Container parent = component.getParent(); while (!(parent instanceof Window)) { parent = parent.getParent(); if (parent == null) { throw new IllegalArgumentException("Component has no root window."); } } return (Window) parent; }
From source file:Main.java
public static void assertRequiredArgs(Object[] methodArgs, int requiredArgs, String methodName) throws IllegalArgumentException { if (methodArgs == null) { throw new IllegalArgumentException( String.format("Expected %d arguments for %s, got 0", requiredArgs, methodName)); } else if (methodArgs.length < requiredArgs) { throw new IllegalArgumentException(String.format("Expected %d arguments for %s, got %d", requiredArgs, methodName, methodArgs.length)); }/*from w w w.j av a 2 s. c o m*/ }
From source file:Main.java
public static int[] generateCompactWindowNaf(int width, BigInteger k) { if (width == 2) { return generateCompactNaf(k); }//from w w w .j a v a2 s .com if (width < 2 || width > 16) { throw new IllegalArgumentException("'width' must be in the range [2, 16]"); } if ((k.bitLength() >>> 16) != 0) { throw new IllegalArgumentException("'k' must have bitlength < 2^16"); } if (k.signum() == 0) { return EMPTY_INTS; } int[] wnaf = new int[k.bitLength() / width + 1]; // 2^width and a mask and sign bit set accordingly int pow2 = 1 << width; int mask = pow2 - 1; int sign = pow2 >>> 1; boolean carry = false; int length = 0, pos = 0; while (pos <= k.bitLength()) { if (k.testBit(pos) == carry) { ++pos; continue; } k = k.shiftRight(pos); int digit = k.intValue() & mask; if (carry) { ++digit; } carry = (digit & sign) != 0; if (carry) { digit -= pow2; } int zeroes = length > 0 ? pos - 1 : pos; wnaf[length++] = (digit << 16) | zeroes; pos = width; } // Reduce the WNAF array to its actual length if (wnaf.length > length) { wnaf = trim(wnaf, length); } return wnaf; }
From source file:Main.java
public static int ulongToInt(long value) { if (value <= MAX_UNSIGNED_INT_VALUE) { if (value >= MAX_UNSIGNED_INT_VALUE / 2) { return (int) (~(MAX_UNSIGNED_INT_VALUE - value) + 1); } else {// w w w .j a v a2s. com return (int) value; } } else { throw new IllegalArgumentException("Value out of range for a int"); } }
From source file:Main.java
public static String decode(final String content, final String encoding) { try {/*from ww w . j a va2 s .co m*/ return URLDecoder.decode(content, encoding != null ? encoding : DEFAULT_CONTENT_CHARSET); } catch (UnsupportedEncodingException problem) { throw new IllegalArgumentException(problem); } }
From source file:Main.java
public static Date readDate(StringReader reader, char delimiter) throws ParseException { String date = readString(reader, ','); try {/*from w ww .ja va2 s . com*/ return new SimpleDateFormat("H.mm").parse(date); } catch (ParseException e) { throw new IllegalArgumentException( "Malformed Compressed Market Data: Could not parse the date from " + date); } }
From source file:Main.java
/** * This method converts the hours in milliseconds.<br> * @param hours {@link Integer} to convert in milliseconds. * @return {@link Long} number representing the milliseconds of hours given. * @throws IllegalArgumentException {@link Exception} if argument given is less of zero. *///from w ww . ja v a 2s . c o m public static long getMillisecondFromHours(int hours) throws IllegalArgumentException { if (hours < 0) throw new IllegalArgumentException("Hours given can not be less of zero."); return hours * 1000 * 60 * 60; }
From source file:Main.java
public static byte[] genRandomBytes(int len) { if (len <= 0) { throw new IllegalArgumentException("Length must > 0: " + len); }// w w w .j a v a 2s . c o m byte[] ret = new byte[len]; for (int i = 0; i < ret.length; i++) { ret[i] = (byte) random.nextInt(256); } return ret; }
From source file:Main.java
public static int getInFormat(int inChannels) { switch (inChannels) { case 1://from ww w . ja v a2 s . co m return AudioFormat.CHANNEL_IN_MONO; case 2: return AudioFormat.CHANNEL_IN_STEREO; default: throw new IllegalArgumentException("illegal number of input channels: " + inChannels); } }
From source file:Main.java
public static Date getFormattedDate(String dateString) { try {//from www.ja va2s .c om return dateFormat.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } throw new IllegalArgumentException("Invalid date string " + dateString); }