Package org.springframework.rules.constraint

Examples of org.springframework.rules.constraint.Constraint


     * @return The range constraint constraint
     *
     * @since 0.3.0
     */
    public PropertyConstraint inRangeProperties(String propertyName, String minPropertyName, String maxPropertyName, Comparator comparator) {
        Constraint min = gteProperty(propertyName, minPropertyName, comparator);
        Constraint max = lteProperty(propertyName, maxPropertyName, comparator);
        return new CompoundPropertyConstraint(new And(min, max));
    }
View Full Code Here


     * @param minPropertyName the low edge of the range
     * @param maxPropertyName the high edge of the range
     * @return The range constraint constraint
     */
    public PropertyConstraint inRangeProperties(String propertyName, String minPropertyName, String maxPropertyName) {
        Constraint min = gteProperty(propertyName, minPropertyName);
        Constraint max = lteProperty(propertyName, maxPropertyName);
        return new CompoundPropertyConstraint(new And(min, max));
    }
View Full Code Here

     */
    public StringLengthConstraint(RelationalOperator operator, int length, String type) {
        Assert.notNull(operator, "The relational operator is required");
        Assert.isTrue(length > 0, "length is required");
        BinaryConstraint comparer = operator.getConstraint();
        Constraint lengthConstraint = bind(comparer, length);
        this.lengthConstraint = testResultOf(StringLength.instance(),
                lengthConstraint);
        this.type = type;
    }
View Full Code Here

     *            The minimum edge of the range
     * @param max
     *            the maximum edge of the range
     */
    public StringLengthConstraint(int min, int max, String type) {
        Constraint rangeConstraint = new Range(min, max);
        this.lengthConstraint = testResultOf(StringLength.instance(),
                rangeConstraint);
        this.type = type;
    }
View Full Code Here

    }

    public static Constraint readableFileCheck() {
        Constraints c = Constraints.instance();
        Constraint checks = c.all(new Constraint[] { exists, file, readable });
        return c.testResultOf(fileConverter, checks);
    }
View Full Code Here

   * @param inclusive
   *            the range is inclusive?
   */
  public Range(Comparable min, Comparable max, boolean inclusive) {
    commonAssert(min, max);
    Constraint minimum;
    Constraint maximum;
    this.inclusive = inclusive;
    if (this.inclusive) {
      Assert.isTrue(LessThanEqualTo.instance().test(min, max), "Minimum " + min
          + " must be less than or equal to maximum " + max);
      minimum = gte(min);
View Full Code Here

   * @param comparator
   *            the comparator to use to perform value comparisons
   */
  public Range(Object min, Object max, Comparator comparator, boolean inclusive) {
    commonAssert(min, max);
    Constraint minimum;
    Constraint maximum;
    this.inclusive = inclusive;
    if (this.inclusive) {
      Assert.isTrue(LessThanEqualTo.instance(comparator).test(min, max), "Minimum " + min
          + " must be less than or equal to maximum " + max);
      minimum = bind(GreaterThanEqualTo.instance(comparator), min);
View Full Code Here

    private void loadPropertyConstraintsForMethod(Rules rules, String propertyName, Method method) {
        if (method != null) {
            for (Iterator i = attributes.getAttributes(method).iterator(); i.hasNext();) {
                Object attribute = i.next();
                if (attribute instanceof Constraint) {
                    Constraint constraint = (Constraint)attribute;
                    if (constraint instanceof PropertyConstraint) {
                        rules.add((PropertyConstraint)constraint);
                    }
                    else if (constraint instanceof CompoundPropertyConstraint) {
                        rules.add((CompoundPropertyConstraint)constraint);
View Full Code Here

    String o3 = "o3";
    Set group = new HashSet();
    group.add(o1);
    group.add(o2);
    group.add(o3);
    Constraint p = constraints.inGroup(group);
    assertTrue(p.test("o1"));
    assertTrue(p.test(o1));
    assertFalse(p.test("o4"));
    p = constraints.inGroup(new Object[] { o1, o2, o1, o3 });
    assertTrue(p.test("o1"));
    assertTrue(p.test(o1));
    assertFalse(p.test("o4"));
  }
View Full Code Here

  public void testLike() {
    String keithDonald = "keith donald";
    String keith = "keith";
    String donald = "donald";
    Constraint p = constraints.like(keithDonald);
    assertTrue(p.test("keith donald"));
    assertFalse(p.test("Keith Donald"));

    p = constraints.like("%keith donald%");
    assertTrue(p.test("keith donald"));
    assertFalse(p.test("Keith Donald"));

    p = constraints.like("keith%");
    assertTrue(p.test(keithDonald));
    assertTrue(p.test(keith));
    assertFalse(p.test(donald));

    p = constraints.like("%donald");
    assertTrue(p.test(keithDonald));
    assertTrue(p.test(donald));
    assertFalse(p.test(keith));

  }
View Full Code Here

TOP

Related Classes of org.springframework.rules.constraint.Constraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.