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(String s) 

Source Link

Document

Constructs a NullPointerException with the specified detail message.

Usage

From source file:Main.java

public static <T> List<List<T>> innerJoin(List<T> l1, List<T> l2, BiFunction<T, T, T> function) {
    if (l1 == null || l2 == null) {
        throw new NullPointerException("inner join arrays must not be null");
    }/*from   www . java2  s  .  c  o m*/

    if (l1.isEmpty() && l2.isEmpty()) {
        return Collections.emptyList();
    } else if (l1.isEmpty()) {
        return Collections.singletonList(l2);
    } else if (l2.isEmpty()) {
        return Collections.singletonList(l1);
    }

    List<List<T>> result = new ArrayList<>(l1.size() * l2.size());
    l1.stream().forEach(t1 -> {
        List<T> l = new ArrayList<>();
        l2.stream().forEach(t2 -> l.add(function.apply(t1, t2)));
        result.add(l);
    });
    return result;
}

From source file:Main.java

/**Throw NullPointerException if the particular object is null
 * @param object The particular object//from  w  ww  . j  a va 2  s  .  com
 * @param message The message which to be wrapped into NullPointerException
 */
public static void notNull(Object object, String message) {
    if (object == null) {
        throw new NullPointerException(message == null ? "" : message);
    }
}

From source file:com.wolvereness.bluebutton.Version.java

private static String getProperty(final Properties properties, final String property) {
    final Object obj = properties.get(property);
    if (obj == null)
        throw new NullPointerException(property);
    return obj.toString();
}

From source file:Main.java

/**
 * Join a collection of strings into a single String object, in the order
 * indicated by the collection's iterator.
 *
 * @param strings a collection containing exclusively String objects
 * @return a single String object//from   w ww .j  a  v a2 s  .  co  m
 */
public static String joinStrings(Collection<String> strings) {
    StringBuilder buf = new StringBuilder();
    if (strings == null) {
        throw new NullPointerException("Received null collection");
    }
    for (String s : strings) {
        buf.append(s);
    }
    return buf.toString();
}

From source file:com.github.jinahya.codec.HexBinaryEncoderProxy.java

/**
 * Returns a new proxy instance for//from  w w  w. j a v a  2s.  c  o m
 * {@code org.apache.commons.codec.BinaryEncoder} with given
 * {@code encoder}.
 *
 * @param encoder the encoder to proxy
 *
 * @return a new proxy instance.
 */
public static Object newInstance(final HexEncoder encoder) {

    if (encoder == null) {
        throw new NullPointerException("encoder");
    }

    return newInstance(HexBinaryEncoderProxy.class, HexEncoder.class, encoder);
}

From source file:com.github.rvesse.airline.Cli.java

/**
 * Creates a builder for specifying a command line in fluent style
 * //  w  w w  .j  ava 2 s.c o  m
 * @param name
 *            Program name
 * @return CLI Builder
 */
public static <T> CliBuilder<T> builder(String name) {
    if (name == null)
        throw new NullPointerException("name cannot be null");
    return new CliBuilder<T>(name);
}

From source file:Main.java

/**
 * Calculates the sign value from a byte array
 * /* w ww.j a va2 s .co m*/
 * @param bytes - Given byte array
 * @return Sign value String
 * @throws NullPointerException when bytes is NULL
 */
private static String createSignOfByteAray(byte[] bytes) {
    if (bytes == null) {
        throw new NullPointerException("AuthUtils.createSignOfByteAray() bytes cannot be NULL");
    }
    return String.valueOf(bytes.length);
}

From source file:net.larry1123.util.api.time.StringTime.java

/**
 * Takes just a number or a set of numbers with a D, H, M or, S fallowing it
 * The letters can be upper or lower case
 * 15h 50m 5s/*from ww w .  ja  v  a 2 s  . c  om*/
 *
 * @param string Whole String to decode into parts
 *
 * @return the amount of time in milliseconds that the time string Decodes to
 */
public static long millisecondsFromString(String string) {
    if (string == null) {
        throw new NullPointerException("String can not be null");
    }
    string = string.trim();
    long ret = 0;
    try {
        ret = Long.parseLong(string);
    } catch (NumberFormatException e) {
        for (String part : string.split(" ")) {
            if (part.length() >= 2) {
                String time = part.substring(part.length() - 1);
                switch (Part.getFromString(time)) {
                case DAYS:
                    try {
                        Long days = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += days * DateUtils.MILLIS_PER_DAY;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case HOUR:
                    try {
                        Long hours = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += hours * DateUtils.MILLIS_PER_HOUR;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case MINUTES:
                    try {
                        Long minutes = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += minutes * DateUtils.MILLIS_PER_MINUTE;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                case SECONDS:
                    try {
                        Long seconds = Long.parseLong(part.substring(0, part.length() - 1));
                        ret += seconds * DateUtils.MILLIS_PER_SECOND;
                    } catch (NumberFormatException error) {
                        // DO nothing right now
                    }
                    break;
                default:
                    // Something is malformed just let it fly by and keep going
                    break;
                }
            } else if (part.length() == 1) {
                switch (Part.getFromString("" + part.charAt(1))) {
                case DAYS:
                    ret += DateUtils.MILLIS_PER_DAY;
                    break;
                case HOUR:
                    ret += DateUtils.MILLIS_PER_HOUR;
                    break;
                case MINUTES:
                    ret += DateUtils.MILLIS_PER_MINUTE;
                    break;
                case SECONDS:
                    ret += DateUtils.MILLIS_PER_SECOND;
                    break;
                default:
                    // Something is malformed just let it fly by and keep going
                    break;
                }
            }
        }
    }
    return ret;
}

From source file:Main.java

public static <E> ArrayList<E> asArrayList(E first, E second, E... other) {
    if (other == null) {
        throw new NullPointerException("other");
    }//from   www . j  a  v a 2 s .  c  o m
    ArrayList<E> list = new ArrayList<>(1 + 1 + other.length);
    list.add(first);
    list.add(second);
    list.addAll(Arrays.asList(other));
    return list;
}

From source file:Main.java

/**
 * Creates a list of integers from a string within tokens. Empty tokens will
 * be omitted: If a string within tokens is <code>"1,,2,,3"</code> and the
 * delimiter string is <code>","</code>, the returned list of integers
 * contains the tree elements <code>1, 2, 3</code>.
 *
 * <em>It is expected, that each token can be parsed as an integer or is
 * empty!</em>//from   w ww  .ja  va 2  s . c  om
 *
 * @param string    String within tokens parsable as integer
 * @param delimiter Delimiter between the integer tokens. Every character
 *                  of the delimiter string is a separate delimiter. If
 *                  the string within tokens is <code>"1,2:3"</code>
 *                  and the delimiter string is <code>",:"</code>, the
 *                  returned list of integers contains the three elements
 *                  <code>1, 2, 3</code>.
 * @return          list of integers
 * @throws          NumberFormatException if the string contains a not empty
 *                  token that can't parsed as an integer
 */
public static List<Integer> integerTokenToList(String string, String delimiter) {
    if (string == null) {
        throw new NullPointerException("string == null");
    }

    if (delimiter == null) {
        throw new NullPointerException("delimiter == null");
    }

    List<Integer> integerList = new ArrayList<>();
    StringTokenizer tokenizer = new StringTokenizer(string, delimiter);

    while (tokenizer.hasMoreTokens()) {
        integerList.add(Integer.parseInt(tokenizer.nextToken()));
    }

    return integerList;
}