List of usage examples for java.lang NullPointerException NullPointerException
public NullPointerException(String s)
From source file:Main.java
/** * Checks whether or not the specified collection contains a <code>null</code>. * * @param col// w ww. ja v a2 s .c om * the collection to check * @throws NullPointerException * if the specified collection contains a null */ public static void checkCollectionForNulls(Collection<?> col) { for (Object entry : col) { if (entry == null) { throw new NullPointerException("collection contains a null entry"); } } }
From source file:Main.java
private static void checkNotNull(Object reference, String name) { if (reference == null) throw new NullPointerException(name + " is null"); }
From source file:Main.java
public static void checkNotNull(Object object, String msg) { if (object == null) { throw new NullPointerException(msg); }/* w w w . ja v a 2 s.c o m*/ }
From source file:Main.java
static NullPointerException arrayOfValuesToLookForIsNull() { return new NullPointerException("The array of values to look for should not be null"); }
From source file:Main.java
/*** * Computes RFC 2104-compliant HMAC signature. This can be used to sign the Amazon S3 * request urls// w w w .j a va 2 s. co m * * @param data The data to be signed. * @param key The signing key. * @return The Base64-encoded RFC 2104-compliant HMAC signature. * @throws SignatureException when signature generation fails */ public static String getHMac(String data, String key) throws SignatureException { if (data == null) { throw new NullPointerException("Data to be signed cannot be null"); } String result = null; try { final String HMAC_SHA1_ALGORITHM = "HmacSHA1"; // get an hmac_sha1 key from the raw key bytes SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM); // get an hmac_sha1 Mac instance & // initialize with the signing key Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); mac.init(signingKey); // compute the hmac on input data bytes byte[] digest = mac.doFinal(data.getBytes()); if (digest != null) { // Base 64 Encode the results result = Base64.encodeToString(digest, Base64.NO_WRAP); } } catch (Exception e) { throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } return result; }
From source file:Main.java
public static void checkNotNull(Object reference, String name) { if (reference == null) { throw new NullPointerException( String.format("Please set the %1$s constant and recompile the app.", name)); }/*w ww . j av a 2 s . co m*/ }
From source file:Main.java
/** * Returns the child element with the specified tagName for the specified * parent element.//from w w w . java 2s. co m * @param parent The parent whose child we're looking for. * @param tagName the name of the child to find * @return The child with the specified name or null if no such child was * found. * @throws NullPointerException if parent or tagName are null */ public static Element findChild(Element parent, String tagName) { if (parent == null || tagName == null) throw new NullPointerException( "Parent or tagname were null! " + "parent = " + parent + "; tagName = " + tagName); NodeList nodes = parent.getChildNodes(); Node node; int len = nodes.getLength(); for (int i = 0; i < len; i++) { node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && ((Element) node).getNodeName().equals(tagName)) return (Element) node; } return null; }
From source file:Main.java
/** * Returns a token string from a collection. Uses {@code Object#toString()} * to get the collection elements strings. * * @param collection collection * @param delimiter delimiter * @param delimiterReplacement replacement for all delimiters contained in * a collection's element * @return token string *//*from w w w . j av a 2s. com*/ public static String toTokenString(Collection<? extends Object> collection, String delimiter, String delimiterReplacement) { if (collection == null) { throw new NullPointerException("collection == null"); } if (delimiter == null) { throw new NullPointerException("delimiter == null"); } if (delimiterReplacement == null) { throw new NullPointerException("delimiterReplacement == null"); } StringBuilder tokenString = new StringBuilder(); int index = 0; for (Object o : collection) { tokenString.append(((index == 0) ? EMPTY_STRING : delimiter)); tokenString.append(o.toString().replace(delimiter, delimiterReplacement)); index++; } return tokenString.toString(); }
From source file:Main.java
/** * Returns the children elements with the specified tagName for the * specified parent element.//from w w w. java 2s.co m * * @param parent The parent whose children we're looking for. * @param tagName the name of the child to find * @return List of the children with the specified name * @throws NullPointerException if parent or tagName are null */ public static List<Element> findChildren(Element parent, String tagName) { if (parent == null || tagName == null) throw new NullPointerException( "Parent or tagname were null! " + "parent = " + parent + "; tagName = " + tagName); List<Element> result = new ArrayList<Element>(); NodeList nodes = parent.getChildNodes(); Node node; int len = nodes.getLength(); for (int i = 0; i < len; i++) { node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.getNodeName().equals(tagName)) result.add(element); } } return result; }
From source file:Main.java
/** * Remove identical adjacent tags from {@code decorations}. * /*from w w w . j a v a2 s.c o m*/ * @param decorations see {@link prettify.parser.Job#decorations} * @param source the source code * * @return the {@code decorations} after treatment * * @throws IllegalArgumentException the size of {@code decoration} is not * a multiple of 2 */ public static List<Object> removeDuplicates(List<Object> decorations, String source) { if (decorations == null) { throw new NullPointerException("argument 'decorations' cannot be null"); } if (source == null) { throw new NullPointerException("argument 'source' cannot be null"); } if ((decorations.size() & 0x1) != 0) { throw new IllegalArgumentException("the size of argument 'decorations' should be a multiple of 2"); } List<Object> returnList = new ArrayList<Object>(); // use TreeMap to remove entrys with same pos Map<Integer, Object> orderedMap = new TreeMap<Integer, Object>(); for (int i = 0, iEnd = decorations.size(); i < iEnd; i += 2) { orderedMap.put((Integer) decorations.get(i), decorations.get(i + 1)); } // remove adjacent style String previousStyle = null; for (Integer pos : orderedMap.keySet()) { String style = (String) orderedMap.get(pos); if (previousStyle != null && previousStyle.equals(style)) { continue; } returnList.add(pos); returnList.add(style); previousStyle = style; } // remove last zero length tag int returnListSize = returnList.size(); if (returnListSize >= 4 && returnList.get(returnListSize - 2).equals(source.length())) { returnList.remove(returnListSize - 2); returnList.remove(returnListSize - 2); } return returnList; }