Example usage for org.jfree.chart.util SortOrder DESCENDING

List of usage examples for org.jfree.chart.util SortOrder DESCENDING

Introduction

In this page you can find the example usage for org.jfree.chart.util SortOrder DESCENDING.

Prototype

SortOrder DESCENDING

To view the source code for org.jfree.chart.util SortOrder DESCENDING.

Click Source Link

Document

Descending order.

Usage

From source file:org.jfree.data.KeyedObjectComparator.java

/**
 * Compares two {@link KeyedValue} instances and returns an
 * <code>int</code> that indicates the relative order of the two objects.
 *
 * @param o1  object 1.//from w  ww  .j  a va  2 s  .c o m
 * @param o2  object 2.
 *
 * @return An int indicating the relative order of the objects.
 */
public int compare(Object o1, Object o2) {

    if (o2 == null) {
        return -1;
    }
    if (o1 == null) {
        return 1;
    }

    KeyedObject ko1 = (KeyedObject) o1;
    KeyedObject ko2 = (KeyedObject) o2;

    if (this.type == KeyedObjectComparatorType.BY_KEY) {
        if (this.order.equals(SortOrder.ASCENDING)) {
            return ko1.getKey().compareTo(ko2.getKey());
        } else if (this.order.equals(SortOrder.DESCENDING)) {
            return ko2.getKey().compareTo(ko1.getKey());
        } else {
            throw new IllegalArgumentException("Unrecognised sort order.");
        }
    } else if (this.type == KeyedObjectComparatorType.BY_VALUE) {
        Object n1 = ko1.getObject();
        Object n2 = ko2.getObject();
        Comparable c1 = "FALLBACK";
        if (n1 instanceof Comparable) {
            c1 = (Comparable) n1;
        }
        Comparable c2 = "FALLBACK";
        if (n2 instanceof Comparable) {
            c2 = (Comparable) n2;
        }
        if (n2 == null) {
            return -1;
        }
        if (n1 == null) {
            return 1;
        }
        if (this.order.equals(SortOrder.ASCENDING)) {
            return c1.compareTo(c2);
        } else if (this.order.equals(SortOrder.DESCENDING)) {
            return c2.compareTo(c1);
        } else {
            throw new IllegalArgumentException("Unrecognised sort order.");
        }
    } else {
        throw new IllegalArgumentException("Unrecognised type.");
    }
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java

/**
 * Tests sorting of data by key (descending).
 */// w w  w. ja va 2 s .  co m
public void testSortByKeyDescending() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByKeys(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "C");
    assertEquals(data.getKey(2), "B");
    assertEquals(data.getKey(3), "A");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(3.0));
    assertEquals(data.getValue(1), new Double(1.0));
    assertEquals(data.getValue(2), null);
    assertEquals(data.getValue(3), new Double(2.0));
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by key (descending).
 *//* w w w  .  j  a v  a  2s .  c o m*/
public void testSortByKeyDescending() {

    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByKeys(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "C");
    assertEquals(data.getKey(2), "B");
    assertEquals(data.getKey(3), "A");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(3.0));
    assertEquals(data.getValue(1), new Double(1.0));
    assertEquals(data.getValue(2), null);
    assertEquals(data.getValue(3), new Double(2.0));

}

From source file:org.jfree.data.junit.KeyedObjectsTests.java

/**
 * Tests sorting of data by key (descending).
 *//*from   w w  w.  j a  va2s  .  c o m*/
public void testSortByKeyDescending() {
    KeyedObjects data = new KeyedObjects();
    data.addObject("C", new Double(1.0));
    data.addObject("B", null);
    data.addObject("D", new Double(3.0));
    data.addObject("A", new Double(2.0));

    data.sortByKeys(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "C");
    assertEquals(data.getKey(2), "B");
    assertEquals(data.getKey(3), "A");

    // check retrieve value by key
    assertEquals(data.getObject("A"), new Double(2.0));
    assertEquals(data.getObject("B"), null);
    assertEquals(data.getObject("C"), new Double(1.0));
    assertEquals(data.getObject("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getObject(0), new Double(3.0));
    assertEquals(data.getObject(1), new Double(1.0));
    assertEquals(data.getObject(2), null);
    assertEquals(data.getObject(3), new Double(2.0));
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java

/**
 * Tests sorting of data by key (descending).
 *///from  w w w .  j a  v  a2  s  . com
public void testSortByValueDescending() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByValues(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "A");
    assertEquals(data.getKey(2), "C");
    assertEquals(data.getKey(3), "B");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(3.0));
    assertEquals(data.getValue(1), new Double(2.0));
    assertEquals(data.getValue(2), new Double(1.0));
    assertEquals(data.getValue(3), null);
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by key (descending).
 *///from   ww  w  . j  ava 2 s  .  c  om
public void testSortByValueDescending() {

    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("C", new Double(1.0));
    data.addValue("B", null);
    data.addValue("D", new Double(3.0));
    data.addValue("A", new Double(2.0));

    data.sortByValues(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "A");
    assertEquals(data.getKey(2), "C");
    assertEquals(data.getKey(3), "B");

    // check retrieve value by key
    assertEquals(data.getValue("A"), new Double(2.0));
    assertEquals(data.getValue("B"), null);
    assertEquals(data.getValue("C"), new Double(1.0));
    assertEquals(data.getValue("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getValue(0), new Double(3.0));
    assertEquals(data.getValue(1), new Double(2.0));
    assertEquals(data.getValue(2), new Double(1.0));
    assertEquals(data.getValue(3), null);

}

From source file:org.jfree.data.junit.KeyedObjectsTests.java

/**
 * Tests sorting of data by key (descending).
 *///from   w w w  .j a  va  2s .  co  m
public void testSortByValueDescending() {
    KeyedObjects data = new KeyedObjects();
    data.addObject("C", new Double(1.0));
    data.addObject("B", null);
    data.addObject("D", new Double(3.0));
    data.addObject("A", new Double(2.0));

    data.sortByObjects(SortOrder.DESCENDING);

    // check key order
    assertEquals(data.getKey(0), "D");
    assertEquals(data.getKey(1), "A");
    assertEquals(data.getKey(2), "C");
    assertEquals(data.getKey(3), "B");

    // check retrieve value by key
    assertEquals(data.getObject("A"), new Double(2.0));
    assertEquals(data.getObject("B"), null);
    assertEquals(data.getObject("C"), new Double(1.0));
    assertEquals(data.getObject("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getObject(0), new Double(3.0));
    assertEquals(data.getObject(1), new Double(2.0));
    assertEquals(data.getObject(2), new Double(1.0));
    assertEquals(data.getObject(3), null);
}