List of usage examples for org.jfree.data KeyedObject getKey
public Comparable getKey()
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 w w .j a va2 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.KeyedObjects.java
/** * Returns the index for a given key, or <code>-1</code>. * * @param key the key (<code>null</code> not permitted). * * @return The index, or <code>-1</code> if the key is unrecognised. * * @see #getKey(int)/*from w w w.j a v a2 s . c o m*/ */ public int getIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int i = 0; Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { KeyedObject ko = (KeyedObject) iterator.next(); if (ko.getKey().equals(key)) { return i; } i++; } return -1; }
From source file:org.jfree.data.KeyedObjects.java
/** * Returns a list containing all the keys in the list. * * @return The keys (never <code>null</code>). *///from ww w . java 2 s.c o m public List getKeys() { List result = new java.util.ArrayList(); Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { KeyedObject ko = (KeyedObject) iterator.next(); result.add(ko.getKey()); } return result; }
From source file:org.jfree.data.KeyedObjects.java
/** * Returns the key at the specified position in the list. * * @param index the item index (zero-based). * * @return The row key.//from w w w . j av a 2s. c o m * * @throws IndexOutOfBoundsException if <code>item</code> is out of bounds. * * @see #getIndex(Comparable) */ public Comparable getKey(int index) { Comparable result = null; KeyedObject item = (KeyedObject) this.data.get(index); if (item != null) { result = item.getKey(); } return result; }