/* * provide a string representation of this XBee Node */ @Override public String toString() { return "(" + jmri.util.StringUtil.hexStringFromBytes(getUserAddress()) + "," + jmri.util.StringUtil.hexStringFromBytes(getGlobalAddress()) + "," + getIdentifier() + ")"; }
/** * Get the prefered name for this XBee Node. * * @return the Identifier string if it is not blank then a string representation of the bytes of * the 16 bit address if it is not a broadcast address. Otherwise return the 64 bit GUID. */ public String getPreferedName() { if (!Identifier.equals("")) { return Identifier; } else if (!(getXBeeAddress16().equals(XBee16BitAddress.BROADCAST_ADDRESS)) && !(getXBeeAddress16().equals(XBee16BitAddress.UNKNOWN_ADDRESS))) { return jmri.util.StringUtil.hexStringFromBytes(useraddress); } else { return jmri.util.StringUtil.hexStringFromBytes(globaladdress); } }
public XBeeNode(byte pan[], byte user[], byte global[]) { super(pan, user, global); Identifier = ""; if (log.isDebugEnabled()) { log.debug( "Created new node with panId: " + StringUtil.arrayToString(pan) + " userId: " + StringUtil.arrayToString(user) + " and GUID: " + StringUtil.arrayToString(global)); } pinObjects = new HashMap<Integer, NamedBean>(); isPolled = false; userAddress = new XBee16BitAddress(user); globalAddress = new XBee64BitAddress(global); }
public void setNames(String[] names) { if (names.length == 0) { return; } jmri.util.StringUtil.sort(names); for (String name : names) { if (!list.contains(name)) { list.add(name); } } }
/** Get an array of all the RosterEntry-containing files in the target directory */ static String[] getAllFileNames() { // ensure preferences will be found for read FileUtil.createDirectory(LocoFile.getFileLocation()); // create an array of file names from roster dir in preferences, count entries int i; int np = 0; String[] sp = null; if (log.isDebugEnabled()) { log.debug("search directory " + LocoFile.getFileLocation()); } File fp = new File(LocoFile.getFileLocation()); if (fp.exists()) { sp = fp.list(); if (sp != null) { for (i = 0; i < sp.length; i++) { if (sp[i].endsWith(".xml") || sp[i].endsWith(".XML")) { np++; } } } else { log.warn("expected directory, but {} was a file", LocoFile.getFileLocation()); } } else { log.warn( FileUtil.getUserFilesPath() + "roster directory was missing, though tried to create it"); } // Copy the entries to the final array String sbox[] = new String[np]; int n = 0; if (sp != null && np > 0) { for (i = 0; i < sp.length; i++) { if (sp[i].endsWith(".xml") || sp[i].endsWith(".XML")) { sbox[n++] = sp[i]; } } } // The resulting array is now sorted on file-name to make it easier // for humans to read jmri.util.StringUtil.sort(sbox); if (log.isDebugEnabled()) { log.debug("filename list:"); for (i = 0; i < sbox.length; i++) { log.debug(" " + sbox[i]); } } return sbox; }
/** * Sort by rolling stock id * * @return list of RollingStock ordered by id */ public List<RollingStock> getByIdList() { Enumeration<String> en = _hashTable.keys(); String[] arr = new String[_hashTable.size()]; List<RollingStock> out = new ArrayList<RollingStock>(); int i = 0; while (en.hasMoreElements()) { arr[i] = en.nextElement(); i++; } jmri.util.StringUtil.sort(arr); for (i = 0; i < arr.length; i++) { out.add(getById(arr[i])); } return out; }
/** * Notify that the ID of an entry has changed. This doesn't actually change the Roster per se, but * triggers recreation. * * @param r The RosterEntry that has changed. */ public void entryIdChanged(RosterEntry r) { log.debug("EntryIdChanged"); // order may be wrong! Sort RosterEntry[] rarray = new RosterEntry[_list.size()]; for (int i = 0; i < rarray.length; i++) { rarray[i] = _list.get(i); } StringUtil.sortUpperCase(rarray); for (int i = 0; i < rarray.length; i++) { _list.set(i, rarray[i]); } firePropertyChange(CHANGE, null, r); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION") // Only used occasionally, so inefficient String processing not really a problem // though it would be good to fix it if you're working in this area public String toString() { String s = ""; if (!QsiTrafficController.instance().isSIIBootMode()) { for (int i = 0; i < _nDataChars; i++) { s += jmri.util.StringUtil.twoHexFromInt(_dataChars[i]) + " "; } } else { for (int i = 0; i < _nDataChars; i++) { s += "<" + _dataChars[i] + ">"; } } return s; }
/** * Performs number sort before adding to list * * @param lengths The set of strings to be ordered. */ public void setValues(String[] lengths) { if (lengths.length == 0) { return; } try { jmri.util.StringUtil.numberSort(lengths); } catch (NumberFormatException e) { log.error("lengths are not all numeric, list:"); for (int i = 0; i < lengths.length; i++) { try { Integer.parseInt(lengths[i]); log.error("length " + i + " = " + lengths[i]); } catch (NumberFormatException ee) { log.error("length " + i + " = " + lengths[i] + " is not a valid number!"); } } } for (String length : lengths) { if (!list.contains(length)) { list.add(length); } } }
public String toMonitorString() { // check for valid length int len = getNumDataElements(); StringBuilder text = new StringBuilder(); if ((getElement(0) & 0xFF) != Constants.HEAD_STX) { text.append("INVALID HEADER: " + String.format("0x%1X", getElement(0) & 0xFF)); text.append(" len: " + len); } else { switch (getElement(1) & 0xFF) { case Constants.FUNCTION_REQ_STD: text.append("Send Cmd "); if (len == 8 || len == 22) { if ((getElement(5) & Constants.FLAG_BIT_STDEXT) == Constants.FLAG_STD) { text.append(" Std"); } else if (len == 22) { text.append(" Ext"); } switch (getElement(5) & Constants.FLAG_MASK_MSGTYPE) { case Constants.FLAG_TYPE_P2P: text.append(" Direct"); break; case Constants.FLAG_TYPE_ACK: text.append(" ACK"); break; case Constants.FLAG_TYPE_NAK: text.append(" NAK"); break; case Constants.FLAG_TYPE_GBCAST: text.append(" Group Broadcast"); break; case Constants.FLAG_TYPE_GBCLEANUP: text.append(" Group Broadcast Cleanup"); break; case Constants.FLAG_TYPE_GBCLEANACK: text.append(" Group Broadcast Cleanup ACK"); break; case Constants.FLAG_TYPE_GBCLEANNAK: text.append(" Group Broadcast Cleanup NAK"); break; } text.append(" message,"); text.append( String.format( " %d hops left", (getElement(5) & Constants.FLAG_MASK_HOPSLEFT >> Constants.FLAG_SHIFT_HOPSLEFT))); text.append( String.format(" , %d max hops", (getElement(5) & Constants.FLAG_MASK_MAXHOPS))); text.append( " addr " + String.format( "%1$X.%2$X.%3$X", (getElement(2) & 0xFF), (getElement(3) & 0xFF), (getElement(4) & 0xFF))); switch (getElement(6) & 0xFF) { case Constants.CMD_LIGHT_ON_RAMP: text.append(" ON RAMP "); text.append((getElement(7) & 0xFF) / 256.0); break; case Constants.CMD_LIGHT_ON_FAST: text.append(" ON FAST "); text.append((getElement(7) & 0xFF) / 256.0); break; case Constants.CMD_LIGHT_OFF_FAST: text.append(" OFF FAST "); text.append((getElement(7) & 0xFF) / 256.0); break; case Constants.CMD_LIGHT_OFF_RAMP: text.append(" OFF "); text.append((getElement(7) & 0xFF) / 256.0); break; case Constants.CMD_LIGHT_CHG: text.append(" CHG "); text.append((getElement(7) & 0xFF) / 256.0); break; default: text.append(" Unknown cmd: " + StringUtil.twoHexFromInt(getElement(6) & 0xFF)); break; } } else { text.append(" !! Length wrong: " + len); } break; // i wrote this then figured the POLL are replies // case Constants.POLL_REQ_BUTTON : // text.append("Poll Button "); // int button = ((getElement(2) & Constants.BUTTON_BITS_ID) >> 4) + 1; // text.append(button); // int op = getElement(2) & Constants.BUTTON_BITS_OP; // if (op == Constants.BUTTON_HELD) { // text.append(" HELD"); // } else if (op == Constants.BUTTON_REL) { // text.append(" RELEASED"); // } else if (op == Constants.BUTTON_TAP) { // text.append(" TAP"); // } // break; // case Constants.POLL_REQ_BUTTON_RESET : // text.append("Reset by Button at Power Cycle"); // break; case Constants.FUNCTION_REQ_X10: text.append("Send Cmd X10 "); if ((getElement(3) & Constants.FLAG_BIT_X10_CMDUNIT) == Constants.FLAG_X10_RECV_CMD) { text.append(X10Sequence.formatCommandByte(getElement(2) & 0xFF)); } else { text.append(X10Sequence.formatAddressByte(getElement(2) & 0xFF)); } break; // case Constants.POLL_REQ_X10 : // text.append("Poll Cmd X10 "); // if ((getElement(3)& Constants.FLAG_BIT_X10_CMDUNIT) == // Constants.FLAG_X10_RECV_CMD) { // text.append(X10Sequence.formatCommandByte(getElement(2) & 0xFF)); // } else { // text.append(X10Sequence.formatAddressByte(getElement(2)& 0xFF)); // } // break; default: { text.append(" Unknown command: " + StringUtil.twoHexFromInt(getElement(1) & 0xFF)); text.append(" len: " + len); } } } return text + "\n"; }
public void testArraySort() { String[] str = new String[] {"8567", "8456"}; jmri.util.StringUtil.sort(str); Assert.assertEquals("first ", "8456", str[0]); }