List of usage examples for java.lang Integer intValue
@HotSpotIntrinsicCandidate public int intValue()
From source file:Util.java
/** * Returns an array of indices indicating the order the data should be sorted * in. Duplicate values are discarded with the first one being kept. This method * is useful when a number of data arrays have to be sorted based on the values in * some coordinate array, such as time./*from w ww . j a v a 2s .c om*/ * * To convert a array of values to a sorted monooic array try: <br> * double[] x; // some 1-D array of data <br> * int[] i = MathUtilities.uniqueSort(x); <br> * double[] xSorted = MathUtilities.orderVector(x, i);<br><br> * * @param x An array of data that is to be sorted. * @return order An array of indexes such that y = Array.sort(x) and * y = x(order) are the same. */ public static final synchronized int[] uniqueSort(double[] x) { TreeMap tm = new TreeMap(); for (int i = 0; i < x.length; i++) { Double key = new Double(x[i]); boolean exists = tm.containsKey(key); if (exists) { // Do nothing. Ignore duplicate keys } else { tm.put(key, new Integer(i)); } } Object[] values = tm.values().toArray(); int[] order = new int[values.length]; for (int i = 0; i < values.length; i++) { Integer tmp = (Integer) values[i]; order[i] = tmp.intValue(); } return order; }
From source file:Main.java
/** * An utility function that returns the menu identifier for a particular * menu item./*from w w w . j a va 2 s.com*/ * * @param cls Class object of the class that handles the menu ite,. * @param identifier Menu identifier. * @return The integer corresponding to the menu item. */ public static int getMenuIdentifier(Class cls, String identifier) { int id = -1; try { Integer field = (Integer) cls.getDeclaredField(identifier).get(cls); id = field.intValue(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return id; }
From source file:Main.java
public static void call() { int counter = 0; Integer counterObject = threadLocal.get(); if (counterObject == null) { counter = 1;/*w w w . ja va 2 s. c om*/ } else { counter = counterObject.intValue(); counter++; } threadLocal.set(counter); String threadName = Thread.currentThread().getName(); System.out.println("Call counter for " + threadName + " = " + counter); }
From source file:Main.java
public static int nullAsNil(Integer integer) { int i;/*from w ww .j a v a 2s .c o m*/ if (integer == null) i = 0; else i = integer.intValue(); return i; }
From source file:Main.java
static void validateCompositeManifest(Map compositeManifest) throws BundleException { if (compositeManifest == null) throw new BundleException("The composite manifest cannot be null.", BundleException.MANIFEST_ERROR); //$NON-NLS-1$ // check for symbolic name if (compositeManifest.get(Constants.BUNDLE_SYMBOLICNAME) == null) throw new BundleException("The composite manifest must contain a Bundle-SymbolicName header.", //$NON-NLS-1$ BundleException.MANIFEST_ERROR); // check for invalid manifests headers for (int i = 0; i < INVALID_COMPOSITE_HEADERS.length; i++) if (compositeManifest.get(INVALID_COMPOSITE_HEADERS[i]) != null) throw new BundleException( "The composite manifest must not contain the header " + INVALID_COMPOSITE_HEADERS[i], //$NON-NLS-1$ BundleException.MANIFEST_ERROR); // validate manifest version String manifestVersion = (String) compositeManifest.get(Constants.BUNDLE_MANIFESTVERSION); if (manifestVersion == null) { compositeManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$ } else {//from w w w. jav a 2s . c om try { Integer parsed = Integer.valueOf(manifestVersion); if (parsed.intValue() > 2 || parsed.intValue() < 2) throw new BundleException("Invalid Bundle-ManifestVersion: " + manifestVersion); //$NON-NLS-1$ } catch (NumberFormatException e) { throw new BundleException("Invalid Bundle-ManifestVersion: " + manifestVersion); //$NON-NLS-1$ } } }
From source file:Main.java
/** * get a color as a int from a string, alpha is set to 255 * if we can not get the color then we return 0 *//* w w w .j ava2s. c om*/ public static int getColor(String nm) { Integer color = (Integer) stringToInt.get(nm); if (color != null) { return color.intValue(); } try { Integer result = Integer.decode(nm); // the 0xff000000 | means the alpha is 255 return 0xff000000 | result.intValue(); } catch (Exception ex) { //System.out.print("Error: unable to find color "+s+".\n"); // testing return 0; } }
From source file:Main.java
/** * Tabu refresh.//from w ww . j a va 2s . c om * @param map * @param tabu * @return map/tabu */ private static Map<Integer, Integer> tabuRefresh(Map<Integer, Integer> map, List<Integer> tabu) { Map<Integer, Integer> mapCopy = new HashMap<Integer, Integer>(); for (Map.Entry<Integer, Integer> e : map.entrySet()) { Integer key = e.getKey(); Integer value = e.getValue(); if (!tabu.contains(key.intValue())) { mapCopy.put(key, value); } } return mapCopy; }
From source file:Main.java
public static byte[] hexStringToBytes(String hex) { byte[] bytes = new byte[hex.length() / 2]; int j = 0;//from www . j a va2s .c om for (int i = 0; i < hex.length(); i += 2) { try { String hexByte = hex.substring(i, i + 2); Integer I = new Integer(0); I = Integer.decode("0x" + hexByte); int k = I.intValue(); bytes[j++] = new Integer(k).byteValue(); } catch (NumberFormatException e) { Log.d(LOG_TAG, "hexStringToBytes", e); return bytes; } catch (StringIndexOutOfBoundsException e) { Log.d(LOG_TAG, "hexStringToBytes", e); return bytes; } } return bytes; }
From source file:Main.java
@SuppressWarnings({ "rawtypes" }) private static final int getFreq(final Object obj, final Map freqMap) { Integer count = (Integer) freqMap.get(obj); if (count != null) { return count.intValue(); }/*from www. j a v a 2 s. c om*/ return 0; }
From source file:Main.java
public final static boolean syncInProgress(String atype, String aname) { String key = inProgressKey(atype, aname); synchronized (s_inprogress) { Integer v = s_inprogress.get(key); if (v == null) { return false; }/* w ww. ja v a2s .c o m*/ if (v.intValue() <= 0) { return false; } return true; } }