/** * Returns the value that corresponds to a given implementation calculator class. * * @param clazz the target class. * @throws IllegalArgumentException if {@code clazz} is {@code null} or if it is abstract. * @return never {@code null}. */ public static AFCalculatorImplementation fromCalculatorClass( final Class<? extends AFCalculator> clazz) { Utils.nonNull(clazz, "input class cannot be null"); Utils.validateArg( !Modifier.isAbstract(clazz.getModifiers()), "class " + clazz.getCanonicalName() + " should not be abstract"); // Using iteration instead of a static map to avoid static state. for (final AFCalculatorImplementation impl : AFCalculatorImplementation.values()) { if (clazz.equals(impl.newInstance().getClass())) { return impl; } } throw new IllegalArgumentException( "Attempt to retrieve AFCalculatorImplementation instance from a non-registered calculator class " + clazz.getName()); }
/** * Returns the best (fastest) model give the required ploidy and alternative allele count. * * @param requiredPloidy required ploidy * @param requiredAlternativeAlleleCount required alternative allele count. * @param preferred a preferred mode if any. A {@code null} indicate that we should be try to use * the default instead. * @return never {@code null} */ public static AFCalculatorImplementation bestValue( final int requiredPloidy, final int requiredAlternativeAlleleCount, final AFCalculatorImplementation preferred) { final AFCalculatorImplementation preferredValue = preferred == null ? DEFAULT : preferred; if (preferredValue.usableForParams(requiredPloidy, requiredAlternativeAlleleCount)) { return preferredValue; } if (EXACT_INDEPENDENT.usableForParams(requiredPloidy, requiredAlternativeAlleleCount)) { return EXACT_INDEPENDENT; } if (EXACT_REFERENCE.usableForParams( requiredPloidy, requiredAlternativeAlleleCount)) { // TODO: this seems to be dead code. EXACT_REFERENCE will // always lose to EXACT_INDEPENDENT. return EXACT_REFERENCE; } return EXACT_GENERAL_PLOIDY; }