コード例 #1
0
ファイル: OpenPath.java プロジェクト: BenEdridge/OpenExplorer
 /**
  * Compare two OpenPath files, with sorting taken into account
  *
  * @param fa First OpenPath
  * @param fb Second OpenPath
  * @return an int determined by comparing the two paths. Possible values are described in the
  *     Comparable interface.
  * @see Comparable
  */
 public static int compare(OpenPath fa, OpenPath fb) {
   try {
     if (fa == null && fb != null) return 1;
     if (fb == null && fa != null) return 0;
     if (fb == null || fa == null) return 0;
     if (Sorting.foldersFirst()) {
       if (fb.isDirectory() && !fa.isDirectory()) return 1;
       if (fa.isDirectory() && !fb.isDirectory()) return -1;
     }
     String a = fa.getName();
     String b = fb.getName();
     Long sa = fa.length();
     Long sb = fb.length();
     Long ma = fa.lastModified();
     Long mb = fb.lastModified();
     if (a == null && b != null) return 1;
     if (a == null || b == null) return 0;
     switch (Sorting.getType()) {
       case ALPHA_DESC:
         return b.toLowerCase().compareTo(a.toLowerCase());
       case ALPHA:
         return a.toLowerCase().compareTo(b.toLowerCase());
       case SIZE_DESC:
         if (sa == null && sb != null) return 1;
         if (sa == null || sb == null) return 0;
         return sa.compareTo(sb);
       case SIZE:
         if (sb == null && sa != null) return 1;
         if (sa == null || sb == null) return 0;
         return sb.compareTo(sa);
       case DATE_DESC:
         if (ma == null && mb != null) return 1;
         if (ma == null || mb == null) return 0;
         return ma.compareTo(mb);
       case DATE:
         if (mb == null && ma != null) return 1;
         if (ma == null || mb == null) return 0;
         return mb.compareTo(ma);
       case TYPE:
         String ea = a.substring(a.lastIndexOf(".") + 1, a.length()).toLowerCase();
         String eb = b.substring(b.lastIndexOf(".") + 1, b.length()).toLowerCase();
         return ea.compareTo(eb);
       case NONE:
         return 0;
       default:
         return a.toLowerCase().compareTo(b.toLowerCase());
     }
   } catch (Exception e) {
     Logger.LogError("Unable to sort.", e);
     return 0;
   }
 }
コード例 #2
0
ファイル: OpenPath.java プロジェクト: BenEdridge/OpenExplorer
 /**
  * Only list child directories, if any.
  *
  * @return Array of OpenPath representing child directories
  * @throws IOException
  */
 public OpenPath[] listDirectories() throws IOException {
   ArrayList<OpenPath> ret = new ArrayList<OpenPath>();
   for (OpenPath path : list()) if (path.isDirectory()) ret.add(path);
   return ret.toArray(new OpenPath[ret.size()]);
 }