Package java.util

Examples of java.util.Comparator


    }
   
    File outputDir = new File(args[k++]);
   
    URI[] uris = FileUtil.listFiles(args[k++], false, "*.xml *.xsl", "");
    Arrays.sort(uris, new Comparator() {
      public int compare(Object o1, Object o2) {
        URI u1 = (URI) o1;
        URI u2 = (URI) o2;
        return (int) (new File(u1).length() - new File(u2).length());
      }     
View Full Code Here


     * Convenience method to set up the delegate respecting any comparator specified in MetaData.
     */
    protected void initialiseDelegate()
    {
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getObjectManager().getClassLoaderResolver());
        if (comparator != null)
        {
            this.delegate = new java.util.TreeSet(comparator);
        }
        else
View Full Code Here

    File[] files = new File[args.length];
    for (int i= 0; i < args.length; i++) {
      files[i] = new File(args[i]);
    }
    // sort by file size
    Arrays.sort(files, new Comparator() {
      public int compare(Object o1, Object o2) {
        File f1 = (File) o1;
        File f2 = (File) o2;
        return (int) (f1.length() - f2.length());
      }     
View Full Code Here

                {
                    //some datastores do not support backingStores
                }
            }
            // Set up our delegate, using a suitable comparator
            Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getObjectManager().getClassLoaderResolver());
            if (comparator != null)
            {
                this.delegate = new java.util.TreeSet(comparator);
            }
            else
View Full Code Here

  /**
   * Test method
   */
  public static void main(String[] args) {
    Comparator cmp = new Comparator() {
      public int compare(Object o1, Object o2) {
        return ((Comparable)o1).compareTo(o2);
      }
    };

    int n = 1000000;
    if (args.length == 1)
      try {
        n = Integer.parseInt(args[0]);
      } catch (Exception e) {
        System.err.println(e);
      }
    System.out.println("Generating " + n + " random integers...");
    java.util.Random random = new java.util.Random();
    Integer[] data = new Integer[n];
    for (int i = 0; i < n; i++) {
      data[i] = new Integer(Math.abs(random.nextInt()));
//      data[i] = new Integer(i);
    }
    int[] indices;
    long time;

    System.out.print("Arrays.sort...");
    time = System.currentTimeMillis();
    Integer[] clone = (Integer[])data.clone();
    Arrays.sort(clone, cmp);
    System.out.println(System.currentTimeMillis()-time  + "ms");

    System.out.print("quicksort...");
    indices = identity(n);
    time = System.currentTimeMillis();
    sort(indices, data, cmp, false);
    System.out.println(System.currentTimeMillis()-time  + "ms");
    for (int i = 1; i < n; i++)
      if (cmp.compare(data[indices[i-1]], data[indices[i]]) > 0)
        System.err.println("proplem: quickSort at " + i);

    System.out.print("quicksort stable...");
//    indices = identity(n);
    time = System.currentTimeMillis();
    sort(indices, data, cmp, true);
    System.out.println(System.currentTimeMillis()-time + "ms");
    for (int i = 1; i < n; i++) {
      int res = cmp.compare(data[indices[i-1]], data[indices[i]]);
      if (res > 0)
        System.err.println("proplem: quickSort stable at " + i);
      if (res == 0 && indices[i-1] > indices[i])
        System.err.println("proplem: quickSort stable (not stable) at " + i);
    }

//    System.out.print("cheapsort...");
//    time = System.currentTimeMillis();
//    indices = cheapSort(data, cmp);
//    System.out.println(System.currentTimeMillis()-time + "ms");
//    for (int i = 1; i < n; i++)
//      if (cmp.compare(data[indices[i-1]], data[indices[i]]) > 0)
//        System.err.println("proplem: cheapSort at " + i);
 
    System.out.print("permutate copy...");
    time = System.currentTimeMillis();
    Object[] data_copy = permute(inverse(indices), data, true);
    System.out.println(System.currentTimeMillis()-time + "ms");
    for (int i = 1; i < n; i++)
      if (cmp.compare(data_copy[i-1], data_copy[i]) > 0)
        System.err.println("proplem: permute copy at " + i);

    System.out.print("permutate original...");
    time = System.currentTimeMillis();
    permute(inverse(indices), data, false);
    System.out.println(System.currentTimeMillis()-time + "ms");
    for (int i = 1; i < n; i++)
      if (cmp.compare(data[i-1], data[i]) > 0)
        System.err.println("proplem: permute original at " + i);
  }
View Full Code Here

     * Convenience method to set up the delegate respecting any comparator specified in MetaData.
     */
    protected void initialiseDelegate()
    {
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getObjectManager().getClassLoaderResolver());
        if (comparator != null)
        {
            this.delegate = new java.util.TreeMap(comparator);
        }
        else
View Full Code Here

     * Convenience method to set up the delegate respecting any comparator specified in MetaData.
     */
    protected void initialiseDelegate()
    {
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getObjectManager().getClassLoaderResolver());
        if (comparator != null)
        {
            this.delegate = new java.util.TreeMap(comparator);
        }
        else
View Full Code Here

     * Convenience method to set up the delegate respecting any comparator specified in MetaData.
     */
    protected void initialiseDelegate()
    {
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getObjectManager().getClassLoaderResolver());
        if (comparator != null)
        {
            this.delegate = new java.util.PriorityQueue(5, comparator);
        }
        else
View Full Code Here

     * Convenience method to set up the delegate respecting any comparator specified in MetaData.
     */
    protected void initialiseDelegate()
    {
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getObjectManager().getClassLoaderResolver());
        if (comparator != null)
        {
            this.delegate = new java.util.TreeSet(comparator);
        }
        else
View Full Code Here

     * Convenience method to set up the delegate respecting any comparator specified in MetaData.
     */
    protected void initialiseDelegate()
    {
        AbstractMemberMetaData fmd = ownerSM.getClassMetaData().getMetaDataForMember(fieldName);
        Comparator comparator = SCOUtils.getComparator(fmd, ownerSM.getObjectManager().getClassLoaderResolver());
        if (comparator != null)
        {
            this.delegate = new java.util.PriorityQueue(5, comparator);
        }
        else
View Full Code Here

TOP

Related Classes of java.util.Comparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.