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.3.RELEASE
Show newest version
/*
 * =============================================================================
 * 
 *   Copyright (c) 2011, 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.ObjectUtils;
import org.thymeleaf.util.Validate;


/**
 * 
 * @author Daniel Fernández
 * 
 * @since 1.0
 *
 */
public final class Bools {
    


    public Boolean isTrue(final Object target) {
        return Boolean.valueOf(ObjectUtils.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();
        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();
        for (final Object element : target) {
            result.add(isTrue(element));
        }
        return result;
    }

    
    
    
    public Boolean isFalse(final Object target) {
        return Boolean.valueOf(!ObjectUtils.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();
        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();
        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 (int i = 0; i < target.length; i++) {
            if (!isTrue(target[i]).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 (int i = 0; i < target.length; i++) {
            if (isTrue(target[i]).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;
    }

    
    
    
    
    
    public Bools() {
        super();
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy