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

/**
 * Join the {@code strings} into one string with {@code delimiter} in 
 * between. It is similar to RegExpObject.test(string) in JavaScript.
 * //from  w  w  w . j  a  v  a2s .  c  om
 * @param strings the string list to join
 * @param delimiter the delimiter
 * 
 * @return the joined string
 */
public static String join(String[] strings, String delimiter) {
    if (strings == null) {
        throw new NullPointerException("argument 'strings' cannot be null");
    }

    StringBuilder sb = new StringBuilder();

    if (strings.length != 0) {
        sb.append(strings[0]);
        for (int i = 1, iEnd = strings.length; i < iEnd; i++) {
            if (delimiter != null) {
                sb.append(delimiter);
            }
            sb.append(strings[i]);
        }
    }

    return sb.toString();
}

From source file:fi.smaa.libror.RandomUtil.java

/**
 * Creates an array of random numbers that sum to a given amount.
 * //w  w  w .  j a v a2 s.co  m
 * @param dest the array to create the numbers to.
 * @param sumTo The amount the numbers must sum to. Must be >= 0.0
 * @throws NullPointerException if dest == null
 */
public static void createSumToRand(double[] dest, double sumTo) throws NullPointerException {
    if (sumTo < 0.0) {
        throw new IllegalArgumentException("sumTo negative");
    }
    if (dest == null) {
        throw new NullPointerException("destination array null");
    }

    int len = dest.length;
    for (int i = 0; i < len - 1; i++) {
        dest[i] = createUnif01() * sumTo;
    }

    dest[len - 1] = sumTo;

    Arrays.sort(dest);

    double last = 0.0;
    for (int i = 0; i < len; i++) {
        double t = dest[i];
        dest[i] = t - last;
        last = t;
    }
}

From source file:com.amazonaws.services.dynamodbv2.xspec.NamedElement.java

NamedElement(String name) {
    if (name == null) {
        throw new NullPointerException("element");
    }/*from  ww w.  j a  v  a 2s  . c om*/
    if (name.trim().isEmpty()) {
        throw new IllegalArgumentException("element cannot be empty");
    }
    this.name = name;
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.permissions.PermissionRegistry.java

/**
 * Create the registry and store it in the context.
 *//*from w  w  w. j  av a2  s.c  o m*/
public static void createRegistry(ServletContext ctx, Collection<? extends Permission> permissions) {
    if (ctx == null) {
        throw new NullPointerException("ctx may not be null.");
    }
    if (permissions == null) {
        throw new NullPointerException("permissions may not be null.");
    }
    if (ctx.getAttribute(ATTRIBUTE_NAME) != null) {
        throw new IllegalStateException("PermissionRegistry has already been set.");
    }

    PermissionRegistry registry = new PermissionRegistry();
    registry.addPermissions(permissions);
    ctx.setAttribute(ATTRIBUTE_NAME, registry);
}

From source file:com.nestedbird.util.UUIDConverter.java

/**
 * Turns a UUID in string format to a Base64 encoded version
 *
 * @param uuidString String representation of the uuid
 * @return base64 encoded version of the uuid
 * @throws IllegalArgumentException String must be a valid uuid
 * @throws NullPointerException     String cannot be null
 *//*  www.j a va 2 s .  com*/
public static String toBase64(final String uuidString) {
    if (uuidString == null)
        throw new NullPointerException("String cannot be null");
    if (!isUUID(uuidString))
        throw new IllegalArgumentException("string must be a valid uuid");

    final UUID uuid = UUID.fromString(uuidString);
    final ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return Base64.encodeBase64URLSafeString(bb.array());
}

From source file:com.cloudhopper.sxmp.SxmpWriter.java

static private void writeOperationStartTag(Writer out, Operation.Type type) throws IOException {
    if (type == null) {
        throw new NullPointerException("Operation type cannot be null");
    }/*from  w  ww .j  a  v  a  2s . co  m*/

    out.write("<operation type=\"" + type.getValue() + "\">\n");
}

From source file:com.jfinal.ext.plugin.sqlinxml.SqlKit.java

public static String sql(String groupNameAndsqlId) {
    if (sqlMap == null) {
        throw new NullPointerException("SqlInXmlPlugin not start");
    }/*from  w  w w .ja  v  a  2 s  . c o  m*/
    return ((SqlValueItem) sqlMap.get(groupNameAndsqlId)).value;
}

From source file:com.symbian.utils.config.CheckGetConfig.java

/**
 * @param aKey/*from   w w w .  j a v a2s .c om*/
 * @param aValue
 * @return
 * @throws ParseException 
 */
public Object get(final String aKey, final Object aValue) throws ParseException {
    if (aValue == null) {
        throw new NullPointerException("Generic getter: " + aKey + " is null.");
    }

    return aValue;
}

From source file:com.symbian.utils.config.CheckSetConfig.java

/**
 * @param aKey/* w ww  .jav  a 2 s. c  om*/
 * @param aValue
 * @return
 * @throws ParseException 
 */
public Object set(final String aKey, final Object aValue) throws ParseException {
    if (aValue == null) {
        throw new NullPointerException("Generic setter: " + aKey + " is null.");
    }

    return aValue;
}

From source file:com.espertech.esper.epl.view.OutputConditionPolledFactory.java

/**
 * Creates an output condition instance.
 * @param outputLimitSpec specifies what kind of condition to create
 * @return instance for handling output condition
 *//*from  w w w  .j a va2s . c  o m*/
public static OutputConditionPolled createCondition(OutputLimitSpec outputLimitSpec,
        AgentInstanceContext agentInstanceContext) throws ExprValidationException {
    if (outputLimitSpec == null) {
        throw new NullPointerException("Output condition by count requires a non-null callback");
    }

    // Check if a variable is present
    VariableReader reader = null;
    if (outputLimitSpec.getVariableName() != null) {
        reader = agentInstanceContext.getStatementContext().getVariableService()
                .getReader(outputLimitSpec.getVariableName());
        if (reader == null) {
            throw new IllegalArgumentException(
                    "Variable named '" + outputLimitSpec.getVariableName() + "' has not been declared");
        }
    }

    if (outputLimitSpec.getRateType() == OutputLimitRateType.CRONTAB) {
        return new OutputConditionPolledCrontab(outputLimitSpec.getCrontabAtSchedule(), agentInstanceContext);
    } else if (outputLimitSpec.getRateType() == OutputLimitRateType.WHEN_EXPRESSION) {
        return new OutputConditionPolledExpression(outputLimitSpec.getWhenExpressionNode(),
                outputLimitSpec.getThenExpressions(), agentInstanceContext);
    } else if (outputLimitSpec.getRateType() == OutputLimitRateType.EVENTS) {
        if (log.isDebugEnabled()) {
            log.debug(".createCondition creating OutputConditionCount with event rate " + outputLimitSpec);
        }

        if ((reader != null) && (!JavaClassHelper.isNumericNonFP(reader.getType()))) {
            throw new IllegalArgumentException("Variable named '" + outputLimitSpec.getVariableName()
                    + "' must be type integer, long or short");
        }

        int rate = -1;
        if (outputLimitSpec.getRate() != null) {
            rate = outputLimitSpec.getRate().intValue();
        }
        return new OutputConditionPolledCount(rate, reader);
    } else {
        if ((reader != null) && (!JavaClassHelper.isNumeric(reader.getType()))) {
            throw new IllegalArgumentException(
                    "Variable named '" + outputLimitSpec.getVariableName() + "' must be of numeric type");
        }

        return new OutputConditionPolledTime(outputLimitSpec.getTimePeriodExpr(), agentInstanceContext);
    }
}