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

com.jidesoft.utils.BooleanUtils Maven / Gradle / Ivy

There is a newer version: 3.6.18
Show newest version
/*
 * @(#)BooleanUtils.java 5/27/2014
 *
 * Copyright 2002 - 2014 JIDE Software Inc. All rights reserved.
 */

package com.jidesoft.utils;

import com.jidesoft.range.BooleanRange;
import com.jidesoft.range.Range;

import java.util.List;

public class BooleanUtils {
    /**
     * Returns the min boolean in the booleans list.
     *
     * @param booleans the booleans to calculate the min.
     * @return the min boolean in the booleans list.
     */
    public static boolean min(List booleans) {
        for (boolean value : booleans) {
            if (!value) {
                return false;
            }
        }
        return true;
    }

    /**
     * Returns the max boolean in the booleans list.
     *
     * @param booleans the booleans to calculate the max.
     * @return the max boolean in the booleans list.
     */
    public static boolean max(List booleans) {
        for (boolean value : booleans) {
            if (value) {
                return true;
            }
        }
        return false;
    }

    /**
     * Returns the range of booleans.
     *
     * @param booleans the booleans to calculate the range.
     * @return the range of the booleans.
     */
    public static Range range(List booleans) {
        boolean min = true;
        boolean max = false;
        for (boolean value : booleans) {
            if (value) {
                max = true;
            }
            else {
                min = false;
            }
            if (max && !min) { // found
                break;
            }
        }
        return new BooleanRange(min, max);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy