List of usage examples for java.lang IllegalArgumentException IllegalArgumentException
public IllegalArgumentException(Throwable cause)
From source file:Main.java
public static <T> T getSingle(List<T> collection) { checkIsNull(collection);/*from ww w.ja va2s .co m*/ if (collection.size() != 1) { throw new IllegalArgumentException("The supplied collection must contain exactly one item."); } return getFirst(collection); }
From source file:Main.java
public static void setViewInvisible(View view) { if (view != null) { view.setVisibility(View.INVISIBLE); } else {// www .j a va2 s .co m throw new IllegalArgumentException("A view is null in your parameter."); } }
From source file:Main.java
public static final int parseIPAddress(String address) { if (TextUtils.isEmpty(address)) throw new IllegalArgumentException("address cannot be null or empty"); String[] tokens = address.split("\\."); boolean isOk = true; int ip = 0;//from w w w . j av a 2 s .co m if (tokens.length == 4) { for (int i = 0; i < 4; i++) { try { short num = Short.parseShort(tokens[i]); if (num < 0 || num > 255) { isOk = false; break; } ip |= (num << (8 * i)); } catch (NumberFormatException ex) { isOk = false; break; } } } else isOk = false; if (!isOk) throw new IllegalArgumentException("address is not in the form X.X.X.X, with X in the range 0-255"); return ip; }
From source file:Main.java
public static String getNumberRadim(int n) { if (n < 1 || n > 10) { throw new IllegalArgumentException("cannot random " + n + " bit number"); }/*from w w w . j ava 2 s . c o m*/ Random ran = new Random(); if (n == 1) { return String.valueOf(ran.nextInt(10)); } int bitField = 0; char[] chs = new char[n]; for (int i = 0; i < n; i++) { while (true) { int k = ran.nextInt(10); if ((bitField & (1 << k)) == 0) { bitField |= 1 << k; chs[i] = (char) (k + '0'); break; } } } return new String(chs); }
From source file:Main.java
public static void checkKeyEventId(int id) { if (id != KeyEvent.KEY_TYPED && id != KeyEvent.KEY_PRESSED && id != KeyEvent.KEY_RELEASED) { throw new IllegalArgumentException("Invalid key event id"); }//from ww w .ja va2 s .co m }
From source file:Main.java
public static void objectCopy(Object from, Object to) throws Exception { if (from.getClass() != to.getClass()) { throw new IllegalArgumentException("[objectCopy]The left and right must be same class"); }/*from w ww. ja v a 2 s .c om*/ Class<?> clz = from.getClass(); Field[] fs = clz.getDeclaredFields(); for (int i = 0; i < fs.length; i++) { Field field = fs[i]; field.setAccessible(true); Object value = field.get(from); field.set(to, value); } }
From source file:Main.java
public static <T> T[] subArray(T[] x, int start, int len) { if (start + len > x.length) throw new IllegalArgumentException("length + start > x.length"); T[] out = null;/*from w ww .jav a 2 s . c om*/ try { out = (T[]) Array.newInstance(x.getClass().getComponentType(), len); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } System.arraycopy(x, start, out, 0, len); return out; }
From source file:Main.java
public static void mergePropertiesIntoMap(Properties props, Map map) { if (map == null) { throw new IllegalArgumentException("Map must not be null"); } else {/* w w w . ja v a 2s . c o m*/ if (props != null) { Enumeration en = props.propertyNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); map.put(key, props.getProperty(key)); } } } }
From source file:Main.java
public final static <T> void add(ArrayList<T> origin, ArrayList<T> list) { if (origin == null) { throw new IllegalArgumentException(""); }//from w w w . j a v a 2s . c om if (list == null || list.size() == 0) { return; } origin.addAll(list); }
From source file:Main.java
public static Point toPoint(Node n) { if (!n.getNodeName().equals("center")) { throw new IllegalArgumentException(n.getNodeName()); }/*from w w w .j ava 2s.com*/ NamedNodeMap map = n.getAttributes(); int x = Integer.parseInt(map.getNamedItem("x").getNodeValue()); int y = Integer.parseInt(map.getNamedItem("y").getNodeValue()); return new Point(x, y); }