se.jbee.inject.Precision Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of silk-di Show documentation
Show all versions of silk-di Show documentation
Silk Java dependency injection framework
/*
* Copyright (c) 2012, Jan Bernitt
*
* Licensed under the Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
*/
package se.jbee.inject;
import java.util.Comparator;
/**
* A util to find out if one object is {@link PreciserThan} an other one.
*
* @author Jan Bernitt ([email protected])
*/
public final class Precision {
public static final Comparator> RESOURCE_COMPARATOR = new ResourcingComparator();
public static > Comparator comparator() {
return new PreciserThanComparator();
}
public static > int comparePrecision( T one, T other ) {
if ( one.morePreciseThan( other ) ) {
return -1;
}
if ( other.morePreciseThan( one ) ) {
return 1;
}
return 0;
}
public static , T2 extends PreciserThan super T2>> boolean morePreciseThan2(
T one, T other, T2 sndOne, T2 sndOther ) {
return one.morePreciseThan( other ) //
|| !other.morePreciseThan( one ) && sndOne.morePreciseThan( sndOther );
}
private static class PreciserThanComparator>
implements Comparator {
PreciserThanComparator() {
// make visible
}
@Override
public int compare( T one, T other ) {
return Precision.comparePrecision( one, other );
}
}
private static final class ResourcingComparator
implements Comparator> {
ResourcingComparator() {
// make visible
}
@Override
public int compare( Resourcing> one, Resourcing> other ) {
Resource> rOne = one.getResource();
Resource> rOther = other.getResource();
Class> rawOne = rOne.getType().getRawType();
Class> rawOther = rOther.getType().getRawType();
if ( rawOne != rawOther ) {
return rawOne.getCanonicalName().compareTo( rawOther.getCanonicalName() );
}
return comparePrecision( rOne, rOther );
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy