List of usage examples for java.lang Integer valueOf
@HotSpotIntrinsicCandidate public static Integer valueOf(int i)
From source file:Main.java
public static Integer readOptionalIntegerAttribute(XMLStreamReader reader, String attributeName) { String attributeValue = reader.getAttributeValue(null, attributeName); return attributeValue != null ? Integer.valueOf(attributeValue) : null; }
From source file:Main.java
public static int getArgument(String[] args, int index, int defaultValue) { if (args == null || args.length <= index) return defaultValue; int retValue = defaultValue; try {//from w w w. ja v a 2 s . c om retValue = Integer.valueOf(args[index]); } catch (NumberFormatException e) { retValue = defaultValue; } return retValue; }
From source file:Main.java
public static ArrayList<Integer> includeWeek(String week, String weekLine) { weekLine = weekLine.trim();//from w w w . j av a2 s .c om ArrayList<Integer> result = new ArrayList<>(); String[] ss = weekLine.split("@"); for (int i = 0; i < ss.length; i++) { String[] s1 = ss[i].split("-"); if (s1.length == 1 && s1[0].trim().substring(0, s1[0].trim().length() - 1).trim().equals(week)) { result.add(i); } else if (s1.length == 2 && Integer.valueOf(s1[0].trim()) <= Integer.valueOf(week.trim()) && Integer .valueOf(s1[1].substring(0, s1[1].length() - 1).trim()) >= Integer.valueOf(week.trim())) { result.add(i); } } return result; }
From source file:Main.java
public static int asInt(Object node, String key, int def) { Object value;//from w w w . ja v a 2 s . co m if ((node instanceof HashMap<?, ?>) && ((value = ((HashMap<?, ?>) node).get(key)) != null)) { if (value instanceof Number) { return ((Number) value).intValue(); } else { try { return Integer.valueOf(value.toString()); } catch (NumberFormatException ex) { return def; } } } else { return def; } }
From source file:Main.java
/** * Gets the localization method from the shared preferences. * * @param context The calling context.//from w w w .j a v a 2 s. com * @return int value, default 1 {@link com.indoor.navigation.indoornavigation.R.array#pref_loc_entries}. */ public static int getPrefPositioningMethod(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); return Integer.valueOf(sharedPreferences.getString("localization_type", "0")); }
From source file:Main.java
public static int readOptionalIntegerAttributeValue(XMLStreamReader reader, String attributeName, int defaultValue) { String attributeValue = reader.getAttributeValue(null, attributeName); return attributeValue != null ? Integer.valueOf(attributeValue) : defaultValue; }
From source file:Main.java
/** * Get the shared preference about knn from localization method. * * @param context The calling context.//w w w . ja va2 s . co m * @return Integer from preferences. If not a number, return value will be 3. */ public static int getPrefKnn(Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); int value = 3; try { value = Integer.valueOf(sharedPreferences.getString("localization_knn", "3")); } catch (NumberFormatException e) { e.printStackTrace(); } return value; }
From source file:Main.java
public static int selectIntAttribute(Element parent, String attrName) { String result = selectStringAttribute(parent, attrName, "0"); return Integer.valueOf(result); }
From source file:Main.java
private static boolean validCCNumber(String n) { try {/*from w ww .j a va 2s. co m*/ /* ** known as the LUHN Formula (mod10) */ int j = n.length(); String[] s1 = new String[j]; for (int i = 0; i < n.length(); i++) { s1[i] = "" + n.charAt(i); } int checksum = 0; for (int i = s1.length - 1; i >= 0; i -= 2) { int k = 0; if (i > 0) { k = Integer.valueOf(s1[i - 1]).intValue() * 2; if (k > 9) { String s = "" + k; k = Integer.valueOf(s.substring(0, 1)).intValue() + Integer.valueOf(s.substring(1)).intValue(); } checksum += Integer.valueOf(s1[i]).intValue() + k; } else { checksum += Integer.valueOf(s1[0]).intValue(); } } return ((checksum % 10) == 0); } catch (Exception e) { return false; } }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T parse(Class<T> type, String stringValue) throws IllegalArgumentException { if (type.equals(String.class)) { return (T) stringValue; }//from ww w.j av a 2s .c om if (type.equals(Boolean.class) || type.equals(boolean.class)) { return (T) Boolean.valueOf(stringValue); } try { if (type.equals(Integer.class) || type.equals(int.class)) { return (T) Integer.valueOf(stringValue); } if (type.equals(Long.class) || type.equals(long.class)) { return (T) Long.valueOf(stringValue); } if (type.equals(Short.class) || type.equals(short.class)) { return (T) Short.valueOf(stringValue); } if (type.equals(Byte.class) || type.equals(byte.class)) { return (T) Byte.valueOf(stringValue); } if (type.equals(Double.class) || type.equals(double.class)) { return (T) Double.valueOf(stringValue); } if (type.equals(Float.class) || type.equals(float.class)) { return (T) Float.valueOf(stringValue); } if (type.equals(File.class)) { return (T) new File(stringValue); } } catch (final NumberFormatException e) { throw new IllegalArgumentException(e.getMessage(), e); } if (type.isEnum()) { @SuppressWarnings("rawtypes") final Class enumType = type; return (T) Enum.valueOf(enumType, stringValue); } throw new IllegalArgumentException("Can't handle type " + type); }