List of usage examples for java.lang Integer decode
public static Integer decode(String nm) throws NumberFormatException
From source file:org.apache.slider.common.tools.SliderUtils.java
/** * Parse an int value, replacing it with defval if undefined; * @param errorKey key to use in exceptions * @param defVal default value to use if the key is not in the map * @param min min value or -1 for do not check * @param max max value or -1 for do not check * @return the int value the integer value * @throws BadConfigException if the value could not be parsed *///w w w . j a v a2s . c om public static int parseAndValidate(String errorKey, String valS, int defVal, int min, int max) throws BadConfigException { if (valS == null) { valS = Integer.toString(defVal); } String trim = valS.trim(); int val; try { val = Integer.decode(trim); } catch (NumberFormatException e) { throw new BadConfigException("Failed to parse value of " + errorKey + ": \"" + trim + "\""); } if (min >= 0 && val < min) { throw new BadConfigException( "Value of " + errorKey + ": " + val + "" + "is less than the minimum of " + min); } if (max >= 0 && val > max) { throw new BadConfigException( "Value of " + errorKey + ": " + val + "" + "is more than the maximum of " + max); } return val; }
From source file:com.bmd.android.collection.SupportLongSparseArrayTest.java
public void testTranslations() { final LongSparseArray<Integer> array1 = AndroidCollections.iterate(mArray) .translateValues(new Translator<String, Integer>() { @Override/*from www . ja v a 2 s .c o m*/ public Integer translate(final String element) { return Integer.decode(element); } }).toSparseArray(); assertThat(AndroidCollections.iterate(array1).values()).containsExactly(0, 1, 2, 3, 4); assertThat(AndroidCollections.iterate(array1).replaceValues(new Translator<Integer, Integer>() { @Override public Integer translate(final Integer element) { return element + 1; } }).values()).containsExactly(1, 2, 3, 4, 5); assertThat(AndroidCollections.iterate(array1).values()).containsExactly(1, 2, 3, 4, 5); assertThat(AndroidCollections.iterate(array1).toImmutableList()).containsExactly( SparseEntries.entry(0L, Integer.valueOf(1)), SparseEntries.entry(1L, Integer.valueOf(2)), SparseEntries.entry(2L, Integer.valueOf(3)), SparseEntries.entry(3L, Integer.valueOf(4)), SparseEntries.entry(4L, Integer.valueOf(5))); final LongSparseArray<Integer> array2 = AndroidCollections.iterate(mArray).translate(new LongTranslator() { @Override public long translate(final long value) { return value + 1; } }, new Translator<String, Integer>() { @Override public Integer translate(final String element) { return Integer.decode(element); } }).toSparseArray(); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(1L, Integer.valueOf(0)), SparseEntries.entry(2L, Integer.valueOf(1)), SparseEntries.entry(3L, Integer.valueOf(2)), SparseEntries.entry(4L, Integer.valueOf(3)), SparseEntries.entry(5L, Integer.valueOf(4))); AndroidCollections.iterate(array1).only().first(3).putInto(array2); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(0L, Integer.valueOf(1)), SparseEntries.entry(1L, Integer.valueOf(2)), SparseEntries.entry(2L, Integer.valueOf(3)), SparseEntries.entry(3L, Integer.valueOf(2)), SparseEntries.entry(4L, Integer.valueOf(3)), SparseEntries.entry(5L, Integer.valueOf(4))); AndroidCollections.iterate(array1).only().first(3).appendTo(array2); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(0L, Integer.valueOf(1)), SparseEntries.entry(1L, Integer.valueOf(2)), SparseEntries.entry(2L, Integer.valueOf(3)), SparseEntries.entry(3L, Integer.valueOf(2)), SparseEntries.entry(4L, Integer.valueOf(3)), SparseEntries.entry(5L, Integer.valueOf(4))); AndroidCollections.iterate(array2).only().keys(2, 3).translateValues(new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "2"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array2).only().keys(2, 3).translateValues(new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).appendTo(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "2"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array2).only().last(1).translate(new LongTranslator() { @Override public long translate(final long value) { return value - 2; } }, new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "4"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array2).only().last(1).translate(new LongTranslator() { @Override public long translate(final long value) { return value - 2; } }, new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).appendTo(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "4"), SparseEntries.entry(4L, "4")); final LongSparseArray<String> array3 = AndroidCollections.iterate(mArray).toSparseArray(); assertThat(AndroidCollections.iterate(array3).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "4"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array3).but().last(1).translateKeys(new LongTranslator() { @Override public long translate(final long value) { return value + 2; } }).appendTo(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "0"), SparseEntries.entry(3L, "1"), SparseEntries.entry(4L, "3"), SparseEntries.entry(5L, "4")); AndroidCollections.iterate(array3).but().last(1).translateKeys(new LongTranslator() { @Override public long translate(final long value) { return value + 2; } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "0"), SparseEntries.entry(3L, "1"), SparseEntries.entry(4L, "3"), SparseEntries.entry(5L, "4")); }
From source file:com.bmd.android.collection.SimpleArrayMapTest.java
public void testTranslations() { final SimpleArrayMap<Integer, Integer> array1 = AndroidCollections.iterate(mArray) .translateValues(new Translator<String, Integer>() { @Override//from w ww . j a v a 2 s . c o m public Integer translate(final String element) { return Integer.decode(element); } }).toSparseArray(); assertThat(AndroidCollections.iterate(array1).values()).containsExactly(0, 1, 2, 3, 4); assertThat(AndroidCollections.iterate(array1).replaceValues(new Translator<Integer, Integer>() { @Override public Integer translate(final Integer element) { return element + 1; } }).values()).containsExactly(1, 2, 3, 4, 5); assertThat(AndroidCollections.iterate(array1).values()).containsExactly(1, 2, 3, 4, 5); assertThat(AndroidCollections.iterate(array1).toImmutableList()).containsExactly( SparseEntries.entry(Integer.valueOf(0), Integer.valueOf(1)), SparseEntries.entry(Integer.valueOf(1), Integer.valueOf(2)), SparseEntries.entry(Integer.valueOf(2), Integer.valueOf(3)), SparseEntries.entry(Integer.valueOf(3), Integer.valueOf(4)), SparseEntries.entry(Integer.valueOf(4), Integer.valueOf(5))); final SimpleArrayMap<Integer, Integer> array2 = AndroidCollections.iterate(mArray) .translate(new Translator<Integer, Integer>() { @Override public Integer translate(final Integer value) { return value + 1; } }, new Translator<String, Integer>() { @Override public Integer translate(final String element) { return Integer.decode(element); } }) .toSparseArray(); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(Integer.valueOf(1), Integer.valueOf(0)), SparseEntries.entry(Integer.valueOf(2), Integer.valueOf(1)), SparseEntries.entry(Integer.valueOf(3), Integer.valueOf(2)), SparseEntries.entry(Integer.valueOf(4), Integer.valueOf(3)), SparseEntries.entry(Integer.valueOf(5), Integer.valueOf(4))); AndroidCollections.iterate(array1).only().first(3).putInto(array2); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(Integer.valueOf(0), Integer.valueOf(1)), SparseEntries.entry(Integer.valueOf(1), Integer.valueOf(2)), SparseEntries.entry(Integer.valueOf(2), Integer.valueOf(3)), SparseEntries.entry(Integer.valueOf(3), Integer.valueOf(2)), SparseEntries.entry(Integer.valueOf(4), Integer.valueOf(3)), SparseEntries.entry(Integer.valueOf(5), Integer.valueOf(4))); AndroidCollections.iterate(array2).only().keys(2, 3).translateValues(new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(Integer.valueOf(0), "0"), SparseEntries.entry(Integer.valueOf(1), "1"), SparseEntries.entry(Integer.valueOf(2), "3"), SparseEntries.entry(Integer.valueOf(3), "2"), SparseEntries.entry(Integer.valueOf(4), "4")); AndroidCollections.iterate(array2).only().last(1).translate(new Translator<Integer, Integer>() { @Override public Integer translate(final Integer value) { return value - 2; } }, new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(Integer.valueOf(0), "0"), SparseEntries.entry(Integer.valueOf(1), "1"), SparseEntries.entry(Integer.valueOf(2), "3"), SparseEntries.entry(Integer.valueOf(3), "4"), SparseEntries.entry(Integer.valueOf(4), "4")); final SimpleArrayMap<Integer, String> array3 = AndroidCollections.iterate(mArray).toSparseArray(); assertThat(AndroidCollections.iterate(array3).toImmutableList()).containsExactly( SparseEntries.entry(Integer.valueOf(0), "0"), SparseEntries.entry(Integer.valueOf(1), "1"), SparseEntries.entry(Integer.valueOf(2), "3"), SparseEntries.entry(Integer.valueOf(3), "4"), SparseEntries.entry(Integer.valueOf(4), "4")); AndroidCollections.iterate(array3).but().last(1).translateKeys(new Translator<Integer, Integer>() { @Override public Integer translate(final Integer value) { return value + 2; } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(Integer.valueOf(0), "0"), SparseEntries.entry(Integer.valueOf(1), "1"), SparseEntries.entry(Integer.valueOf(2), "0"), SparseEntries.entry(Integer.valueOf(3), "1"), SparseEntries.entry(Integer.valueOf(4), "3"), SparseEntries.entry(Integer.valueOf(5), "4")); }
From source file:com.bmd.android.collection.LongSparseArrayTest.java
public void testTranslations() { if (VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN) { return;/*from w w w . ja v a2 s. c om*/ } final LongSparseArray<Integer> array1 = AndroidCollections.iterate(mArray) .translateValues(new Translator<String, Integer>() { @Override public Integer translate(final String element) { return Integer.decode(element); } }).toSparseArray(); assertThat(AndroidCollections.iterate(array1).values()).containsExactly(0, 1, 2, 3, 4); assertThat(AndroidCollections.iterate(array1).replaceValues(new Translator<Integer, Integer>() { @Override public Integer translate(final Integer element) { return element + 1; } }).values()).containsExactly(1, 2, 3, 4, 5); assertThat(AndroidCollections.iterate(array1).values()).containsExactly(1, 2, 3, 4, 5); assertThat(AndroidCollections.iterate(array1).toImmutableList()).containsExactly( SparseEntries.entry(0L, Integer.valueOf(1)), SparseEntries.entry(1L, Integer.valueOf(2)), SparseEntries.entry(2L, Integer.valueOf(3)), SparseEntries.entry(3L, Integer.valueOf(4)), SparseEntries.entry(4L, Integer.valueOf(5))); final LongSparseArray<Integer> array2 = AndroidCollections.iterate(mArray).translate(new LongTranslator() { @Override public long translate(final long value) { return value + 1; } }, new Translator<String, Integer>() { @Override public Integer translate(final String element) { return Integer.decode(element); } }).toSparseArray(); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(1L, Integer.valueOf(0)), SparseEntries.entry(2L, Integer.valueOf(1)), SparseEntries.entry(3L, Integer.valueOf(2)), SparseEntries.entry(4L, Integer.valueOf(3)), SparseEntries.entry(5L, Integer.valueOf(4))); AndroidCollections.iterate(array1).only().first(3).putInto(array2); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(0L, Integer.valueOf(1)), SparseEntries.entry(1L, Integer.valueOf(2)), SparseEntries.entry(2L, Integer.valueOf(3)), SparseEntries.entry(3L, Integer.valueOf(2)), SparseEntries.entry(4L, Integer.valueOf(3)), SparseEntries.entry(5L, Integer.valueOf(4))); AndroidCollections.iterate(array1).only().first(3).appendTo(array2); assertThat(AndroidCollections.iterate(array2).toImmutableList()).containsExactly( SparseEntries.entry(0L, Integer.valueOf(1)), SparseEntries.entry(1L, Integer.valueOf(2)), SparseEntries.entry(2L, Integer.valueOf(3)), SparseEntries.entry(3L, Integer.valueOf(2)), SparseEntries.entry(4L, Integer.valueOf(3)), SparseEntries.entry(5L, Integer.valueOf(4))); AndroidCollections.iterate(array2).only().keys(2, 3).translateValues(new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "2"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array2).only().keys(2, 3).translateValues(new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).appendTo(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "2"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array2).only().last(1).translate(new LongTranslator() { @Override public long translate(final long value) { return value - 2; } }, new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "4"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array2).only().last(1).translate(new LongTranslator() { @Override public long translate(final long value) { return value - 2; } }, new Translator<Integer, String>() { @Override public String translate(final Integer element) { return element.toString(); } }).appendTo(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "4"), SparseEntries.entry(4L, "4")); final LongSparseArray<String> array3 = AndroidCollections.iterate(mArray).toSparseArray(); assertThat(AndroidCollections.iterate(array3).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "3"), SparseEntries.entry(3L, "4"), SparseEntries.entry(4L, "4")); AndroidCollections.iterate(array3).but().last(1).translateKeys(new LongTranslator() { @Override public long translate(final long value) { return value + 2; } }).appendTo(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "0"), SparseEntries.entry(3L, "1"), SparseEntries.entry(4L, "3"), SparseEntries.entry(5L, "4")); AndroidCollections.iterate(array3).but().last(1).translateKeys(new LongTranslator() { @Override public long translate(final long value) { return value + 2; } }).putInto(mArray); assertThat(AndroidCollections.iterate(mArray).toImmutableList()).containsExactly( SparseEntries.entry(0L, "0"), SparseEntries.entry(1L, "1"), SparseEntries.entry(2L, "0"), SparseEntries.entry(3L, "1"), SparseEntries.entry(4L, "3"), SparseEntries.entry(5L, "4")); }
From source file:de.ribeiro.android.gso.core.UntisProvider.java
/** * @param weekData WeekData, das bereinigt werden soll * @return WeekData, das bereinigt wurde * @author Tobias Janssen Entfernt doppelte Reihen und Spalten *//*from ww w . ja v a 2 s. c o m*/ private static WeekData removeDubColsnRows(WeekData weekData) { Xml[][] tempTimeTable = new Xml[0][0]; Boolean dub = false; // zuerst alle Zeilen prfen, ob diese gleich der nchsten ist for (int y = 0; y + 1 < weekData.timetable.length; y++) { dub = true; for (int x = 0; x < weekData.timetable.length && dub; x++) { if (!weekData.timetable[y + 1][x].equals(weekData.timetable[y][x]) && dub) { dub = false; } } if (!dub) { // alle nicht Dublicate werden dem neuen array hinzugefgt tempTimeTable = (Xml[][]) ArrayOperations.AppendToArray(tempTimeTable, weekData.timetable[y]); } } tempTimeTable = (Xml[][]) ArrayOperations.AppendToArray(tempTimeTable, weekData.timetable[weekData.timetable.length - 1]); // fingerprints(strings aus 0 und 1) fr jede zeile erstellen. 1 zeigt, // dass dieses feld mit dem vorgnger gleich ist String[] print = new String[weekData.timetable.length]; for (int y = 0; y < weekData.timetable.length; y++) { print[y] = fingerprintOfDubs(weekData.timetable[y]); } // nun mssen die fingerprints aller Array zeilen zusammengefgt werden int sum = 0; String printRes = ""; for (int y = 0; y < print.length; y++) { sum = 0; for (int x = 0; x < print[y].length(); x++) { sum += Integer.decode(String.valueOf(print[y].charAt(x))); } if (sum != 0) { printRes += "1"; } else { printRes += "0"; } } // es ist eine fingerabdruck fr ein zweidimensinales array entstanden, // an hand diesem kann nun ein neues array erstellt werden, dass keine // dublicate hat int count = -1; // zhlen der 0en fr die lnge einer zeile, denn diese sind kein // dublicat. for (int y = 0; y < printRes.length() && count == -1; y++) { if (String.valueOf(printRes.charAt(y)).equalsIgnoreCase("0")) { count = print[y].length(); } } // das neue array fr das ergebnis erstellen weekData.timetable = new Xml[tempTimeTable.length][count]; Point point = new Point(); // das vorherige ergenis nutzen wir nun um mit hilfe des fingerprints // das neue array zu fllen for (int y = 0; y < tempTimeTable.length; y++) { for (int x = 0; x < tempTimeTable[y].length; x++) { // nur 0en, also nicht dublicate hinzufgen if (String.valueOf(printRes.charAt(x)).equalsIgnoreCase("0")) { // das feld hinzufgen point = getLastFreePosition(weekData); System.arraycopy(tempTimeTable[y], x, weekData.timetable[point.y], point.x, 1); } } } return weekData; }
From source file:org.openhab.binding.dscalarm1.internal.DSCAlarmActiveBinding.java
/** * Handle Keypad LED events for the EyezOn Envisalink 3/2DS DSC Alarm Interface * * @param event/* w w w.ja v a 2s. c o m*/ */ private void keypadLEDStateEventHandler(EventObject event) { DSCAlarmEvent dscAlarmEvent = (DSCAlarmEvent) event; APIMessage apiMessage = dscAlarmEvent.getAPIMessage(); DSCAlarmItemType[] dscAlarmItemTypes = { DSCAlarmItemType.KEYPAD_READY_LED, DSCAlarmItemType.KEYPAD_ARMED_LED, DSCAlarmItemType.KEYPAD_MEMORY_LED, DSCAlarmItemType.KEYPAD_BYPASS_LED, DSCAlarmItemType.KEYPAD_TROUBLE_LED, DSCAlarmItemType.KEYPAD_PROGRAM_LED, DSCAlarmItemType.KEYPAD_FIRE_LED, DSCAlarmItemType.KEYPAD_BACKLIGHT_LED }; String itemName; APICode apiCode = APICode.getAPICodeValue(apiMessage.getAPICode()); int bitField = Integer.decode("0x" + apiMessage.getAPIData()); int[] masks = { 1, 2, 4, 8, 16, 32, 64, 128 }; int[] bits = new int[8]; for (int i = 0; i < 8; i++) { bits[i] = bitField & masks[i]; itemName = getItemName(dscAlarmItemTypes[i], 0, 0); if (StringUtils.isNotEmpty(itemName)) { switch (apiCode) { case KeypadLEDState: /* 510 */ updateItem(itemName, bits[i] != 0 ? 1 : 0, ""); break; case KeypadLEDFlashState: /* 511 */ if (bits[i] != 0) { updateItem(itemName, 2, ""); } break; default: break; } } } }
From source file:org.topazproject.otm.stores.ItqlStore.java
private List<String> execCollectionsQry(String qry, ItqlStoreConnection isc) throws OtmException { if (log.isDebugEnabled()) log.debug("rdf:List/rdf:Bag query : " + qry); List<Answer> ans;/*from w w w .j av a2 s . c om*/ try { ans = isc.getItqlClient().doQuery(qry); } catch (IOException ioe) { throw new OtmException("error performing rdf:List/rdf:Bag query", ioe); } catch (AnswerException ae) { throw new OtmException("error performing rdf:List/rdf:Bag query", ae); } List<String> res = new ArrayList<String>(); try { // check if we got something useful Answer qa = ans.get(0); if (qa.getVariables() == null) throw new OtmException("query failed: " + qa.getMessage()); // collect the results, qa.beforeFirst(); boolean isRdfList = qa.indexOf("n") != -1; if (isRdfList) { Map<String, String> fwd = new HashMap<String, String>(); Map<String, String> rev = new HashMap<String, String>(); Map<String, String> objs = new HashMap<String, String>(); while (qa.next()) { String assoc = qa.getString("o"); String node = qa.getString(1); String next = qa.getString(2); objs.put(node, assoc); fwd.put(node, next); rev.put(next, node); } if (objs.size() == 0) return res; String first = rev.keySet().iterator().next(); while (rev.containsKey(first)) first = rev.get(first); for (String n = first; fwd.get(n) != null; n = fwd.get(n)) res.add(objs.get(n)); } else { while (qa.next()) { String p = qa.getString("p"); if (!p.startsWith(Rdf.rdf + "_")) continue; // an un-recognized predicate int i = Integer.decode(p.substring(Rdf.rdf.length() + 1)) - 1; while (i >= res.size()) res.add(null); String assoc = qa.getString("o"); res.set(i, assoc); } } qa.close(); } catch (AnswerException ae) { throw new OtmException("Error parsing answer", ae); } return res; }
From source file:org.openhab.binding.dscalarm.internal.DSCAlarmActiveBinding.java
/** * Handle Keypad LED events for the EyezOn Envisalink 3/2DS DSC Alarm Interface * /*from w ww . j av a 2 s . c o m*/ * @param event */ private void keypadLEDStateEventHandler(EventObject event) { DSCAlarmEvent dscAlarmEvent = (DSCAlarmEvent) event; APIMessage apiMessage = dscAlarmEvent.getAPIMessage(); DSCAlarmItemType[] dscAlarmItemTypes = { DSCAlarmItemType.KEYPAD_READY_LED, DSCAlarmItemType.KEYPAD_ARMED_LED, DSCAlarmItemType.KEYPAD_MEMORY_LED, DSCAlarmItemType.KEYPAD_BYPASS_LED, DSCAlarmItemType.KEYPAD_TROUBLE_LED, DSCAlarmItemType.KEYPAD_PROGRAM_LED, DSCAlarmItemType.KEYPAD_FIRE_LED, DSCAlarmItemType.KEYPAD_BACKLIGHT_LED }; String itemName; APICode apiCode = APICode.getAPICodeValue(apiMessage.getAPICode()); int bitField = Integer.decode("0x" + apiMessage.getAPIData()); int[] masks = { 1, 2, 4, 8, 16, 32, 64, 128 }; int[] bits = new int[8]; for (int i = 0; i < 8; i++) { bits[i] = bitField & masks[i]; itemName = getItemName(dscAlarmItemTypes[i], 0, 0); if (itemName != "") { switch (apiCode) { case KeypadLEDState: /*510*/ updateDeviceProperties(itemName, bits[i] != 0 ? 1 : 0, ""); break; case KeypadLEDFlashState: /*511*/ if (bits[i] != 0) { updateDeviceProperties(itemName, 2, ""); } break; default: break; } updateItem(itemName); } } }
From source file:org.ohmage.query.impl.SurveyUploadQuery.java
/** * Initializes the directory structure by drilling down to the leaf * directory with each step choosing the directory with the largest * integer value./* w ww .j a v a 2 s. c o m*/ */ private synchronized void init(int numFilesPerDirectory) throws DataAccessException { try { // If the current leaf directory has been set, we weren't the // first to call init(), so we can just back out. if (imageLeafDirectory != null) { return; } // Get the root directory from the preference cache based on the // key. String rootFile; try { rootFile = PreferenceCache.instance().lookup(PreferenceCache.KEY_IMAGE_DIRECTORY); } catch (CacheMissException e) { throw new DataAccessException( "Preference cache doesn't know about 'known' key: " + PreferenceCache.KEY_IMAGE_DIRECTORY, e); } File rootDirectory = new File(rootFile); if (!rootDirectory.exists()) { throw new DataAccessException( "The root file doesn't exist suggesting an incomplete installation: " + rootFile); } else if (!rootDirectory.isDirectory()) { throw new DataAccessException("The root file isn't a directory."); } // Get the number of folders deep that documents are stored. int fileDepth; try { fileDepth = Integer .decode(PreferenceCache.instance().lookup(PreferenceCache.KEY_FILE_HIERARCHY_DEPTH)); } catch (CacheMissException e) { throw new DataAccessException("Preference cache doesn't know about 'known' key: " + PreferenceCache.KEY_FILE_HIERARCHY_DEPTH, e); } catch (NumberFormatException e) { throw new DataAccessException("Stored value for key '" + PreferenceCache.KEY_FILE_HIERARCHY_DEPTH + "' is not decodable as a number.", e); } DirectoryFilter directoryFilter = new DirectoryFilter(); File currDirectory = rootDirectory; for (int currDepth = 0; currDepth < fileDepth; currDepth++) { // Get the list of directories in the current directory. File[] currDirectories = currDirectory.listFiles(directoryFilter); // If there aren't any, create the first subdirectory in this // directory. if (currDirectories.length == 0) { String newFolderName = directoryNameBuilder(0, numFilesPerDirectory); currDirectory = new File(currDirectory.getAbsolutePath() + "/" + newFolderName); currDirectory.mkdir(); } // If the directory is overly full, step back up in the // structure. This should never happen, as it indicates that // there is an overflow in the structure. else if (currDirectories.length > numFilesPerDirectory) { LOGGER.warn("Too many subdirectories in: " + currDirectory.getAbsolutePath()); // Take a step back in our depth. currDepth--; // If, while backing up the tree, we back out of the root // directory, we have filled up the space. if (currDepth < 0) { LOGGER.error("Image directory structure full!"); throw new DataAccessException("Image directory structure full!"); } // Get the next parent and the current directory to it. int nextDirectoryNumber = Integer.decode(currDirectory.getName()) + 1; currDirectory = new File(currDirectory.getParent() + "/" + nextDirectoryNumber); // If the directory already exists, then there is either a // concurrency issue or someone else is adding files. // Either way, this shouldn't happen. if (currDirectory.exists()) { LOGGER.error("Somehow the 'new' directory already exists. This should be looked into: " + currDirectory.getAbsolutePath()); } // Otherwise, create the directory. else { currDirectory.mkdir(); } } // Drill down to the directory with the largest, numeric value. else { currDirectory = getLargestSubfolder(currDirectories); } } // After we have found a suitable directory, set it. imageLeafDirectory = currDirectory; } catch (SecurityException e) { throw new DataAccessException( "The current process doesn't have sufficient permiossions to create new directories.", e); } }