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

public static Drawable bitmapToDrawable(Context context, Bitmap bitmap) {
    if (context == null || bitmap == null) {
        throw new IllegalArgumentException("Params illegal, please check you param");
    }/*from w ww  .  j  ava2  s  .c  o m*/
    Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
    return drawable;
}

From source file:Main.java

public static Map<String, String> toStringMap(final String... pairs) {
    final Map<String, String> parameters = new HashMap<String, String>();
    if (pairs.length > 0) {
        if (pairs.length % 2 != 0) {
            throw new IllegalArgumentException("pairs must be even.");
        }//from   w  w w. ja  v a  2s.c o m
        for (int i = 0; i < pairs.length; i = i + 2) {
            parameters.put(pairs[i], pairs[i + 1]);
        }
    }
    return parameters;
}

From source file:Main.java

public static Element getSingleChildElement(Element parent, Enum<?> child) {
    final Element el = getSingleOptionalChildElement(parent, child);
    if (el != null) {
        return el;
    }/*from w  w  w . ja v a  2 s .  c  o m*/
    throw new IllegalArgumentException("mandatory (single) child element " + getXmlName(child)
            + " missing for XML element " + parent.getNodeName());
}

From source file:Main.java

/**
 *  Gets a named attribute of a Node<p>
 *  @param node The node to search/*from   w w w . jav a2s . c  o m*/
 *  @param attr The name of the attribute to get
 */
public synchronized static String getAttribute(Node node, String attr) {
    if (node == null)
        throw new IllegalArgumentException("Node argument cannot be null");
    if (attr == null)
        throw new IllegalArgumentException("Node attribute argument cannot be null");

    NamedNodeMap map = node.getAttributes();
    if (map != null) {
        Node an = map.getNamedItem(attr);
        if (an != null)
            return an.getNodeValue();
    }

    return null;
}

From source file:Main.java

/**
 *  Removes a named attribute of a Node<p>
 *  @param node The node to search/*from  w  w w  .j  av a 2  s . c  o m*/
 *  @param attr The name of the attribute to remove
 */
public synchronized static void removeAttribute(Node node, String attr) {
    if (node == null)
        throw new IllegalArgumentException("Node argument cannot be null");
    if (attr == null)
        throw new IllegalArgumentException("Node attribute argument cannot be null");

    NamedNodeMap map = node.getAttributes();
    if (map != null) {
        Node an = map.getNamedItem(attr);
        if (an != null)
            map.removeNamedItem(attr);
    }
}

From source file:Main.java

public static byte[] transStreamToBytes(InputStream is, int buffSize) {
    if (is == null) {
        return null;
    }/*  ww w  .j a v  a2 s  .co m*/
    if (buffSize <= 0) {
        throw new IllegalArgumentException("buffSize can not less than zero.....");
    }
    byte[] data = null;
    byte[] buffer = new byte[buffSize];
    int actualSize = 0;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        while ((actualSize = is.read(buffer)) != -1) {
            baos.write(buffer, 0, actualSize);
        }
        data = baos.toByteArray();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return data;
}

From source file:Main.java

public static Float testNumber(String aArg) {
    while (true) {
        if (aArg.length() == 0) {
            return null;
        }/* www  .  ja  va 2  s  . co m*/
        if (aArg.matches("-?\\d+(\\.\\d+)?") == true) {
            break;
        } else {
            throw new IllegalArgumentException("not a number");
        }
    }
    return Float.parseFloat(aArg);
}

From source file:Main.java

public static int bytesToInt(boolean asc, byte... bytes) {
    if (null == bytes) {
        throw new NullPointerException("bytes is null!");
    }//from  w w w .ja  v  a  2  s  .  com
    final int length = bytes.length;
    if (length > 4) {
        throw new IllegalArgumentException("Illegal length!");
    }
    int result = 0;
    if (asc)
        for (int i = length - 1; i >= 0; i--) {
            result <<= 8;
            result |= (bytes[i] & 0x000000ff);
        }
    else
        for (int i = 0; i < length; i++) {
            result <<= 8;
            result |= (bytes[i] & 0x000000ff);
        }
    return result;
}

From source file:Main.java

/**
 * Return a BCD representation of an integer as a 4-byte array.
 * @param i int/*w  ww  .  j  a  va 2s . c om*/
 * @return  byte[4]
 */
public static byte[] intToBcdArray(int i) {
    if (i < 0)
        throw new IllegalArgumentException("Argument cannot be a negative integer.");

    StringBuilder binaryString = new StringBuilder();

    while (true) {
        int quotient = i / 10;
        int remainder = i % 10;
        String nibble = String.format("%4s", Integer.toBinaryString(remainder)).replace(' ', '0');
        binaryString.insert(0, nibble);

        if (quotient == 0) {
            break;
        } else {
            i = quotient;
        }
    }

    return ByteBuffer.allocate(4).putInt(Integer.parseInt(binaryString.toString(), 2)).array();
}

From source file:Main.java

public static String getFormDataContent(final List<? extends NameValuePair> parameters, final String boundary)
        throws IllegalArgumentException {

    if (parameters == null || parameters.size() == 0)
        throw new IllegalArgumentException("parameters error");
    final StringBuilder result = new StringBuilder();
    for (final NameValuePair parameter : parameters) {

        result.append(String.format("\r\n--%1$s\r\nContent-Disposition: form-data; name=\"%2$s\"\r\n\r\n%3$s",
                boundary, parameter.getName(), parameter.getValue()));
    }/*from  w ww .  j a va2 s .c o  m*/
    return result.toString();
}