Example usage for org.apache.commons.lang.mutable MutableBoolean setValue

List of usage examples for org.apache.commons.lang.mutable MutableBoolean setValue

Introduction

In this page you can find the example usage for org.apache.commons.lang.mutable MutableBoolean setValue.

Prototype

public void setValue(Object value) 

Source Link

Document

Sets the value from any Boolean instance.

Usage

From source file:com.darkstar.beanCartography.utils.NameUtils.java

/**
 * @param o object instanct to check/*w  w  w  .  j ava2s.  c o m*/
 * @return <code>true</code> if any fields have names associated with them
 */
public static boolean hasFieldBusinessNames(Object o) {
    Preconditions.checkNotNull(o, "Object cannot be null");

    // look for business field annotation...
    Map<String, List<Field>> classFieldMap = getFields(o, true);
    final MutableBoolean hasBusinessName = new MutableBoolean(false);
    classFieldMap.values().stream().forEach(fieldList -> {
        Optional<Field> fieldOpt = fieldList.stream().filter(NameUtils::hasBusinessName).findFirst();
        fieldOpt.ifPresent(field -> hasBusinessName.setValue(field != null));
    });
    return hasBusinessName.booleanValue();
}

From source file:com.palantir.ptoss.util.Reflections.java

/**
 * Checks whether or not the specified {@link Annotation} exists in the passed {@link Object}'s
 * class hierarchy.//  w w  w . jav a  2s .  c o m
 * @param object object to check
 * @param annotation annotation to look for
 * @return true is a class in this passed object's type hierarchy is annotated with the
 * passed {@link Annotation}
 */
public static boolean isClassAnnotatedForClassHierarchy(Object object,
        final Class<? extends Annotation> annotation) {
    final MutableBoolean bool = new MutableBoolean(false);
    visitClassHierarchy(object.getClass(), new Visitor<Class<?>>() {
        public void visit(Class<?> klass) {
            if (klass.isAnnotationPresent(annotation)) {
                bool.setValue(true);
            }
        }
    });
    return bool.booleanValue();
}

From source file:com.evolveum.midpoint.schema.util.ObjectQueryUtil.java

public static boolean hasAllDefinitions(ObjectFilter filter) {
    final MutableBoolean hasAllDefinitions = new MutableBoolean(true);
    Visitor visitor = new Visitor() {
        @Override//w ww . j av  a  2s .  c  o  m
        public void visit(ObjectFilter filter) {
            if (filter instanceof ValueFilter) {
                ItemDefinition definition = ((ValueFilter<?>) filter).getDefinition();
                if (definition == null) {
                    hasAllDefinitions.setValue(false);
                }
            }
        }
    };
    filter.accept(visitor);
    return hasAllDefinitions.booleanValue();
}

From source file:com.digitalpebble.stormcrawler.protocol.httpclient.HttpProtocol.java

private static final byte[] toByteArray(final HttpEntity entity, int maxContent, MutableBoolean trimmed)
        throws IOException {

    if (entity == null)
        return new byte[] {};

    final InputStream instream = entity.getContent();
    if (instream == null) {
        return null;
    }//from  w  w  w. j av  a  2s.c om
    try {
        Args.check(entity.getContentLength() <= Integer.MAX_VALUE,
                "HTTP entity too large to be buffered in memory");
        int i = (int) entity.getContentLength();
        if (i < 0) {
            i = 4096;
        }
        final ByteArrayBuffer buffer = new ByteArrayBuffer(i);
        final byte[] tmp = new byte[4096];
        int l;
        int total = 0;
        while ((l = instream.read(tmp)) != -1) {
            // check whether we need to trim
            if (maxContent != -1 && total + l > maxContent) {
                buffer.append(tmp, 0, maxContent - total);
                trimmed.setValue(true);
                break;
            }
            buffer.append(tmp, 0, l);
            total += l;
        }
        return buffer.toByteArray();
    } finally {
        instream.close();
    }
}

From source file:net.itransformers.expect4java.Expect4JavaTest.java

@Test
public void testSetTimeout() throws IOException, MalformedPatternException {
    final MutableBoolean status = new MutableBoolean(false);
    e4j.setTimeout(new TimeoutMatch(1000L, it -> {
        status.setValue(true);
    }));//from w  w  w  .  jav a  2 s . c  o  m

    e4j.send("hello\n");
    e4j.expect(new GlobMatch("hello\n", it -> {
        System.out.println("Hello World!");
        Thread.sleep(1100);
        it.exp_continue();
    }));
    Assert.assertTrue(status.booleanValue());
}

From source file:net.itransformers.expect4java.Expect4JavaTest.java

@Test
public void testGlob() throws IOException, MalformedPatternException {
    final MutableBoolean status = new MutableBoolean(false);
    e4j.send("hello\n");
    e4j.expect(new GlobMatch("hello\n", it -> {
        System.out.println("Hello World!");
        status.setValue(true);
    }));/*from  www . j a  va  2s  .  c  om*/
    Assert.assertTrue(status.booleanValue());
}

From source file:com.metamx.druid.realtime.plumber.RealtimePlumberSchoolTest.java

@Test
public void testPersist() throws Exception {
    final MutableBoolean committed = new MutableBoolean(false);
    plumber.startJob();/* w w w  . ja v a 2  s  .co m*/
    plumber.persist(new Runnable() {
        @Override
        public void run() {
            committed.setValue(true);
        }
    });

    Stopwatch stopwatch = new Stopwatch().start();
    while (!committed.booleanValue()) {
        Thread.sleep(100);
        if (stopwatch.elapsed(TimeUnit.MILLISECONDS) > 1000) {
            throw new ISE("Taking too long to set perist value");
        }
    }
    plumber.finishJob();
}

From source file:mitm.common.util.SizeLimitedOutputStreamTest.java

@Test
public void testClose() throws IOException {
    final MutableBoolean closeCalled = new MutableBoolean();

    ByteArrayOutputStream bos = new ByteArrayOutputStream() {
        @Override//from  www. j a  va  2 s  .  c  om
        public void close() {
            closeCalled.setValue(true);
        }
    };

    SizeLimitedOutputStream slo = new SizeLimitedOutputStream(bos, 100);

    assertFalse(closeCalled.booleanValue());

    slo.close();

    assertTrue(closeCalled.booleanValue());
}

From source file:mitm.common.util.SizeLimitedOutputStreamTest.java

@Test
public void testFlush() throws IOException {
    final MutableBoolean flushCalled = new MutableBoolean();

    ByteArrayOutputStream bos = new ByteArrayOutputStream() {
        @Override//from ww w  . j a  v  a  2  s . co m
        public void flush() {
            flushCalled.setValue(true);
        }
    };

    SizeLimitedOutputStream slo = new SizeLimitedOutputStream(bos, 100);

    assertFalse(flushCalled.booleanValue());

    slo.flush();

    assertTrue(flushCalled.booleanValue());
}

From source file:net.itransformers.expect4java.Expect4JavaTest.java

@Test
public void testRegex() throws IOException, MalformedPatternException {
    final MutableBoolean status = new MutableBoolean(false);
    e4j.send("hello World\n");
    e4j.expect(new RegExpMatch("hello ([^\n]*)\n", (ExpectContext context) -> {
        System.out.println("Hello " + context.getMatch(1));
        status.setValue(true);
    }));/*from w  w w  .  j  a  v  a 2s.  c o  m*/
    Assert.assertTrue(status.booleanValue());
}