Extension SDK

oracle.ide.model
Class DefaultFilter.SortedComparator

java.lang.Object
  |
  +--oracle.ide.model.DefaultFilter.SortedComparator
All Implemented Interfaces:
java.util.Comparator
Direct Known Subclasses:
DefaultFilter.SortedFolderFirstComparator
Enclosing class:
DefaultFilter

public static class DefaultFilter.SortedComparator
extends java.lang.Object
implements java.util.Comparator

Builtin Comparator class for ordering the children of a container node in locale-sensitive collation order.

This class provides a number of template methods that may be overridden by subclasses to provide custom behavior. This makes it possible for subclasses to leverage the existing functionality without having to reimplement it.

Note: This implementation is not as efficient as it could be. Rather than calling Collator.compare(String, String) to compare the Element labels directly, for better efficiency we should generate a CollationKey for each Element label and use those keys during the comparison. In practice, however, this is somewhat difficult to achieve, since we need to maintain the collation keys somewhere, and the most convenient place to put them would require a change to the Element interface.


Field Summary
protected static java.text.Collator collator
          Collator instance used for comparing strings in locale-sensitive collation order.
 
Constructor Summary
DefaultFilter.SortedComparator()
           
 
Method Summary
 int compare(java.lang.Object o1, java.lang.Object o2)
          Implementation of the Comparator.compare(Object, Object) method, which may not be overriden by subclasses.
protected  int compareElements(Element e1, Element e2)
          Template method for comparing the Element objects associated with each TNode, representing the second level of comparison in the compare() call chain.
protected  int compareElementToElement(Element e1, Element e2)
          Template method for comparing two like Element objects in locale-sensitive collation order, representing the third level of comparison in the compare() call chain.
protected  int compareStrings(java.lang.String s1, java.lang.String s2)
          Template method for comparing two String objects in locale-sensitive collation order, representing the fourth level of comparison in the compare() call chain.
protected  int compareTNodes(TNode t1, TNode t2)
          Template method for comparing two TNode objects to each other, representing the first level of comparison in the compare() call chain.
 boolean equals(java.lang.Object obj)
          Implementation of the Comparator.equals(Object) method.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

collator

protected static final java.text.Collator collator
Collator instance used for comparing strings in locale-sensitive collation order.
Constructor Detail

DefaultFilter.SortedComparator

public DefaultFilter.SortedComparator()
Method Detail

compare

public final int compare(java.lang.Object o1,
                         java.lang.Object o2)
Implementation of the Comparator.compare(Object, Object) method, which may not be overriden by subclasses. Subclasses should instead override one or more of the template comparison methods to provide custom behavior.

The default implementation calls the template method for comparing the TNode objects.

Specified by:
compare in interface java.util.Comparator

equals

public boolean equals(java.lang.Object obj)
Implementation of the Comparator.equals(Object) method. Subclasses may need to override this method.

The default implementation returns true if this Comparator has the same class as the other Object.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class java.lang.Object

compareTNodes

protected int compareTNodes(TNode t1,
                            TNode t2)
Template method for comparing two TNode objects to each other, representing the first level of comparison in the compare() call chain.

Most subclasses should not need to override this method. The default implementation simply calls the template method for comparing the Element objects associated with the nodes.


compareElements

protected int compareElements(Element e1,
                              Element e2)
Template method for comparing the Element objects associated with each TNode, representing the second level of comparison in the compare() call chain. Each Element object may either represent a Folder or a regular Element.

Subclasses may wish to override this method to provide custom behavior. The default implementation simply calls the template method for comparing the elements in locale-sensitive collation order.


compareElementToElement

protected int compareElementToElement(Element e1,
                                      Element e2)
Template method for comparing two like Element objects in locale-sensitive collation order, representing the third level of comparison in the compare() call chain.

Most subclasses should not need to override this method. The default implementation first compares the element short labels, followed by the element long labels if the short labels were the same.


compareStrings

protected int compareStrings(java.lang.String s1,
                             java.lang.String s2)
Template method for comparing two String objects in locale-sensitive collation order, representing the fourth level of comparison in the compare() call chain.

Most subclasses should not need to override this method. The default implementation checks for null and orders those items at the end; otherwise, the strings are compared using the default Collator for the current locale.


Extension SDK