Interface PropertyConstraint

  • All Known Implementing Classes:
    PropertyConstraint.And, PropertyConstraint.ByAnnotationType, PropertyConstraint.ByClass, PropertyConstraint.Enumeration, PropertyConstraint.ExactValue, PropertyConstraint.Or

    public interface PropertyConstraint

    PropertyConstraints describes a constraint applied to the members of an annotation bundle.

    PropertyConstraints are usually used in conjunction with the AnnotationType interface to describe a class of annotations by the values of their properties. In this way, you can generate controlled vocabularies over Java objects.

    The constraints accept or reject individual objects. In general, it is not possible to get back a set of all items that would be accepted by a particular constraint.

    Instantiate PropertyConstraint classes when populating an AnnotationType instance Implement PropertyContraint to provide meta-data about a new type of object relationship. For example, if there was a data-structure representing an inheritance hierachy, then an implementation of PropertyConstraint could be written that allowed a propertie's value to be constrained to be a child of a particular node in the hierachy
    Since:
    1.3
    Author:
    Matthew Pocock, Keith James, Thomas Down
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  PropertyConstraint.And
      A property constraint that accpepts items iff they are accepted by both child constraints.
      static class  PropertyConstraint.ByAnnotationType
      ByAnnotationType accepts a property value if it belongs to type defined by AnnotationType.
      static class  PropertyConstraint.ByClass
      ByClass accepts a property value if it is an instance of a specific Java class.
      static class  PropertyConstraint.Enumeration
      Enumeration accepts a property if it is present in the specified set of values.
      static class  PropertyConstraint.ExactValue
      Matches properties if they have exactly this one value.
      static class  PropertyConstraint.Or
      A property constraint that accepts items iff they are accepted by either child constraints.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static PropertyConstraint ANY
      ANY is a constraint which accepts a property for addition under all conditions.
      static PropertyConstraint NONE
      NONE is a constraint which accepts no value for a property under any condition.
    • Field Detail

      • ANY

        static final PropertyConstraint ANY
        ANY is a constraint which accepts a property for addition under all conditions. Whenever a PropertyConstraint is needed and you want to allow any value there
      • NONE

        static final PropertyConstraint NONE
        NONE is a constraint which accepts no value for a property under any condition. Whenever a PropertyConstraint is needed and you want to dissalow all values there e.g. when marking a property as having to be unset
    • Method Detail

      • accept

        boolean accept​(Object value)
        accept returns true if the value fulfills the constraint. Manually compare items with the PropertyConstraint. Node: this will ususaly be done for you in an AnnotationType instance Use for implementing accept() on AnnotatoinType
        Parameters:
        value - an Object to check.
        Returns:
        a boolean.
      • subConstraintOf

        boolean subConstraintOf​(PropertyConstraint subConstraint)

        subConstraintOf returns true if the constraint is a sub-constraint.

        A pair of constraints super and sub are in a superConstraint/subConstraint relationship if every object accepted by sub is also accepted by super. To put it another way, if instanceOf was used as a set-membership indicator function over some set of objects, then the set produced by super would be a superset of that produced by sub.

        It is not expected that constraints will neccesarily maintain references to super/sub types. It will be more usual to infer this relationship by introspecting the constraints themselves. For example, PropertyConstraint.ByClass will infer subConstraintOf by looking at the possible class of all items matching subConstraint.

        Useful when attempting to compare two constraints to see if it is necisary to retain both. You may want to check the more general or the more specific constraint only.
        Parameters:
        subConstraint - a PropertyConstraint to check.
        Returns:
        a boolean.