List of usage examples for java.lang Integer Integer
@Deprecated(since = "9") public Integer(String s) throws NumberFormatException
From source file:Main.java
public static LinkedList<Integer> retrieveIntegerFromCursor(Cursor cursor, String columnName) { if (null == cursor || 0 == cursor.getCount()) { return new LinkedList<Integer>(); }/*from w ww . j av a 2s.co m*/ LinkedList<Integer> ids = new LinkedList<Integer>(); try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { int id = cursor.getInt(cursor.getColumnIndexOrThrow(columnName)); ids.add(new Integer(id)); } } catch (Exception e) { //do nothing. } finally { cursor.close(); } return ids; }
From source file:Main.java
public static String formatXmlAsString(Document document) { StringWriter writer = new StringWriter(); TransformerFactory factory = TransformerFactory.newInstance(); try {//from ww w .jav a2s .c om factory.setAttribute("indent-number", new Integer(2)); } catch (IllegalArgumentException ex) { } try { Transformer transformer = factory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); transformer.transform(new DOMSource(document), new StreamResult(writer)); } catch (TransformerException ex) { throw new RuntimeException("Error formatting xml as pretty-printed string", ex); } return writer.toString(); }
From source file:Main.java
public static Integer convertInteger(String str) { int val = 0; try {/* w ww .j a v a2s .com*/ val = Integer.parseInt(str); } catch (NumberFormatException ex) { } return new Integer(val); }
From source file:Main.java
public static <T> Map<T, Integer> getCardinalityMap(final Collection<T> coll) { if (coll == null) { return null; }/*from w w w .ja va 2 s .c o m*/ Map<T, Integer> result = new HashMap<T, Integer>(); Iterator<T> it = coll.iterator(); while (it.hasNext()) { T t = it.next(); Integer count = result.get(t); if (count == null) { result.put(t, ONE); } else { result.put(t, new Integer(count.intValue() + 1)); } } return result; }
From source file:Main.java
/** * * @param wd//from w w w . j a v a 2 s. c om * @return the hi byte. */ public static final byte hiByte(int wd) { return (new Integer(0xff & (wd >> 8)).byteValue()); }
From source file:Main.java
private static int[] distinct(int[] iValues) { Arrays.sort(iValues);//w w w . j a va 2s . c o m List tempList = new ArrayList(); tempList.add(new Integer(iValues[0])); for (int i = 1; i < iValues.length; i++) { if (iValues[i] != iValues[i - 1]) { tempList.add(new Integer(iValues[i])); } } int[] result = new int[tempList.size()]; for (int i = 0; i < result.length; i++) { result[i] = ((Integer) tempList.get(i)).intValue(); } return result; }
From source file:Main.java
/** * Returs the low byte of an integer word. * * @param wd// ww w . j a va 2s .c o m * @return the low byte. */ public static final byte lowByte(int wd) { return (new Integer(0xff & wd).byteValue()); }
From source file:GetNumber.java
public static Number process(String s) { if (s.matches(".*[.dDeEfF]")) { try {//from w w w . j a va 2 s .c om double dValue = Double.parseDouble(s); System.out.println("It's a double: " + dValue); return new Double(dValue); } catch (NumberFormatException e) { System.out.println("Invalid a double: " + s); return NAN; } } else // did not contain . d e or f, so try as int. try { int iValue = Integer.parseInt(s); System.out.println("It's an int: " + iValue); return new Integer(iValue); } catch (NumberFormatException e2) { System.out.println("Not a number:" + s); return NAN; } }
From source file:Main.java
public static Set<Integer> toSet(int... array) { if (isEmpty(array)) { return new HashSet<>(0); }//from w ww . ja v a 2 s. com Set<Integer> set = new HashSet<>(array.length); for (int I : array) { set.add(new Integer(I)); } return set; }
From source file:Main.java
/** * Decodes an Integer.//from www. j a v a 2 s. c om * * @param xmlInteger * the xmlInteger * @return a int */ public static int decodeInteger(String xmlInteger) { return new Integer(xmlInteger).intValue(); }