Example usage for org.apache.commons.lang3 BooleanUtils and

List of usage examples for org.apache.commons.lang3 BooleanUtils and

Introduction

In this page you can find the example usage for org.apache.commons.lang3 BooleanUtils and.

Prototype

public static Boolean and(final Boolean... array) 

Source Link

Document

Performs an and on an array of Booleans.

 BooleanUtils.and(Boolean.TRUE, Boolean.TRUE)                 = Boolean.TRUE BooleanUtils.and(Boolean.FALSE, Boolean.FALSE)               = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.FALSE)                = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE)   = Boolean.TRUE BooleanUtils.and(Boolean.FALSE, Boolean.FALSE, Boolean.TRUE) = Boolean.FALSE BooleanUtils.and(Boolean.TRUE, Boolean.FALSE, Boolean.TRUE)  = Boolean.FALSE 

Usage

From source file:com.shazam.fork.summary.OutcomeAggregator.java

private static Boolean and(final Collection<Boolean> booleans) {
    return BooleanUtils.and(booleans.toArray(new Boolean[booleans.size()]));
}

From source file:org.debux.webmotion.shiro.Shiro.java

/**
 * Check if the current user has role./*from ww w.j  a  v  a  2  s.  c  o  m*/
 * 
 * @param role
 * @return 
 */
public Render hasRole(HttpContext context, Call call) {
    FilterRule rule = (FilterRule) call.getCurrentRule();
    Map<String, String[]> defaultParameters = rule.getDefaultParameters();

    String[] values = defaultParameters.get("role");
    List<String> roles = Arrays.asList(values);

    Subject currentUser = getSubject(context);
    if (currentUser.isAuthenticated()) {

        boolean[] hasRoles = currentUser.hasRoles(roles);
        if (BooleanUtils.and(hasRoles)) {
            doProcess();
            return null;
        } else {
            return renderError(HttpURLConnection.HTTP_FORBIDDEN);
        }

    } else {
        return renderError(HttpURLConnection.HTTP_UNAUTHORIZED);
    }
}

From source file:org.debux.webmotion.shiro.Shiro.java

/**
 * Check if the current user is permitted.
 * //from   w  ww .  j  a va 2  s .c  om
 * @param permission
 * @return 
 */
public Render isPermitted(HttpContext context, Call call) {
    FilterRule rule = (FilterRule) call.getCurrentRule();
    Map<String, String[]> defaultParameters = rule.getDefaultParameters();

    String[] permissions = defaultParameters.get("permission");

    Subject currentUser = getSubject(context);
    if (currentUser.isAuthenticated()) {

        boolean[] permitted = currentUser.isPermitted(permissions);
        if (BooleanUtils.and(permitted)) {
            doProcess();
            return null;
        } else {
            return renderError(HttpURLConnection.HTTP_FORBIDDEN);
        }

    } else {
        return renderError(HttpURLConnection.HTTP_UNAUTHORIZED);
    }
}

From source file:org.ruogu.lang3.TestBooleanUtils.java

public static void main(String[] args) {
    boolean[] a1 = { true, true };
    //      //from  w w w  .  j  a va2 s  .  c  om
    System.out.println("BooleanUtils.and(true, true)         = " + BooleanUtils.and(a1));

    /**
     * and(final boolean... array)and(final Boolean... array)???
     * ?and(final boolean... array)
     */
    //      System.out.println("and(true, true)         = " + and(Boolean.TRUE, Boolean.TRUE));
    //      System.out.println("and(true, true)         = " + and(true, true));

    //      System.out.println("BooleanUtils.and(true, true)         = " + BooleanUtils.and(Boolean.TRUE, Boolean.TRUE));

    //      System.out.println("BooleanUtils.and(false, false)       = " + BooleanUtils.and(false, false));
    //      System.out.println("BooleanUtils.and(true, false)        = " + BooleanUtils.and(true, false));
    //      System.out.println("BooleanUtils.and(true, true, false)  = " + BooleanUtils.and(true, true, false));
    //      System.out.println("BooleanUtils.and(true, true, true)   = " + BooleanUtils.and(true, true, true));
    //      

    test("a1", "a2");
    test(1, 2, 3);
    //      test(true, false, true);

    test(Boolean.TRUE);

}

From source file:yoyo.framework.standard.shared.commons.lang.BooleanUtilsTest.java

@Test
public void test() {
    assertThat(BooleanUtils.and(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.and(new boolean[] { true, false }), is(false));
    assertThat(BooleanUtils.isFalse(false), is(true));
    assertThat(BooleanUtils.isNotFalse(false), is(false));
    assertThat(BooleanUtils.isNotTrue(true), is(false));
    assertThat(BooleanUtils.isTrue(true), is(true));
    assertThat(BooleanUtils.negate(Boolean.FALSE), is(true));
    assertThat(BooleanUtils.or(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.or(new boolean[] { true, false }), is(true));
    assertThat(BooleanUtils.toBoolean(Boolean.TRUE), is(true));
    assertThat(BooleanUtils.toBoolean(0), is(false));
    assertThat(BooleanUtils.toBoolean(1), is(true));
    assertThat(BooleanUtils.toBoolean((String) null), is(false));
    assertThat(BooleanUtils.toBoolean("true"), is(true));
    assertThat(BooleanUtils.toBoolean("hoge"), is(false));
    assertThat(BooleanUtils.toBooleanDefaultIfNull(null, false), is(false));
    assertThat(BooleanUtils.toBooleanObject(0), is(Boolean.FALSE));
    assertThat(BooleanUtils.toBooleanObject(1), is(Boolean.TRUE));
    assertThat(BooleanUtils.toInteger(true), is(1));
    assertThat(BooleanUtils.toInteger(false), is(0));
    assertThat(BooleanUtils.toIntegerObject(true), is(Integer.valueOf(1)));
    assertThat(BooleanUtils.toIntegerObject(false), is(Integer.valueOf(0)));
    assertThat(BooleanUtils.toString(true, "true", "false"), is("true"));
    assertThat(BooleanUtils.toString(false, "true", "false"), is("false"));
    assertThat(BooleanUtils.toStringOnOff(true), is("on"));
    assertThat(BooleanUtils.toStringOnOff(false), is("off"));
    assertThat(BooleanUtils.toStringTrueFalse(true), is("true"));
    assertThat(BooleanUtils.toStringTrueFalse(false), is("false"));
    assertThat(BooleanUtils.toStringYesNo(true), is("yes"));
    assertThat(BooleanUtils.toStringYesNo(false), is("no"));
    assertThat(BooleanUtils.xor(new boolean[] { true }), is(true));
    assertThat(BooleanUtils.xor(new boolean[] { true, false }), is(true));
    assertThat(BooleanUtils.xor(new boolean[] { true, true }), is(false));
}