List of usage examples for java.lang IllegalArgumentException IllegalArgumentException
public IllegalArgumentException(Throwable cause)
From source file:Main.java
public static Date parseSqliteFormattedDateTime(String sqliteFormattedDateTime) throws IllegalArgumentException { try {/*ww w . j a v a 2 s.c o m*/ return DateFormat.getInstance().parse(sqliteFormattedDateTime); } catch (ParseException e) { throw new IllegalArgumentException("Unrecognized date-time format: " + sqliteFormattedDateTime); } }
From source file:Main.java
public static String getProjectByUrl(String url) { Pattern pattern = Pattern.compile("https://(\\p{Ll}+).(.*)", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(url); if (!matcher.matches()) throw new IllegalArgumentException("Regex fail. not matched. Url: " + url); return matcher.group(1); }
From source file:Main.java
public static ExecutorService newFixedThreadPool(int threadSize) { if (threadSize <= 0) { throw new IllegalArgumentException("ThreadSize must be greater than 0!"); }// w w w.j av a 2s . co m if (threadSize == 1) { return MoreExecutors.sameThreadExecutor(); } return new ThreadPoolExecutor(threadSize - 1, threadSize - 1, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:Main.java
/** * Validate given argument isn't null.//from w ww.ja v a 2 s.c o m * * @param arg argument to validate * @param argName name of the argument to show in error message * @throws IllegalArgumentException */ public static void notNull(Object arg, String argName) { if (arg == null) { throw new IllegalArgumentException("argument is null: " + argName); } }
From source file:Main.java
public static String filterOutSoapHeader(String xml) { int start = xml.indexOf("<soap:Header>"); if (start < 0) { return xml; }/* w w w .ja v a 2 s.co m*/ int end = xml.indexOf("</soap:Header>"); if (end < 0) { throw new IllegalArgumentException("Close tag for SOAP header not presented"); } String part1 = xml.substring(0, start); String part2 = xml.substring(end + "</soap:Header>".length()); return part1 + part2; }
From source file:Main.java
public static int[] generateCompactWindowNaf(int width, BigInteger k) { if (width == 2) { return generateCompactNaf(k); }/*from w w w. ja va 2s . c o m*/ 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"); } 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
@SuppressWarnings("unchecked") public static <K, V> Map<K, V> castMap(Object obj) { if (obj == null) { return new HashMap<>(); }//from ww w . j a v a 2 s. co m if (obj instanceof Map) { return (Map<K, V>) obj; } else { throw new IllegalArgumentException("Expected [" + obj + "] to be a Map"); } }
From source file:Main.java
@SuppressWarnings("unchecked") public static <K, V> Map<K, V> castMap(Object obj) { if (obj == null) { return new HashMap<K, V>(); }/*from ww w .j a va 2 s .c om*/ if (obj instanceof Map) { return (Map<K, V>) obj; } else { throw new IllegalArgumentException("Expected [" + obj + "] to be a Map"); } }
From source file:Main.java
public static Rect getLocationInView(View parent, View child) { if (child == null || parent == null) { throw new IllegalArgumentException("parent and child can not be null ."); }/*from w w w. j a v a2s .co m*/ View decorView = null; Context context = child.getContext(); if (context instanceof Activity) { decorView = ((Activity) context).getWindow().getDecorView(); } Rect result = new Rect(); Rect tmpRect = new Rect(); View tmp = child; if (child == parent) { child.getHitRect(result); return result; } while (tmp != decorView && tmp != parent) { tmp.getHitRect(tmpRect); if (!tmp.getClass().equals(FRAGMENT_CON)) { result.left += tmpRect.left; result.top += tmpRect.top; } tmp = (View) tmp.getParent(); } result.right = result.left + child.getMeasuredWidth(); result.bottom = result.top + child.getMeasuredHeight(); return result; }
From source file:Main.java
/** * @return the child element, throws exception if the parent does not * have exactly one sub element with name *///w w w . j av a 2 s . co m public static Element getSingleSubElement(Element parentElement, String name) { NodeList nodes = parentElement.getElementsByTagName(name); if (nodes.getLength() != 1) { throw new IllegalArgumentException("Expected the element " + parentElement.getNodeName() + " to have one child called " + name + " but found " + nodes.getLength()); } return (Element) nodes.item(0); }