Example usage for java.lang IllegalArgumentException IllegalArgumentException

List of usage examples for java.lang IllegalArgumentException IllegalArgumentException

Introduction

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

Prototype

public IllegalArgumentException(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

private static String encodeUrlParams(/*@Nullable*/String userLocale,
        /*@Nullable*/String/*@Nullable*/[] params) {
    StringBuilder buf = new StringBuilder();
    String sep = "";
    if (userLocale != null) {
        buf.append("locale=").append(userLocale);
        sep = "&";
    }/*from ww w. j  a  v a2  s  . c om*/

    if (params != null) {
        if (params.length % 2 != 0) {
            throw new IllegalArgumentException(
                    "'params.length' is " + params.length + "; expecting a multiple of two");
        }
        for (int i = 0; i < params.length;) {
            String key = params[i];
            String value = params[i + 1];
            if (key == null)
                throw new IllegalArgumentException("params[" + i + "] is null");
            if (value != null) {
                buf.append(sep);
                sep = "&";
                buf.append(encodeUrlParam(key));
                buf.append("=");
                buf.append(encodeUrlParam(value));
            }
            i += 2;
        }
    }

    return buf.toString();
}

From source file:Main.java

public static Object evaluateXPath(String xpath, Object item, QName returnType) {
    try {//  w w  w .ja  v  a2s .  com
        return XPathFactory.newInstance().newXPath().compile(xpath).evaluate(item, returnType);
    } catch (XPathExpressionException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:Main.java

/**
 * Checks that an array does not contain null reference.
 *
 * @param parameterName   Parameter name.
 * @param parameterValues Parameter values.
 * @param <ParameterType> Parameter type.
 *///www  .  jav  a 2  s. c  o  m
static <ParameterType> void checkParameterArrayIsNotNull(final String parameterName,
        final ParameterType[] parameterValues) {
    // - Check array.
    checkParameterIsNotNull(parameterName, parameterValues);

    // - Check array size.
    if (parameterValues.length == 0) {
        throw new IllegalArgumentException(parameterName + " cannot be empty.");
    }

    // - Check array values.
    for (final ParameterType parameterValue : parameterValues) {
        if (parameterValue == null) {
            throw new IllegalArgumentException(parameterName + " cannot contain null.");
        }
    }
}

From source file:Main.java

private static Method findGetterMethod(String propertyName, Class<?> itemClass) {
    try {//from  ww w .j av  a 2 s  .  c o  m
        String capitalizedPropertyName = capitalize(propertyName);
        Method getterMethod;
        try {
            getterMethod = itemClass.getMethod("get" + capitalizedPropertyName);
        } catch (NoSuchMethodException e) {
            getterMethod = itemClass.getMethod("is" + capitalizedPropertyName);
        }
        return getterMethod;
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException("Could not find getter method for property " + propertyName);
    }
}

From source file:Main.java

public static boolean nextStartTagInsideTree(final XmlPullParser pp, final String tagNamespace,
        final String tagName) throws XmlPullParserException, IOException {
    if (tagNamespace == null && tagName == null)
        throw new IllegalArgumentException(
                "namespace and name argument can not be both null:" + pp.getPositionDescription());

    if (pp.getEventType() != XmlPullParser.START_TAG && pp.getEventType() != XmlPullParser.END_TAG)
        throw new IllegalStateException(
                "expected START_TAG of parent or END_TAG of child:" + pp.getPositionDescription());

    while (true) {
        final int eventType = pp.next();

        if (eventType == XmlPullParser.START_TAG) {
            final String name = pp.getName();
            final String namespace = pp.getNamespace();
            boolean matches = (tagNamespace != null && tagNamespace.equals(namespace))
                    || (tagName != null && tagName.equals(name));
            if (matches)
                return true;

            skipSubTree(pp);//from  w  w  w .  jav a  2s  . co m
            pp.require(XmlPullParser.END_TAG, namespace, name);
        } else if (eventType == XmlPullParser.END_TAG) {
            return false;
        }
    }
}

From source file:Main.java

/**
 * Scales the provided dimension such that it is just large enough to fit
 * the target width and height.// www  . j  av  a  2  s  .co m
 *
 * @param dimensions The dimensions to scale
 * @param targetWidth The target width
 * @param targetHeight The target height
 * @return The scale factor applied to dimensions
 */
public static float scaleToFitTargetSize(int[] dimensions, int targetWidth, int targetHeight) {
    if (dimensions.length < 2 || dimensions[0] <= 0 || dimensions[1] <= 0) {
        throw new IllegalArgumentException(
                "Expected dimensions to have length >= 2 && dimensions[0] > 0 && " + "dimensions[1] > 0");
    }
    float scale = Math.max((float) targetWidth / dimensions[0], (float) targetHeight / dimensions[1]);
    dimensions[0] *= scale;
    dimensions[1] *= scale;
    return scale;
}