Package net.shibboleth.idp.consent.logic.impl

# Class PreferExplicitOrderComparator

java.lang.Object
net.shibboleth.idp.consent.logic.impl.PreferExplicitOrderComparator

All Implemented Interfaces:
  `Comparator<String>`

public class PreferExplicitOrderComparator extends Object implements Comparator<String>
Comparator which prefers to order strings according to the order in which they appear in a list, and which falls back to natural ordering for strings not present in the list. Relies on Guava's `Ordering.explicit(List)` to compare strings present in the list. Strings not present in the list are treated as greater than strings present in the list and are compared according to their natural ordering. Does not support comparing null values. Is not serializable, and such should not be used as part of a TreeMap, for example, which is serialized.

## Field Summary

Fields
Modifier and Type
Field
Description
`private final List<String>`
`explicitOrder`
Strings in order.
`private final Ordering<String>`
`explicitOrdering`
Explicit ordering.

## Constructor Summary

Constructors
Constructor
Description
`PreferExplicitOrderComparator(List<String> order)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`int`
`compare(String o1, String o2)`

### 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, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

## Field Details

### explicitOrdering

@Nonnull private final Ordering<String> explicitOrdering
Explicit ordering.

### explicitOrder

@Nonnull @Unmodifiable private final List<String> explicitOrder
Strings in order.

## Constructor Details

### PreferExplicitOrderComparator

public PreferExplicitOrderComparator(@Nullable @NullableElements List<String> order)
Constructor.

Parameters:
  `order` - the desired order, null and empty strings are ignored, duplicates are removed

## Method Details

### compare

public int compare(String o1, String o2)

Specified by:
  `compare` in interface `Comparator<String>`
Throws:
  `NullPointerException` - if either argument is null