List of usage examples for java.lang IllegalArgumentException IllegalArgumentException
public IllegalArgumentException(Throwable cause)
From source file:Main.java
/** * @author TheMrMilchmann// ww w.ja v a 2 s . c om * @since DerpieLang v1.0.0 */ @SuppressWarnings("unchecked") public static final <K, V, OK> HashMap<K, V> transform(Map<OK, ?> toTransform) throws IllegalArgumentException { HashMap<K, V> map = new HashMap<K, V>(); try { for (Object key : toTransform.keySet()) { map.put((K) key, (V) toTransform.get((OK) key)); } return map; } catch (Throwable t) { throw new IllegalArgumentException(t); } }
From source file:Main.java
public static <ENUM extends Enum> ENUM fromValue(Class<ENUM> aClass, String value) { try {//from w ww .ja v a2s. c o m for (ENUM c : aClass.getEnumConstants()) { Field field = aClass.getField(c.name()); XmlEnumValue annotation = field.getAnnotation(XmlEnumValue.class); if (annotation.value().equals(value)) { return c; } } } catch (NoSuchFieldException e) { } throw new IllegalArgumentException(value); }
From source file:Main.java
public static int inetAddressToInt(InetAddress inetaddress) throws IllegalArgumentException { byte[] abyte0 = inetaddress.getAddress(); if (abyte0.length == 4) { return ((((abyte0[3] & MotionEventCompat.ACTION_MASK) << 24) | ((abyte0[2] & MotionEventCompat.ACTION_MASK) << 16)) | ((abyte0[1] & MotionEventCompat.ACTION_MASK) << 8)) | (abyte0[0] & MotionEventCompat.ACTION_MASK); }/*from w w w . j a va 2 s . c o m*/ throw new IllegalArgumentException("Not an IPv4 address"); }
From source file:eumetsat.pn.common.util.MimeUtil.java
/** * Get Mime type from a Filename//from www . ja v a2 s. c o m * * @param aFilename * @return Mime type as a String */ static final public String getMimeType(String aFilename) { String mime; if (aFilename == null) { throw new IllegalArgumentException("aFilename is null"); } String extension = FilenameUtils.getExtension(aFilename); if (extension.equalsIgnoreCase("css")) { mime = "text/css"; } else if (extension.equalsIgnoreCase("js")) { mime = "text/javascript"; } else if (extension.equalsIgnoreCase("ico")) { mime = "image/x-icon"; } else if (extension.equalsIgnoreCase(".svg")) { mime = "image/svg+xml"; } else { mime = "application/octet-stream"; } return mime; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> Map<T, Object> asMap(T key, Object... values) { if ((values == null || values.length == 0) && key instanceof Map) { return (Map<T, Object>) key; }/*ww w . ja va2 s . com*/ Map<T, Object> result = new LinkedHashMap<>(); if (values == null) { result.put(key, null); return result; } if (values.length % 2 == 0) { throw new IllegalArgumentException("value[] must be not null and an odd length"); } result.put(key, values[0]); for (int i = 1; i < values.length; i += 2) { result.put((T) values[i], values[i + 1]); } return result; }
From source file:Main.java
public static String getQETAG(String path) { byte[] SHA1Byte; try {/* ww w . ja v a 2 s . com*/ SHA1Byte = getFileSHA1(path); } catch (IOException e) { e.printStackTrace(); return null; } if (null == SHA1Byte) { throw new IllegalArgumentException("SHA1 must not be empty!"); } if (SHA1Byte.length != 20) { throw new IllegalArgumentException("SHA1 length must be 20! Current length:" + SHA1Byte.length); } byte[] QETAGByte = new byte[21]; QETAGByte[0] = 0x16; System.arraycopy(SHA1Byte, 0, QETAGByte, 1, 20); return Base64.encodeToString(QETAGByte, Base64.URL_SAFE | Base64.NO_WRAP); }
From source file:Main.java
/** * Returns new byte buffer whose content is a shared subsequence of this buffer's content * between the specified start (inclusive) and end (exclusive) positions. As opposed to * {@link ByteBuffer#slice()}, the returned buffer's byte order is the same as the source * buffer's byte order.//from w ww.j a v a 2s. co m */ private static ByteBuffer sliceFromTo(final ByteBuffer source, final int start, final int end) { if (start < 0) { throw new IllegalArgumentException("start: " + start); } if (end < start) { throw new IllegalArgumentException("end < start: " + end + " < " + start); } final int capacity = source.capacity(); if (end > source.capacity()) { throw new IllegalArgumentException("end > capacity: " + end + " > " + capacity); } final int originalLimit = source.limit(); final int originalPosition = source.position(); try { source.position(0); source.limit(end); source.position(start); final ByteBuffer result = source.slice(); result.order(source.order()); return result; } finally { source.position(0); source.limit(originalLimit); source.position(originalPosition); } }
From source file:Main.java
/** * Returns a sorted array of middle terms of the reduction polynomial. * @param k The unsorted array of middle terms of the reduction polynomial * of length 1 or 3.//ww w .j a v a 2 s .com * @return the sorted array of middle terms of the reduction polynomial. * This array always has length 3. */ static int[] convertMidTerms(int[] k) { int[] res = new int[3]; if (k.length == 1) { res[0] = k[0]; } else { if (k.length != 3) { throw new IllegalArgumentException("Only Trinomials and pentanomials supported"); } if (k[0] < k[1] && k[0] < k[2]) { res[0] = k[0]; if (k[1] < k[2]) { res[1] = k[1]; res[2] = k[2]; } else { res[1] = k[2]; res[2] = k[1]; } } else if (k[1] < k[2]) { res[0] = k[1]; if (k[0] < k[2]) { res[1] = k[0]; res[2] = k[2]; } else { res[1] = k[2]; res[2] = k[0]; } } else { res[0] = k[2]; if (k[0] < k[1]) { res[1] = k[0]; res[2] = k[1]; } else { res[1] = k[1]; res[2] = k[0]; } } } return res; }
From source file:com.enonic.cms.core.content.binary.AttachmentNativeLinkKeyParser.java
public static AttachmentNativeLinkKey parse(Path path) throws InvalidAttachmentNativeLinkKeyException { if (path == null) { throw new IllegalArgumentException("Given path cannot be null"); }// w w w . j a va 2 s. c o m List<String> pathElements = path.getPathElements(); if (pathElements.size() == 0) { throw new InvalidAttachmentNativeLinkKeyException(path.getPathAsString(), "Path is empty"); } final String firstPathElement = pathElements.get(0); final ContentKey contentKey = parseContentKey(firstPathElement); if (pathElements.size() == 1) { // handling: <contentkey>* String extension = parseExtension(firstPathElement); //AttachmentNativeLinkKey linkKey = new AttachmentNativeLinkKeyWithLabel( contentKey, "source" ); AttachmentNativeLinkKey linkKey = new AttachmentNativeLinkKey(contentKey); if (extension != null) { linkKey.setExtension(extension); } return linkKey; } final String secondPathElement = pathElements.get(1); final boolean hasLabelPathElement = secondPathElement.equals("label"); final boolean hasBinaryPathElement = secondPathElement.equals("binary"); if (hasLabelPathElement) { // handling: <contentkey>*/label/<label> return parseWithLabel(pathElements, contentKey, path); } else if (hasBinaryPathElement) { // handling: <contentkey>*/binary/<binarydatakey> return parseWithBinaryDataKey(pathElements, contentKey, path); } throw new InvalidAttachmentNativeLinkKeyException(path.getPathAsString(), "Unknown format"); }
From source file:Main.java
public static Element getChildElement(Element parent, String name, boolean strict) { List<Element> childElements = getChildElements(parent, name); if (strict && childElements.size() != 1) { throw new IllegalArgumentException("parent must contain exactly one element with the given name"); }/*from w w w. ja v a 2 s .c o m*/ return childElements.isEmpty() ? null : childElements.get(0); }