OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 179 → Rev 180

/trunk/OpenConcerto/src/org/openconcerto/utils/TransformedComparator.java
14,12 → 14,9
package org.openconcerto.utils;
 
import org.openconcerto.utils.cc.ITransformer;
import org.openconcerto.utils.cc.Transformer;
 
import java.util.Comparator;
 
import org.apache.commons.collections.ComparatorUtils;
 
/**
* A comparator that transforms before comparing.
*
26,29 → 23,22
* @author Sylvain
*
* @param <E> the type of the objects before being transformed.
* @param <T> the type of the objects after being transformed.
*/
public class TransformedComparator<E, T> implements Comparator<E> {
public class TransformedComparator<E> implements Comparator<E> {
 
public static final <T> TransformedComparator<T, T> from(final Comparator<T> comp) {
return new TransformedComparator<T, T>(Transformer.<T> nopTransformer(), comp);
}
private final Comparator<E> comp;
 
private final ITransformer<E, T> transf;
private final Comparator<T> comp;
 
@SuppressWarnings("unchecked")
public TransformedComparator(final ITransformer<E, T> transf) {
this(transf, ComparatorUtils.NATURAL_COMPARATOR);
public <T extends Comparable<T>> TransformedComparator(final ITransformer<E, T> transf) {
this(transf, Comparator.naturalOrder());
}
 
public TransformedComparator(final ITransformer<E, T> transf, final Comparator<T> comp) {
public <T> TransformedComparator(final ITransformer<E, T> transf, final Comparator<T> comp) {
super();
this.transf = transf;
this.comp = comp;
this.comp = (o1, o2) -> (comp.compare(transf.transformChecked(o1), transf.transformChecked(o2)));
}
 
@Override
public int compare(E o1, E o2) {
return this.comp.compare(this.transf.transformChecked(o1), this.transf.transformChecked(o2));
return this.comp.compare(o1, o2);
}
}