
de.citec.tcs.alignment.ComparatorValidator Maven / Gradle / Ivy
/*
* TCS Alignment Toolbox Version 3
*
* Copyright (C) 2016
* Benjamin Paaßen
* AG Theoretical Computer Science
* Centre of Excellence Cognitive Interaction Technology (CITEC)
* University of Bielefeld
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.citec.tcs.alignment;
import de.citec.tcs.alignment.comparators.Comparator;
import de.citec.tcs.alignment.comparators.OperationType;
import lombok.NonNull;
/**
* This class has the sole purpose to validate that a Comparator supports all OperationTypes an
* AlignmentAlgorithm requires.
*
* @author Benjamin Paassen - [email protected]
*/
public class ComparatorValidator {
private ComparatorValidator() {
}
/**
* Returns true if and only if the given Comparator supports all OperationType the given
* AlignmentAlgorithm requires.
*
* @param the class of elements in left-hand sequences for the given AlignmentAlgorithm.
* @param the class of elements in right-hand sequences for the given AlignmentAlgorithm.
* @param algorithm an AlignmentAlgorithm.
* @param comp a Comparator.
* @return true if and only if the given Comparator supports all OperationType the given
* AlignmentAlgorithm requires.
*/
public static boolean isValid(@NonNull AlignmentAlgorithm algorithm,
@NonNull Comparator extends X, ? extends Y> comp) {
return checkValidity(algorithm, comp) == null;
}
/**
* Checks whether the given Comparator supports all OperationType the given AlignmentAlgorithm
* requires and throws an IllegalArgumentException if it does not.
*
* @param the class of elements in left-hand sequences for the given AlignmentAlgorithm.
* @param the class of elements in right-hand sequences for the given AlignmentAlgorithm.
* @param algorithm an AlignmentAlgorithm.
* @param comp a Comparator.
* @throws IllegalArgumentException if at least one required OperationType is not supported by
* the given Comparator.
*/
public static void validate(@NonNull AlignmentAlgorithm algorithm,
@NonNull Comparator extends X, ? extends Y> comp) throws IllegalArgumentException {
final IllegalArgumentException ex = checkValidity(algorithm, comp);
if (ex != null) {
throw ex;
}
}
/**
* Checks whether the given Comparator supports all OperationType the given AlignmentAlgorithm
* requires and returns an IllegalArgumentException if it does not.
*
* @param the class of elements in left-hand sequences for the given AlignmentAlgorithm.
* @param the class of elements in right-hand sequences for the given AlignmentAlgorithm.
* @param algorithm an AlignmentAlgorithm.
* @param comp a Comparator.
* @return null if everything is fine and an IllegalArgumentException if at least one required
* OperationType is not supported by the given Comparator.
*/
public static IllegalArgumentException checkValidity(
@NonNull AlignmentAlgorithm algorithm, @NonNull Comparator extends X, ? extends Y> comp) {
for (final OperationType type : OperationType.values()) {
if (algorithm.requires(type) && !comp.supports(type)) {
return new IllegalArgumentException("The given algorithm of type "
+ algorithm.getClass().getName() + " requires OperationType " + type
+ " but the given comparator of type " + comp.getClass().getName()
+ " does not support that OperationType.");
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy