Example usage for java.lang Integer MAX_VALUE

List of usage examples for java.lang Integer MAX_VALUE

Introduction

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

Prototype

int MAX_VALUE

To view the source code for java.lang Integer MAX_VALUE.

Click Source Link

Document

A constant holding the maximum value an int can have, 231-1.

Usage

From source file:Main.java

public static int longToInt(long l) {
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
        throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");
    }/*from w ww . ja va 2s  . c  om*/
    return (int) l;
}

From source file:Main.java

private static int getMin(int... vals) {
    int min = Integer.MAX_VALUE;
    for (int i : vals)
        if (i < min)
            min = i;/*from w w  w. j a  va2 s. c om*/
    return min;
}

From source file:Main.java

public static void add(Calendar c, int unit, long increment) {
    while (increment > Integer.MAX_VALUE) {
        c.add(unit, Integer.MAX_VALUE);
        increment -= Integer.MAX_VALUE;
    }/*from  w w w.  j a va2  s  .co  m*/
    c.add(unit, (int) increment);
}

From source file:Main.java

public static int addAndCheck(int x, int y) {
    long s = (long) x + (long) y;
    if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) {
        throw new ArithmeticException("overflow: add");
    }//  w  w  w .j  a v  a2s .  c o  m
    return (int) s;
}

From source file:Main.java

private static boolean isFieldValid(int field) {
    return (field != -1) && (field != Integer.MAX_VALUE);
}

From source file:Main.java

public static Integer getInteger(TypedArray a, int attr) {
    int value = a.getResourceId(attr, Integer.MAX_VALUE);
    return value == Integer.MAX_VALUE ? null : Integer.valueOf(value);
}

From source file:Main.java

public static <RET> RET fromBase36(String basecode) {
    Long result = Long.valueOf(basecode, 36);
    long maxInt = new Long(Integer.MAX_VALUE);

    if (result > maxInt) {
        return ((RET) result);
    } else {/*from   ww w . j a  v a2s.  c o m*/
        return ((RET) (Integer) result.intValue());
    }

}

From source file:Main.java

public static int getSeqNo() {
    seqNo++;

    if (seqNo >= Integer.MAX_VALUE) {
        seqNo = 0;
    }

    return seqNo;
}

From source file:Main.java

public static int getFileSize(String fileName) {
    File f = new File(fileName);
    long len = f.length();
    len = len > Integer.MAX_VALUE ? Integer.MAX_VALUE : len;
    return (int) len;
}

From source file:Main.java

public static Rectangle bound(Point... points) {
    int smallestX = Integer.MAX_VALUE;
    int smallestY = Integer.MAX_VALUE;
    int largestX = Integer.MIN_VALUE;
    int largestY = Integer.MIN_VALUE;
    for (Point point : points) {
        if (point == null) {
            continue;
        }// ww w . ja  va 2s  .c om
        if (point.x > largestX)
            largestX = point.x;
        if (point.y > largestY)
            largestY = point.y;
        if (point.x < smallestX)
            smallestX = point.x;
        if (point.y < smallestY)
            smallestY = point.y;
    }
    return new Rectangle(smallestX, smallestY, largestX - smallestX, largestY - smallestY);
}