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 double pixelXToLongitude(int pixelX, double zoomLevel, int tileSize) {
    int mapSize = getMapSize(zoomLevel, tileSize);
    if (pixelX < 0 || pixelX > mapSize) {
        throw new IllegalArgumentException(
                "invalid pixelX coordinate at zoom level " + zoomLevel + ": " + pixelX);
    }/* w ww  .  j a  v a2  s  .c om*/
    return 360d * pixelX / mapSize - 180d;
}

From source file:Main.java

public static <T> Collection<T> isEmpty(Collection<T> collection, String messgae) {
    if (collection == null || collection.isEmpty()) {
        //TODO: Araz
        throw new IllegalArgumentException(messgae);
    }/* w  ww.j  a v a 2  s .c om*/

    return collection;
}

From source file:Main.java

public static double pixelYToLatitude(int pixelY, double zoomLevel, int tileSize) {
    int mapSize = getMapSize(zoomLevel, tileSize);
    if (pixelY < 0 || pixelY > mapSize) {
        throw new IllegalArgumentException(
                "invalid pixelY coordinate at zoom level " + zoomLevel + ": " + pixelY);
    }//from w  w w .  j  a v  a2  s .  com
    double y = .5d - ((double) pixelY / mapSize);
    return 90d - 360d * Math.atan(Math.exp(-y * (2d * Math.PI))) / Math.PI;
}

From source file:Main.java

public static boolean isFiledWithName(Field field, String fieldName) {
    if (field == null || TextUtils.isEmpty(fieldName)) {
        throw new IllegalArgumentException("params is illegal");
    }// ww w . jav  a 2 s  .  c om
    if (fieldName.equals(field.getName())) {
        return true;
    }
    return false;
}

From source file:Main.java

/**
 *   Gets the text for a node by concatenating child TEXT elements.
 *//* w  w w  . java  2 s .c o m*/
public synchronized static String getText(Node n) {
    if (n == null)
        throw new IllegalArgumentException("Node argument cannot be null");

    StringBuilder b = new StringBuilder();
    NodeList nl = n.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        if (nl.item(i).getNodeType() == Node.TEXT_NODE)
            b.append(nl.item(i).getNodeValue());
        else if (nl.item(i).getNodeType() == Node.CDATA_SECTION_NODE)
            b.append(nl.item(i).getNodeValue());
    }

    return b.toString().trim();
}

From source file:Main.java

public static void checkContent(final Collection<?> collection, final Class<?> clazz) {
    for (final Object o : collection) {
        if (!clazz.isInstance(o)) {
            throw new IllegalArgumentException(
                    "Collection has an instance of " + o.getClass() + ", which doesn't inherit from " + clazz);
        }/*from  ww  w  .j av a 2 s . c om*/
    }
}

From source file:Main.java

public static Map<String, String> toMap(String... arr) {
    Map<String, String> map = new HashMap<String, String>();
    if (arr.length == 0 || arr.length % 2 != 0) {
        throw new IllegalArgumentException(Arrays.toString(arr) + " should have an even number of arguments");
    }//from   www.j  av a 2 s.  c o  m

    for (int i = 0; i < arr.length; i += 2) {
        map.put(arr[i], arr[i + 1]);
    }

    return map;

}

From source file:Main.java

public static <T> List<T> pageList(List<T> list, int page, int size) {
    if (page < 1) {
        throw new IllegalArgumentException("page should not little than 1,page:" + page);
    }//  w  w w.  j a v a 2s.  c  o  m
    if (size < 1) {
        throw new IllegalArgumentException("size should not little than 1,size:" + size);
    }
    if (isEmpty(list)) {
        return Collections.emptyList();
    }
    int totalSize = list.size();

    int fromIndex = (page - 1) * size > (totalSize - 1) ? 0 : (page - 1) * size;

    int endIndex = (fromIndex + size) > (totalSize) ? (totalSize) : (fromIndex + size);

    return list.subList(fromIndex, endIndex);

}

From source file:Main.java

public static <T> T findLastItem(SortedSet<T> queryResult, int lastItemPosition) {
    if (queryResult == null || queryResult.isEmpty())
        throw new IllegalArgumentException("Provided result set is 'null' or empty.");

    Iterator<T> resultSetIterator = queryResult.iterator();
    int nbItemInList = 0;
    T lastItem = null;//from   w  w  w .  ja v a  2s.  c  o  m
    while (resultSetIterator.hasNext() && nbItemInList++ < lastItemPosition)
        lastItem = resultSetIterator.next();
    return lastItem;
}

From source file:Main.java

public static long getFolderSize(File folder) throws IllegalArgumentException {
    // Validate/*from  w  w  w.  j ava 2 s  .  c o  m*/
    if (folder == null || !folder.isDirectory())
        throw new IllegalArgumentException("Invalid   folder ");
    String list[] = folder.list();
    if (list == null || list.length < 1)
        return 0;

    // Get size
    File object = null;
    long folderSize = 0;
    for (int i = 0; i < list.length; i++) {
        object = new File(folder, list[i]);
        if (object.isDirectory())
            folderSize += getFolderSize(object);
        else if (object.isFile())
            folderSize += object.length();
    }
    return folderSize;
}