Eclipse Platform Release 3.7

## org.eclipse.ui.model
Class ContributionComparator

    java.lang.Object
      org.eclipse.jface.viewers.ViewerComparator
          org.eclipse.ui.model.ContributionComparator

All Implemented Interfaces:
  Comparator

    public class ContributionComparator

extends ViewerComparator
implements Comparator

A ContributionComparator is capable of ordering `IComparableContribution` instances, either as a `ViewerComparator` (for `StructuredViewer`s) or as a traditional `Comparator`. This class orders contributions by first grouping by priority (`IComparableContribution.getPriority()`) and then by utilizing the JFace policy comparator to order by label (`IComparableContribution.getLabel()`).

Since:
  3.4
See Also:
  `IComparableContribution`

Constructor Summary
`ContributionComparator()`

Method Summary
`int` `category(IComparableContribution c)` Returns the category of the given element.
`int` `category(Object element)` Returns the category of the given element.
`int` `compare(IComparableContribution c1, IComparableContribution c2)` Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.
`int` `compare(Object o1, Object o2)` This implementation of `Comparator.compare(Object, Object)` does a blind cast on each element to `IComparableContribution`.
`int` `compare(Viewer viewer, Object e1, Object e2)` Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.

Methods inherited from class org.eclipse.jface.viewers.ViewerComparator
`getComparator, isSorterProperty, sort`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface java.util.Comparator
`equals`

Constructor Detail

### ContributionComparator

    public ContributionComparator()

Method Detail

### compare

    public int compare(Object o1,
                       Object o2)

  This implementation of `Comparator.compare(Object, Object)` does a blind cast on each element to `IComparableContribution`.

  Specified by:
    `compare` in interface `Comparator`

### compare

    public int compare(IComparableContribution c1,
                       IComparableContribution c2)

  Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.

  The default implementation of this method is based on comparing the elements' categories as computed by the `category` framework method. Elements within the same category are further subjected to a case insensitive compare of their label strings. Subclasses may override.

  Parameters:
    `c1` - the first element
    `c2` - the second element
  Returns:
    a negative number if the first element is less than the second element; the value `0` if the first element is equal to the second element; and a positive number if the first element is greater than the second element

### compare

    public int compare(Viewer viewer,
                       Object e1,
                       Object e2)

  Description copied from class: `ViewerComparator`
  Returns a negative, zero, or positive number depending on whether the first element is less than, equal to, or greater than the second element.

  The default implementation of this method is based on comparing the elements' categories as computed by the `category` framework method. Elements within the same category are further subjected to a case insensitive compare of their label strings, either as computed by the content viewer's label provider, or their `toString` values in other cases. Subclasses may override.

  Overrides:
    `compare` in class `ViewerComparator`
  Parameters:
    `viewer` - the viewer
    `e1` - the first element
    `e2` - the second element
  Returns:
    a negative number if the first element is less than the second element; the value `0` if the first element is equal to the second element; and a positive number if the first element is greater than the second element

### category

    public int category(IComparableContribution c)

  Returns the category of the given element. The category is a number used to allocate elements to bins; the bins are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort criterion.

  The default implementation of this framework method returns the result of `IComparableContribution.getPriority()`. Subclasses may re-implement this method to provide non-trivial categorization.

  Parameters:
    `c` - the element
  Returns:
    the category

### category

    public int category(Object element)

  Description copied from class: `ViewerComparator`
  Returns the category of the given element. The category is a number used to allocate elements to bins; the bins are arranged in ascending numeric order. The elements within a bin are arranged via a second level sort criterion.

  The default implementation of this framework method returns `0`. Subclasses may reimplement this method to provide non-trivial categorization.

  Overrides:
    `category` in class `ViewerComparator`
  Parameters:
    `element` - the element
  Returns:
    the category

Eclipse Platform Release 3.7

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2011. All rights reserved.