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

org.thymeleaf.expression.Bools Maven / Gradle / Ivy

Go to download

Modern server-side Java template engine for both web and standalone environments

There is a newer version: 3.1.2.RELEASE
Show newest version
/*
 * =============================================================================
 *
 *   Copyright (c) 2011-2018, The THYMELEAF team (http://www.thymeleaf.org)
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 * =============================================================================
 */
package org.thymeleaf.expression;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.thymeleaf.util.EvaluationUtils;
import org.thymeleaf.util.Validate;


/**
 * 

* Expression Object for performing boolean operations inside Thymeleaf Standard Expressions. *

*

* An object of this class is usually available in variable evaluation expressions with the name * {@code #bools}. *

* * @author Daniel Fernández * * @since 1.0 * */ public final class Bools { public Bools() { super(); } public Boolean isTrue(final Object target) { return Boolean.valueOf(EvaluationUtils.evaluateAsBoolean(target)); } public Boolean[] arrayIsTrue(final Object[] target) { Validate.notNull(target, "Target cannot be null"); final Boolean[] result = new Boolean[target.length]; for (int i = 0; i < target.length; i++) { result[i] = isTrue(target[i]); } return result; } public List listIsTrue(final List target) { Validate.notNull(target, "Target cannot be null"); final List result = new ArrayList(target.size() + 2); for (final Object element : target) { result.add(isTrue(element)); } return result; } public Set setIsTrue(final Set target) { Validate.notNull(target, "Target cannot be null"); final Set result = new LinkedHashSet(target.size() + 2); for (final Object element : target) { result.add(isTrue(element)); } return result; } public Boolean isFalse(final Object target) { return Boolean.valueOf(!EvaluationUtils.evaluateAsBoolean(target)); } public Boolean[] arrayIsFalse(final Object[] target) { Validate.notNull(target, "Target cannot be null"); final Boolean[] result = new Boolean[target.length]; for (int i = 0; i < target.length; i++) { result[i] = isFalse(target[i]); } return result; } public List listIsFalse(final List target) { Validate.notNull(target, "Target cannot be null"); final List result = new ArrayList(target.size() + 2); for (final Object element : target) { result.add(isFalse(element)); } return result; } public Set setIsFalse(final Set target) { Validate.notNull(target, "Target cannot be null"); final Set result = new LinkedHashSet(target.size() + 2); for (final Object element : target) { result.add(isFalse(element)); } return result; } public Boolean arrayAnd(final Object[] target) { Validate.notNull(target, "Target cannot be null"); for (final Object aTarget : target) { if (!isTrue(aTarget).booleanValue()) { return Boolean.FALSE; } } return Boolean.TRUE; } public Boolean listAnd(final List target) { Validate.notNull(target, "Target cannot be null"); for (final Object element : target) { if (!isTrue(element).booleanValue()) { return Boolean.FALSE; } } return Boolean.TRUE; } public Boolean setAnd(final Set target) { Validate.notNull(target, "Target cannot be null"); for (final Object element : target) { if (!isTrue(element).booleanValue()) { return Boolean.FALSE; } } return Boolean.TRUE; } public Boolean arrayOr(final Object[] target) { Validate.notNull(target, "Target cannot be null"); for (final Object aTarget : target) { if (isTrue(aTarget).booleanValue()) { return Boolean.TRUE; } } return Boolean.FALSE; } public Boolean listOr(final List target) { Validate.notNull(target, "Target cannot be null"); for (final Object element : target) { if (isTrue(element).booleanValue()) { return Boolean.TRUE; } } return Boolean.FALSE; } public Boolean setOr(final Set target) { Validate.notNull(target, "Target cannot be null"); for (final Object element : target) { if (isTrue(element).booleanValue()) { return Boolean.TRUE; } } return Boolean.FALSE; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy