SubCollectionConstraint.java
package org.opentrafficsim.base.parameters.constraint;
import java.util.Collection;
import org.djutils.exceptions.Throw;
/**
* Constraint that checks whether a collection (the parameter value) is a subset of a constraint collection.
* <p>
* Copyright (c) 2013-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
* BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
* </p>
* @author Alexander Verbraeck
* @author Peter Knoppers
* @author Wouter Schakel
* @param <T> object type
*/
public class SubCollectionConstraint<T> implements Constraint<Collection<T>>
{
/** Acceptable objects. */
@SuppressWarnings("checkstyle:visibilitymodifier")
protected final Collection<T> objects;
/**
* Constructor.
* @param objects acceptable objects
*/
public SubCollectionConstraint(final Collection<T> objects)
{
Throw.whenNull(objects, "Collection of acceptable objects may not be null.");
this.objects = objects;
}
@Override
public boolean accept(final Collection<T> value)
{
return this.objects.containsAll(value);
}
@Override
public String failMessage()
{
return "Value of parameter '%s' contains value(s) not in the collection of acceptable values.";
}
@Override
public String toString()
{
return "SubCollectionConstraint [objects=" + this.objects + "]";
}
}