package org.opentrafficsim.base.parameters.constraint;
import java.util.Collection;
import java.util.LinkedHashSet;
/**
* Constraint that checks whether the value is any of a given collection of classes, where each class is a sub class of a given
* type.
*
* Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
* BSD-style license. See OpenTrafficSim License.
*
* @version $Revision$, $LastChangedDate$, by $Author$, initial version 30 jun. 2017
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param super type for all possible classes, e.g. TacticalPlanner
*/
public final class ClassConstraint extends CollectionConstraint>
{
/**
* @param classes Collection<Class<? extends T>>; acceptable classes
*/
private ClassConstraint(final Collection> classes)
{
super(classes);
}
/**
* Creates a new instance with given collection.
* @param objs Class<? extends T>...; acceptable classes
* @param type class
* @return new instance with given collection
*/
@SafeVarargs
public static ClassConstraint newInstance(final Class extends T>... objs)
{
Collection> collection = new LinkedHashSet<>();
for (Class extends T> clazz : objs)
{
collection.add(clazz);
}
return new ClassConstraint<>(collection);
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("checkstyle:designforextension")
public String toString()
{
return "ClassConstraint [classes=" + super.objects + "]";
}
}