Ejemplo n.º 1
0
 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);
     }
   }
 }
Ejemplo n.º 2
0
  /** 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;
  }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 public void testArraySort() {
   String[] str = new String[] {"8567", "8456"};
   jmri.util.StringUtil.sort(str);
   Assert.assertEquals("first ", "8456", str[0]);
 }