List of usage examples for java.lang NullPointerException NullPointerException
public NullPointerException(String s)
From source file:Main.java
/** * Creates and returns an unmodifiable List that wraps the given array. * Changes to the array will be reflected in the List. * @param arr The array to wrap as a List * @return an unmodifiable List that wraps the array * @throws NullPointerException if the array is null *///w w w. ja va2 s . co m public static List<Float> listFromFloatArray(final float[] arr) { if (arr == null) throw new NullPointerException("array cannot be null"); return new AbstractList<Float>() { @Override public Float get(int index) { return arr[index]; } @Override public int size() { return arr.length; } }; }
From source file:Main.java
/** * Returns a List of all child Elements of the given Element. * * @param element the element from which to retrieve child elements * @return a List of child Elements./* w w w. java 2 s.c o m*/ * @throws NullPointerException if the element is null. */ public static List getChildElements(Element element) { if (element == null) throw new NullPointerException("Tried to get child elements on a null element"); List result = new ArrayList(); NodeList children = element.getChildNodes(); for (int i = 0; i != children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { result.add(children.item(i)); } } return result; }
From source file:Main.java
public static <K, V> Map<K, V> copyNullSafeMutableHashMapWithNullValues(Map<? extends K, ? extends V> map) { if (map == null) throw new NullPointerException("map"); Map<K, V> result = new HashMap<K, V>(map); for (Map.Entry<K, V> entry : result.entrySet()) { if (entry.getKey() == null) throw new NullPointerException("entry.getKey()"); }// w w w .j a va 2 s .c om return result; }
From source file:Main.java
/** * Treat a variable as an integer in JavaScript style. Note this function can * only handle integer and boolean currently. * * @param var the variable to get value from * @return the integer value/*from w ww.j ava 2s. com*/ * @throws IllegalArgumentException the data type of {@code var} is neither * integer nor boolean. */ public static Integer getVariableValueAsInteger(Object var) { if (var == null) { throw new NullPointerException("argument 'var' cannot be null"); } Integer returnResult = -1; if (var instanceof Integer) { returnResult = (Integer) var; } else if (var instanceof Boolean) { // Javascript treat true as 1 returnResult = (Boolean) var ? 1 : 0; } else { throw new IllegalArgumentException("'var' is neither integer nor boolean"); } return returnResult; }
From source file:Main.java
public static String generateKey(Object... objects) { Object[] args = objects;/*w w w.j a v a 2 s .co m*/ if (args == null) { throw new NullPointerException("Cannot generate key with no params!"); } StringBuilder stringBuilder = new StringBuilder(); for (Object o : args) { if (o != null) { if (o instanceof String) { stringBuilder.append(o); stringBuilder.append("_"); } else { String json = gson.toJson(o); stringBuilder.append(json); stringBuilder.append("_"); } } } return Base64.encodeToString(stringBuilder.toString().getBytes(), Base64.DEFAULT); }
From source file:Main.java
public static File getFile(String[] names) { if (names == null) { throw new NullPointerException("names must not be null"); }//from ww w .j a v a 2 s .c o m File file = null; for (String name : names) { if (file == null) file = new File(name); else { file = new File(file, name); } } return file; }
From source file:Main.java
/** * Returns all elements of a specific class from a container. * * <em>Only elements of that class are detected, not sub- and supertyes!</em> * * @param <T> class type//w w w .j a va 2 s .c o m * @param container container * @param clazz class * @return found elements or empty list */ public static <T> List<T> getAllOf(Container container, Class<T> clazz) { if (container == null) { throw new NullPointerException("container == null"); } if (clazz == null) { throw new NullPointerException("clazz == null"); } List<T> components = new ArrayList<>(); addAllOf(container, clazz, components); return components; }
From source file:Main.java
/** * Gets a string list based on an iterator. * <p>// w w w.j a va 2 s . c om * As the wrapped Iterator is traversed, an LinkedList of its string values is * created. At the end, the list is returned. * * @param iterator the iterator to use, not null * @return a list of the iterator string contents * @throws NullPointerException if iterator parameter is null */ public static List<String> toStringList(Iterator<?> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } List<String> list = new LinkedList<String>(); while (iterator.hasNext()) { list.add(String.valueOf(iterator.next())); } return list; }
From source file:Main.java
public static byte[] decodeYUV420SP2RGB(byte[] yuv420sp, int width, int height) { final int frameSize = width * height; byte[] rgbBuf = new byte[frameSize * 3]; // if (rgbBuf == null) throw new NullPointerException("buffer 'rgbBuf' is null"); if (rgbBuf.length < frameSize * 3) throw new IllegalArgumentException( "buffer 'rgbBuf' size " + rgbBuf.length + " < minimum " + frameSize * 3); if (yuv420sp == null) throw new NullPointerException("buffer 'yuv420sp' is null"); if (yuv420sp.length < frameSize * 3 / 2) throw new IllegalArgumentException( "buffer 'yuv420sp' size " + yuv420sp.length + " < minimum " + frameSize * 3 / 2); int i = 0, y = 0; int uvp = 0, u = 0, v = 0; int y1192 = 0, r = 0, g = 0, b = 0; for (int j = 0, yp = 0; j < height; j++) { uvp = frameSize + (j >> 1) * width; u = 0;//from w ww . j a v a2 s .c o m v = 0; for (i = 0; i < width; i++, yp++) { y = (0xff & ((int) yuv420sp[yp])) - 16; if (y < 0) y = 0; if ((i & 1) == 0) { v = (0xff & yuv420sp[uvp++]) - 128; u = (0xff & yuv420sp[uvp++]) - 128; } y1192 = 1192 * y; r = (y1192 + 1634 * v); g = (y1192 - 833 * v - 400 * u); b = (y1192 + 2066 * u); if (r < 0) r = 0; else if (r > 262143) r = 262143; if (g < 0) g = 0; else if (g > 262143) g = 262143; if (b < 0) b = 0; else if (b > 262143) b = 262143; rgbBuf[yp * 3] = (byte) (r >> 10); rgbBuf[yp * 3 + 1] = (byte) (g >> 10); rgbBuf[yp * 3 + 2] = (byte) (b >> 10); } } // for return rgbBuf; }
From source file:Main.java
public static NodeList findNodes(Element parentNode, String nodeName) { if (parentNode == null) throw new NullPointerException("Parent Node cannot be null!"); if (nodeName == null) throw new NullPointerException("Nodename cannot be null!"); return parentNode.getElementsByTagName(nodeName); }