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:TestLargest.java
public static int largest(int[] list) { int index, max = Integer.MAX_VALUE; if (list.length == 0) { throw new RuntimeException("Empty list"); }/* w w w . ja v a 2 s . com*/ for (index = 0; index < list.length - 1; index++) { if (list[index] > max) { max = list[index]; } } return max; }
From source file:Main.java
public static Bitmap getImageBitmapFromAssetsFolderThroughImagePathName(Context context, String imagePathName, int reqWidth, int reqHeight) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true;/*from w ww .j a v a 2 s .c o m*/ Bitmap bitmap = null; AssetManager assetManager = context.getResources().getAssets(); InputStream inputStream = null; try { inputStream = assetManager.open(imagePathName); inputStream.mark(Integer.MAX_VALUE); } catch (IOException e) { e.printStackTrace(); return null; } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); return null; } try { if (inputStream != null) { BitmapFactory.decodeStream(inputStream, null, opts); inputStream.reset(); } else { return null; } } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); return null; } catch (Exception e) { e.printStackTrace(); return null; } opts.inSampleSize = calculateInSampleSiez(opts, reqWidth, reqHeight); // Log.d(TAG,""+opts.inSampleSize); opts.inJustDecodeBounds = false; opts.inPreferredConfig = Bitmap.Config.RGB_565; opts.inPurgeable = true; opts.inInputShareable = true; opts.inDither = false; opts.inTempStorage = new byte[512 * 1024]; try { if (inputStream != null) { bitmap = BitmapFactory.decodeStream(inputStream, null, opts); } else { return null; } } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); return null; } catch (Exception e) { e.printStackTrace(); return null; } finally { if (inputStream != null) { try { inputStream.close(); } catch (Exception e) { e.printStackTrace(); return null; } } } //Log.d(TAG,"w:"+bitmap.getWidth()+" h:"+bitmap.getHeight()); if (bitmap != null) { try { bitmap = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true); } catch (OutOfMemoryError outOfMemoryError) { outOfMemoryError.printStackTrace(); System.gc(); return null; } } return bitmap; }
From source file:Main.java
public static void setMaxPreferredSize(JComponent comp) { comp.setPreferredSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); }
From source file:Main.java
public static boolean isLikelyFloat(int value) { // Check for some common named float values // We don't check for Float.MIN_VALUE, which has an integer representation of 1 if (value == canonicalFloatNaN || value == maxFloat || value == piFloat || value == eFloat) { return true; }// w w w. j a v a 2s .com // Check for some named integer values if (value == Integer.MAX_VALUE || value == Integer.MIN_VALUE) { return false; } // Check for likely resource id int packageId = value >> 24; int resourceType = value >> 16 & 0xff; int resourceId = value & 0xffff; if ((packageId == 0x7f || packageId == 1) && resourceType < 0x1f && resourceId < 0xfff) { return false; } // a non-canocical NaN is more likely to be an integer float floatValue = Float.intBitsToFloat(value); if (Float.isNaN(floatValue)) { return false; } // Otherwise, whichever has a shorter scientific notation representation is more likely. // Integer wins the tie String asInt = format.format(value); String asFloat = format.format(floatValue); // try to strip off any small imprecision near the end of the mantissa int decimalPoint = asFloat.indexOf('.'); int exponent = asFloat.indexOf("E"); int zeros = asFloat.indexOf("000"); if (zeros > decimalPoint && zeros < exponent) { asFloat = asFloat.substring(0, zeros) + asFloat.substring(exponent); } else { int nines = asFloat.indexOf("999"); if (nines > decimalPoint && nines < exponent) { asFloat = asFloat.substring(0, nines) + asFloat.substring(exponent); } } return asFloat.length() < asInt.length(); }
From source file:Main.java
public static boolean isEmpty(String val) { return (val == null | "".equals(val) | val.equals(Integer.toString(Integer.MAX_VALUE))); }
From source file:Main.java
public static Integer[] getLineAndCharPosition(String text, int offset) { int index = 0; int line = 0; int positionInLine = 0; while (true) { line++;/* ww w . j a v a 2 s . co m*/ positionInLine = offset - index + 1; int nextN = text.indexOf("\n", index); int nextR = text.indexOf("\r", index); int nextNorR = Integer.MAX_VALUE; if (nextN >= 0) { nextNorR = nextN; } else if (nextR >= 0 && nextR < nextNorR) { nextNorR = nextR; } else { // found no EOL character break; } index = nextNorR + 1; if (index == nextN) { index++; } if (index == nextR) { index++; } if (index > offset) { break; } } return new Integer[] { line, positionInLine }; }
From source file:Util.java
/** * Read bytes from a File into a byte[].//from w ww . ja v a2 s . c o m * * @param file The File to read. * @return A byte[] containing the contents of the File. * @throws IOException Thrown if the File is too long to read or couldn't be * read fully. */ public static byte[] readBytesFromFile(File file) throws IOException { InputStream is = new FileInputStream(file); // Get the size of the file long length = file.length(); // You cannot create an array using a long type. // It needs to be an int type. // Before converting to an int type, check // to ensure that file is not larger than Integer.MAX_VALUE. if (length > Integer.MAX_VALUE) { throw new IOException("Could not completely read file " + file.getName() + " as it is too long (" + length + " bytes, max supported " + Integer.MAX_VALUE + ")"); } // Create the byte array to hold the data byte[] bytes = new byte[(int) length]; // Read in the bytes int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } // Ensure all the bytes have been read in if (offset < bytes.length) { throw new IOException("Could not completely read file " + file.getName()); } // Close the input stream and return bytes is.close(); return bytes; }
From source file:Main.java
public static boolean isServiceRunning(Context context, Class serviceClass) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; }//ww w . ja v a 2s.co m } return false; }
From source file:com.microsoft.tfs.client.common.ui.teamexplorer.internal.TeamExplorerConfigHelpers.java
public static int getInteger(final IConfigurationElement element, final String attributeName) { try {/*from w w w.ja v a2 s .co m*/ return Integer.parseInt(element.getAttribute(attributeName)); } catch (final NumberFormatException e) { return Integer.MAX_VALUE; } }
From source file:Main.java
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) { ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; }/*from w ww. java 2 s .c o m*/ } return false; }