List of usage examples for java.lang Integer MAX_VALUE
int MAX_VALUE
To view the source code for java.lang Integer MAX_VALUE.
Click Source Link
From source file:Main.java
/** * Check for a running service/*from w w w .j a va 2s .c o m*/ * * @param ctx the application context * @param serviceClassName the service class name * @return true if service is running, false overwise */ public static boolean checkForRunningService(Context ctx, String serviceClassName) { ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClassName.equals(service.service.getClassName())) { return true; } } return false; }
From source file:at.tuwien.ifs.commons.util.MathUtils.java
/** finds the minimum value from a given array of integer values */ public static int min(int... arguments) { int min = Integer.MAX_VALUE; for (int argument : arguments) { if (argument < min) { min = argument;/*w w w. j a va2 s .com*/ } } return min; }
From source file:ardufocuser.starfocusing.Utils.java
/** * Calcula valores de luz maximos y minimos de la matriz imagen. */// w w w. jav a 2 s . c om public static int[] computeMinMax(int[][] pixels) { int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for (int x = 0; x < pixels.length; x++) { for (int y = 0; y < pixels[0].length; y++) { if (min > pixels[x][y]) { min = pixels[x][y]; } if (max < pixels[x][y]) { max = pixels[x][y]; } } } return new int[] { min, max }; }
From source file:Main.java
public static byte[] getFileAsBytes(File file) { byte[] bytes = null; InputStream is = null;// w w w . j ava 2 s . co m try { is = new FileInputStream(file); // Get the size of the file long length = file.length(); if (length > Integer.MAX_VALUE) { Log.e(t, "File " + file.getName() + "is too large"); return null; } // Create the byte array to hold the data bytes = new byte[(int) length]; // Read in the bytes int offset = 0; int read = 0; try { while (offset < bytes.length && read >= 0) { read = is.read(bytes, offset, bytes.length - offset); offset += read; } } catch (IOException e) { Log.e(t, "Cannot read " + file.getName()); e.printStackTrace(); return null; } // Ensure all the bytes have been read in if (offset < bytes.length) { try { throw new IOException("Could not completely read file " + file.getName()); } catch (IOException e) { e.printStackTrace(); return null; } } return bytes; } catch (FileNotFoundException e) { Log.e(t, "Cannot find " + file.getName()); e.printStackTrace(); return null; } finally { // Close the input stream try { is.close(); } catch (IOException e) { Log.e(t, "Cannot close input stream for " + file.getName()); e.printStackTrace(); return null; } } }
From source file:Main.java
/** * Add two integers, checking for overflow. * //from w w w. j av a 2s.c o m * @param x an addend * @param y an addend * @return the sum <code>x+y</code> * @throws ArithmeticException if the result can not be represented as an * int * @since 1.1 */ 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"); } return (int) s; }
From source file:Main.java
public static int safeLongToInt(long l) throws IllegalArgumentException { if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw new IllegalArgumentException(l + " cannot be cast to int without changing its value."); }//ww w.j a v a2s. c om return (int) l; }
From source file:FileUtil.java
public static byte[] readFileAsBytes(String path, Integer start, Integer length) { byte[] byteData = null; try {// ww w. j ava 2 s . c o m File file = new File(path); DataInputStream dis; dis = new DataInputStream(new FileInputStream(file)); if (dis.available() > Integer.MAX_VALUE) { System.out.println("dis.available() > Integer.MAX_VALUE"); } ByteArrayOutputStream os = new ByteArrayOutputStream(length); byte[] bytes = new byte[length]; dis.skipBytes(start); int readBytes = dis.read(bytes, 0, length); os.write(bytes, 0, readBytes); byteData = os.toByteArray(); dis.close(); os.close(); } catch (Exception e) { System.out.println(e); } return byteData; }
From source file:it.sephiroth.android.library.exif2.io.IOUtils.java
public static int copy(final InputStream input, final OutputStream output) throws IOException { final long count = copyLarge(input, output); if (count > Integer.MAX_VALUE) { return -1; }// w w w.j a va 2s. c o m return (int) count; }
From source file:Main.java
/** * Subtract two integers, checking for overflow. * // w ww . ja v a2 s .c o m * @param x the minuend * @param y the subtrahend * @return the difference <code>x-y</code> * @throws ArithmeticException if the result can not be represented as an * int * @since 1.1 */ 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"); } return (int) s; }
From source file:Main.java
private static String buildTmdbUrl(String baseUrl, String imagePath, int width) { StringBuilder url = new StringBuilder(baseUrl); if (width == Integer.MAX_VALUE) { url.append("original"); } else {/*from www. j a va 2 s. c om*/ url.append('w').append(width); } url.append(imagePath); return url.toString(); }