Example usage for java.lang Integer MIN_VALUE

List of usage examples for java.lang Integer MIN_VALUE

Introduction

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

Prototype

int MIN_VALUE

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

Click Source Link

Document

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

Usage

From source file:Main.java

/** Helper method - gets a named element's value as a <I>Byte</I>.
   @param pElement The parent <I>Element</I>.
   @param strName Name of the element./*from w ww. j a  v  a2s .  c o  m*/
   @return Value of the element.
 */
public static byte getElementByte(Element pElement, String strName)
        throws ClassCastException, NumberFormatException {
    int nReturn = getElementInt(pElement, strName);

    if (Integer.MIN_VALUE == nReturn)
        return Byte.MIN_VALUE;

    return (byte) nReturn;
}

From source file:Main.java

/** Helper method - gets a named element's value as a <I>short</I>.
   @param pElement The parent <I>Element</I>.
   @param strName Name of the element./* w  ww  . j a v  a 2  s .com*/
   @return Value of the element.
 */
public static short getElementShort(Element pElement, String strName)
        throws ClassCastException, NumberFormatException {
    int nReturn = getElementInt(pElement, strName);

    if (Integer.MIN_VALUE == nReturn)
        return Short.MIN_VALUE;

    return (short) nReturn;
}

From source file:Main.java

/**
 * result linear coef with coef[0]=a and coef[1]=b in a*x+b*/
static public double[] regress(double[] y, double[] x) {
    double[] coefs = new double[2];

    // first pass: read in data, compute xbar and ybar
    double sumx = 0.0, sumy = 0.0, sumx2 = 0.0;
    int offset = 0;
    int length = x.length;
    double R2 = 0;
    while (R2 < 0.50) {
        for (int i = offset; i < length; i++) {
            if (x[i] != Integer.MIN_VALUE && y[i] != Integer.MIN_VALUE) {
                sumx += x[i];// www  .ja v  a 2s.com
                sumx2 += x[i] * x[i];
                sumy += y[i];
            }
        }
        double xbar = sumx / length;
        double ybar = sumy / length;

        // second pass: compute summary statistics
        double xxbar = 0.0, yybar = 0.0, xybar = 0.0;
        for (int i = offset; i < length; i++) {
            if (x[i] != Integer.MIN_VALUE && y[i] != Integer.MIN_VALUE) {
                xxbar += (x[i] - xbar) * (x[i] - xbar);
                yybar += (y[i] - ybar) * (y[i] - ybar);
                xybar += (x[i] - xbar) * (y[i] - ybar);
            }
        }
        double a = xybar / xxbar;
        double b = ybar - a * xbar;

        coefs[0] = a;
        coefs[1] = b;

        // analyze results

        int df = length - 2;
        double rss = 0.0; // residual sum of squares
        double ssr = 0.0; // regression sum of squares
        for (int i = offset; i < length; i++) {
            if (x[i] != Integer.MIN_VALUE && y[i] != Integer.MIN_VALUE) {
                double fit = a * x[i] + b;
                rss += (fit - y[i]) * (fit - y[i]);
                ssr += (fit - ybar) * (fit - ybar);
            }
        }
        R2 = ssr / yybar;
        double svar = rss / df;
        double svar1 = svar / xxbar;
        double svar0 = svar / length + xbar * xbar * svar1;
        svar0 = svar * sumx2 / (length * xxbar);
        //Log.v("BORDER", "Coefficient of correlation : " + R2);
        offset++;
    }
    return coefs;
}

From source file:Main.java

public static int subAndCheck(int x, int y) {
    long s = (long) x - (long) y;
    if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) {
        throw new ArithmeticException("overflow: subtract");
    }// w  ww  .ja v  a  2s.com
    return (int) s;
}

From source file:Main.java

public static int max(final int... values) {
    int max = Integer.MIN_VALUE;
    for (final int v : values) {
        max = Math.max(v, max);/*from w  ww  .java 2 s. co m*/
    }
    return max;
}

From source file:Main.java

public static int toInt(long l) {
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE)
        throw new ArithmeticException("Value (" + l + ") cannot fit into int");
    return (int) l;
}

From source file:Main.java

public static int[] findBoundsOfVisibleBitmap(Bitmap bitmap) {
    // Sanity check
    if (bitmap == null)
        return null;

    // Init data/*from w w  w . jav a2s  . c  om*/
    int bitmapWidth = bitmap.getWidth();
    int bitmapHeight = bitmap.getHeight();

    // Color
    int backgroundColor = Color.TRANSPARENT;

    // Bounds
    int xMin = Integer.MAX_VALUE;
    int xMax = Integer.MIN_VALUE;
    int yMin = Integer.MAX_VALUE;
    int yMax = Integer.MIN_VALUE;

    // Get pixel array
    int[][] bitmapArray = new int[bitmapHeight][bitmapWidth];
    for (int y = 0; y < bitmapHeight; y++) {
        bitmap.getPixels(bitmapArray[y], 0, bitmapWidth, 0, y, bitmapWidth, 1);
    }

    // Find bitmap bound
    boolean foundPixel = false;
    // Find xMin
    for (int x = 0; x < bitmapWidth; x += SCAN_INTERVAL) {
        boolean stop = false;
        for (int y = 0; y < bitmapHeight; y += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                xMin = x;
                stop = true;
                foundPixel = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Image is empty...
    if (!foundPixel)
        return null;

    // Find yMin
    for (int y = 0; y < bitmapHeight; y += SCAN_INTERVAL) {
        boolean stop = false;
        for (int x = xMin; x < bitmapWidth; x += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                yMin = y;
                stop = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Find xMax
    for (int x = bitmapWidth - 1; x >= xMin; x -= SCAN_INTERVAL) {
        boolean stop = false;
        for (int y = yMin; y < bitmapHeight; y += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                xMax = x;
                stop = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Find yMax
    for (int y = bitmapHeight - 1; y >= yMin; y -= SCAN_INTERVAL) {
        boolean stop = false;
        for (int x = xMin; x <= xMax; x += SCAN_INTERVAL) {
            if (bitmapArray[y][x] != backgroundColor) {
                yMax = y;
                stop = true;
                break;
            }
        }
        if (stop)
            break;
    }

    // Expand bitmap with offset
    int offset = SCAN_INTERVAL;
    int left = Math.max(xMin - offset, 0);
    int top = Math.max(yMin - offset, 0);
    int right = Math.min(xMax + offset, bitmapWidth);
    int bottom = Math.min(yMax + offset, bitmapHeight);

    int[] bound = { left, top, right, bottom };
    return bound;
}

From source file:Main.java

public static boolean isEmpty(int val) {
    return (val == Integer.MIN_VALUE) ? true : 0 == val;
}

From source file:Main.java

public static int getFrequentElement(int[] bcp) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;//from  w ww. j  a va2s  . com

    for (int col = 0; col < bcp.length; col++) {
        //System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(bcp[col])) {
            map.put(bcp[col], id++);
            count.add(1);
            uniId.add(bcp[col]);
        } else {
            no = map.get(bcp[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        //System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    //System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    return maxId;
}

From source file:Main.java

public static boolean getFrequentElementBinary(int[] sample) {
    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    ArrayList<Integer> count = new ArrayList<Integer>();
    ArrayList<Integer> uniId = new ArrayList<Integer>();
    int id = 0;// w  w  w .  jav a 2 s  .c  om

    for (int col = 0; col < sample.length; col++) {
        // System.out.print(bcp[col] + "\t");
        int no = 0;
        if (!map.containsKey(sample[col])) {
            map.put(sample[col], id++);
            count.add(1);
            uniId.add(sample[col]);
        } else {
            no = map.get(sample[col]);
            count.set(no, count.get(no) + 1);
        }
    }

    int maximum = Integer.MIN_VALUE;
    int maxId = Integer.MIN_VALUE;
    for (int i = 0; i < count.size(); i++) {
        // System.out.print(uniId.get(i) + ":" + count.get(i) + ",\t");
        if (maximum < count.get(i)) {
            maximum = count.get(i);
            maxId = uniId.get(i);
        }
    }
    // System.out.println();

    map.clear();
    uniId.clear();
    count.clear();
    if (maxId == 1)
        return true;
    else
        return false;
}