All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.vpro.domain.constraint.AbstractNot Maven / Gradle / Ivy

Go to download

Contains the objects used by the Frontend API, like forms and result objects

There is a newer version: 8.3.3
Show newest version
/*
 * Copyright (C) 2013 All rights reserved
 * VPRO The Netherlands
 */
package nl.vpro.domain.constraint;

import java.util.List;
import java.util.Locale;

import javax.el.ELContext;
import javax.xml.bind.annotation.*;

import org.checkerframework.checker.nullness.qual.Nullable;

import static nl.vpro.domain.constraint.PredicateTestResult.FACTORY;


/**
 * @author Roelof Jan Koekoek
 * @since 2.0
 */
@XmlAccessorType(XmlAccessType.NONE)
@XmlTransient
public abstract class AbstractNot implements Constraint {

    protected Constraint constraint;

    protected AbstractNot() {
    }

    protected AbstractNot(Constraint constraint) {
        this.constraint = constraint;
    }

    public Constraint getConstraint() {
        return constraint;
    }

    public void setConstraint(Constraint constraint) {
        this.constraint = constraint;
    }

    @Override
    public boolean test(@Nullable T t) {
        return constraint == null || constraint.negate().test(t);
    }


    @Override
    public NotPredicateTestResult testWithReason(@Nullable T t) {
        PredicateTestResult result = constraint.testWithReason(t);
        return new NotPredicateTestResult(this, t, ! result.applies(), result);
    }

    @Override
    public void setELContext(ELContext ctx, Object value, Locale locale, PredicateTestResult result) {
        Constraint.super.setELContext(ctx, value, locale, result);
        NotPredicateTestResult notResult = (NotPredicateTestResult) result;
        ctx.getVariableMapper().setVariable("clause",
            FACTORY.createValueExpression(notResult.getClause().getDescription(locale), String.class));
    }

    @Override
    public List getDefaultBundleKey() {
        List result = Constraint.super.getDefaultBundleKey();
        result.add(0, "Not");
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy