Example usage for java.lang NullPointerException NullPointerException

List of usage examples for java.lang NullPointerException NullPointerException

Introduction

In this page you can find the example usage for java.lang NullPointerException NullPointerException.

Prototype

public NullPointerException() 

Source Link

Document

Constructs a NullPointerException with no detail message.

Usage

From source file:Main.java

/**
 * Calculates a value case insensitive hash code for a String v String map. Method placed here to
 * reduce .NET translation overhead/*w  w w.j av  a  2s. co m*/
 * @param map
 * @return
 */
public static int calculateCaseInsensitiveValueStringVsStringMapHash(Map<String, String> map) {
    if (map == null) {
        throw new NullPointerException();
    }

    int result = 0;
    Iterator<Map.Entry<String, String>> iter = map.entrySet().iterator();

    while (iter.hasNext()) {
        Map.Entry<String, String> next = iter.next();
        int entryHash = (next.getKey() == null ? 0 : next.getKey().hashCode())
                ^ (next.getValue() == null ? 0 : next.getValue().toLowerCase().hashCode());
        result += entryHash;
    }
    return result;
}

From source file:Main.java

public static void checkCollectionDoesNotContainNull(final Collection<?> collection) {
    boolean containsNull = false;

    try {/*from  w ww . jav a  2 s  .  c  om*/
        containsNull = collection.contains(null);
    } catch (NullPointerException ex) {
        // Not a problem.
    }

    if (containsNull) {
        throw new NullPointerException();
    }
}

From source file:Main.java

public static <T> T checkNotNull(T reference) {
    if (reference == null) {
        throw new NullPointerException();
    }//w  w w . j  a v a2 s . co m
    return reference;
}

From source file:Main.java

public static void setTextContent(Node node, String nodeValue) {

    if (node == null || nodeValue == null)
        throw new NullPointerException();

    node.appendChild(node.getOwnerDocument().createTextNode(xmlEncode(nodeValue)));
}

From source file:Main.java

public static <T> T checkNotNull(T object) {
    if (object == null)
        throw new NullPointerException();
    return object;
}

From source file:Main.java

public static Node parseXML(String text) throws SAXException, ParserConfigurationException, IOException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = dbf.newDocumentBuilder();
    InputSource source = new InputSource(new StringReader(text));
    Document doc = parser.parse(source);
    if (doc == null) {
        throw new NullPointerException();
    }//from   ww  w  . j  av  a2 s .co m

    return doc.getFirstChild();
}

From source file:Main.java

/**
 * Set the drawable to a specific color and return it
 * @param drawable The drawable to change
 * @param colorToSet The color to set it to
 * @return Drawable//  w  w w.  j a  v  a 2  s  .c  o  m
 * @throws NullPointerException, if it fails, throws a null pointer
 */
public static Drawable colorDrawable(Drawable drawable, int colorToSet) {
    try {
        drawable.mutate().setColorFilter(colorToSet, PorterDuff.Mode.MULTIPLY);
        return drawable;
    } catch (Exception e) {
        e.printStackTrace();
        throw new NullPointerException();
    }
}

From source file:Main.java

public static <E> ArrayList<E> arrayAsList(final E[] array, final int start, final int end) {
    if (array == null) {
        throw new NullPointerException();
    }/* ww w  .j a  v  a 2  s  . c  o  m*/
    if (start < 0 || start > end || end > array.length) {
        throw new IllegalArgumentException();
    }

    final ArrayList<E> list = new ArrayList<>(end - start);
    for (int i = start; i < end; i++) {
        list.add(array[i]);
    }
    return list;
}

From source file:Main.java

public static boolean isAllNullArray(Object array) {
    if (array == null) {
        throw new NullPointerException();
    }//from w w w .  j a v  a 2s  .  co  m
    if (!array.getClass().isArray()) {
        throw new IllegalArgumentException("Expected array but received " + array.getClass());
    }
    for (int i = 0; i < Array.getLength(array); i++) {
        if (Array.get(array, i) != null) {
            return false;
        }
    }
    return true;
}

From source file:com.laxser.blitz.util.BlitzStringUtil.java

public static String relativePathToModulePath(String relativePath) {
    if (relativePath == null) {
        throw new NullPointerException();
    }//from  w  w w  . ja va  2  s  .c  o  m
    if (relativePath.length() == 0) {
        return "";
    }
    return StringUtils.removeEnd("/" + relativePath, "/");
}