Package java.util

Examples of java.util.Comparator.compare()


            SortField sortField = iterator.next();
            SortOrder sortOrder = sortField.getSortOrder();
            if (sortOrder != null && !SortOrder.unsorted.equals(sortOrder)) {
                Comparator comparator = sortField.getComparator();
                if (comparator != null) {
                    result = comparator.compare(object1, object2);
                } else {
                    ValueExpression sortBy = sortField.getSortBy();
                    if (sortBy != null) {
                        updateVar(context, var, object1);
                        Object value1 = sortBy.getValue(context.getELContext());
View Full Code Here


  }

  public int compare(Object[] o1, Object[] o2) {
    for (int i = 0; i < comparators.length; i++) {
      Comparator comparator = comparators[i];
      int c = comparator.compare(o1[i], o2[i]);
      if (c != 0) {
        return c;
      }
    }
    return 0;
View Full Code Here

      if (actual.size() == 0) return;
      Comparator rawComparator = comparator;
      if (actual.size() == 1) {
        // Compare unique element with itself to verify that it is compatible with comparator (a ClassCastException is
        // thrown if not). We have to use a raw comparator to compare the unique element of actual ... :(
        rawComparator.compare(actual.get(0), actual.get(0));
        return;
      }
      for (int i = 0; i < actual.size() - 1; i++) {
        // List is sorted in comparator defined order if current element is less or equal than next element
        if (rawComparator.compare(actual.get(i), actual.get(i + 1)) > 0)
View Full Code Here

        rawComparator.compare(actual.get(0), actual.get(0));
        return;
      }
      for (int i = 0; i < actual.size() - 1; i++) {
        // List is sorted in comparator defined order if current element is less or equal than next element
        if (rawComparator.compare(actual.get(i), actual.get(i + 1)) > 0)
          throw failures.failure(info, shouldBeSortedAccordingToGivenComparator(i, actual, comparator));
      }
    } catch (ClassCastException e) {
      throw failures.failure(info, shouldHaveComparableElementsAccordingToGivenComparator(actual, comparator));
    }
View Full Code Here

            // compare by value first
            for(int d = 0; d < aEffectiveLength && d < bEffectiveLength; d++) {
                Comparator comparator = format.getComparator(d);
                if (comparator == null) return 0;
                int result = comparator.compare(a.path.get(d), b.path.get(d));
                if(result != 0) return result;
            }

            // and path length second
            return aEffectiveLength - bEffectiveLength;
View Full Code Here

     *     then depth 3 corresponds to the element <code>yarmo.mp4</code>.
     */
    private boolean valuesEqual(int depth, E a, E b) {
        Comparator comparator = format.getComparator(depth);
        if (comparator != null) {
            return comparator.compare(a, b) == 0;
        } else {
            return GlazedListsImpl.equal(a, b);
        }
    }

View Full Code Here

                // compare by value first
                for(int d = 0; d < aPathLength && d < bPathLength; d++) {
                    Comparator comparator = format.getComparator(d);
                    if (comparator == null) return 0;
                    int result = comparator.compare(a.get(d), b.get(d));
                    if(result != 0) return result;
                }

                // and path length second
                return aPathLength - bPathLength;
View Full Code Here

     * Tests that comparison by property works.
     */
    public void testCompare() {
        Comparator comparator = GlazedLists.beanPropertyComparator(Position.class, "position", new String[0]);

        assertTrue(comparator.compare(new Position(4), new Position(1)) > 0);
        assertTrue(comparator.compare(new Position(1), new Position(4)) < 0);
        assertTrue(comparator.compare(new Position(3), new Position(3)) == 0);
    }

    /**
 
View Full Code Here

     */
    public void testCompare() {
        Comparator comparator = GlazedLists.beanPropertyComparator(Position.class, "position", new String[0]);

        assertTrue(comparator.compare(new Position(4), new Position(1)) > 0);
        assertTrue(comparator.compare(new Position(1), new Position(4)) < 0);
        assertTrue(comparator.compare(new Position(3), new Position(3)) == 0);
    }

    /**
     * Tests that the equals() method of the comparator works.
View Full Code Here

    public void testCompare() {
        Comparator comparator = GlazedLists.beanPropertyComparator(Position.class, "position", new String[0]);

        assertTrue(comparator.compare(new Position(4), new Position(1)) > 0);
        assertTrue(comparator.compare(new Position(1), new Position(4)) < 0);
        assertTrue(comparator.compare(new Position(3), new Position(3)) == 0);
    }

    /**
     * Tests that the equals() method of the comparator works.
     */
 
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.