Class CollectionConstraint<T>

  • Type Parameters:
    T - value type
    All Implemented Interfaces:
    Constraint<T>
    Direct Known Subclasses:
    ClassConstraint

    public class CollectionConstraint<T>
    extends Object
    implements Constraint<T>
    Constraint that checks whether a value is in a given constraint collection.

    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 10 sep. 2017
    Author:
    Alexander Verbraeck, Peter Knoppers, Wouter Schakel
    • Field Detail

      • objects

        protected final Collection<T> objects
        Acceptable objects.
    • Constructor Detail

      • CollectionConstraint

        public CollectionConstraint​(Collection<T> objects)
        Parameters:
        objects - Collection<T>; acceptable objects
    • Method Detail

      • accept

        public boolean accept​(T value)
        Checks whether the value complies with constraints.
        Specified by:
        accept in interface Constraint<T>
        Parameters:
        value - T; Value to check.
        Returns:
        Whether the value complies with constraints.
      • failMessage

        public String failMessage()
        Returns a message for value failure, pointing to a parameter using '%s'.
        Specified by:
        failMessage in interface Constraint<T>
        Returns:
        Message for value failure, pointing to a parameter using '%s'.
      • newInstance

        @SafeVarargs
        public static <T> CollectionConstraint<T> newInstance​(T... objs)
        Creates a new instance with given objects.
        Type Parameters:
        T - type
        Parameters:
        objs - T...; acceptable objects
        Returns:
        new instance with given objects