List of usage examples for java.lang Integer MIN_VALUE
int MIN_VALUE
To view the source code for java.lang Integer MIN_VALUE.
Click Source Link
From source file:Main.java
public static int adjustDepthToBorders(int depth) { int depthBorder = 2; // TODO when can min value actually occur? if (depth > Integer.MIN_VALUE && depth < depthBorder) { return depthBorder; }//from www .ja v a2 s .co m return depth; }
From source file:Main.java
/** * Uses the value returned via the component's getText() method to set a Mnemonic key. * The character following the first '&' charcater is used as Mnemonic key, * but this only works for characters in the range a..Z * If a Mnemonic key is found, the '&' character is removed from the text. * @param textComponent//from w w w . ja va 2s.c om */ public static void setMnemonic(AbstractButton textComponent) { String label = textComponent.getText(); if (label == null || label.isEmpty() || !label.contains("&") || label.indexOf('&') == label.length() - 1) { return; } char ch = label.charAt(label.indexOf('&') + 1); if (!Character.isLetter(ch)) { return; } int ke = getKeyEvent(ch); if (ke != Integer.MIN_VALUE) { label = label.substring(0, label.indexOf('&')) + label.substring(label.indexOf('&') + 1, label.length()); textComponent.setText(label); textComponent.setMnemonic(ke); } }
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 ww.java 2s . c o m // 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
private static int parse(char[] chars, int offset, int len, int radix, boolean negative) throws NumberFormatException { int max = Integer.MIN_VALUE / radix; int result = 0; for (int i = 0; i < len; i++) { int digit = Character.digit(chars[i + offset], radix); if (digit == -1) { throw new NumberFormatException("Unable to parse"); }//from w w w . j a va 2s . co m if (max > result) { throw new NumberFormatException("Unable to parse"); } int next = result * radix - digit; if (next > result) { throw new NumberFormatException("Unable to parse"); } result = next; } /*while (offset < len) { }*/ if (!negative) { result = -result; if (result < 0) { throw new NumberFormatException("Unable to parse"); } } return result; }
From source file:Main.java
private static int parse(char[] string, int start, int length, int offset, int radix, boolean negative) throws NumberFormatException { int max = Integer.MIN_VALUE / radix; int result = 0; while (offset < length) { int digit = Character.digit(string[start + (offset++)], radix); if (digit == -1) { throw new NumberFormatException(new String(string, start, length)); }/*from ww w.java 2 s. c o m*/ if (max > result) { throw new NumberFormatException(new String(string, start, length)); } int next = result * radix - digit; if (next > result) { throw new NumberFormatException(new String(string, start, length)); } result = next; } if (!negative) { result = -result; if (result < 0) { throw new NumberFormatException(new String(string, start, length)); } } return result; }
From source file:Main.java
/** * Gets the number of bytes in the signed LEB128 encoding of the * given value./* w w w . j a v a 2 s . c o m*/ * * @param value the value in question * @return its write size, in bytes */ public static int signedLeb128Size(int value) { // TODO: This could be much cleverer. int remaining = value >> 7; int count = 0; boolean hasMore = true; int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1; while (hasMore) { hasMore = (remaining != end) || ((remaining & 1) != ((value >> 6) & 1)); value = remaining; remaining >>= 7; count++; } return count; }
From source file:Main.java
/** Helper method - gets a named attribute's value as an <I>int</I>. @param pNodeMap The <I>NamedNodeMap</I>. @param strName Name of the attribute. @return Value of the attribute.//w w w . j a v a 2 s . co m */ public static int getAttributeInt(NamedNodeMap pNodeMap, String strName) throws ClassCastException, NumberFormatException { String strValue = getAttributeString(pNodeMap, strName); if (null == strValue) return Integer.MIN_VALUE; return Integer.parseInt(strValue); }
From source file:Main.java
/** * Casts a long to an int. In many cases I use a long for a UInt32 but this cannot be used to allocate * ByteBuffers or arrays since they restricted to <code>Integer.MAX_VALUE</code> this cast-method will throw * a RuntimeException if the cast would cause a loss of information. * * @param l the long value/* w w w. j av a 2 s . com*/ * @return the long value as int */ public static int l2i(long l) { if (l > Integer.MAX_VALUE || l < Integer.MIN_VALUE) { throw new RuntimeException( "A cast to int has gone wrong. Please contact the mp4parser discussion group (" + l + ")"); } return (int) l; }
From source file:Main.java
/** Helper method - gets a named element's value as an <I>int</I>. @param pElement The parent <I>Element</I>. @param strName Name of the element.// w w w . jav a 2s.c om @return Value of the element. */ public static int getElementInt(Element pElement, String strName) throws ClassCastException, NumberFormatException { String strValue = getElementString(pElement, strName); if (null == strValue) return Integer.MIN_VALUE; return Integer.parseInt(strValue); }
From source file:Main.java
/** * Add two integers, checking for overflow. * /*from w w w. j a va 2 s .co 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; }