Example usage for org.apache.commons.lang3.mutable MutableObject getValue

List of usage examples for org.apache.commons.lang3.mutable MutableObject getValue

Introduction

In this page you can find the example usage for org.apache.commons.lang3.mutable MutableObject getValue.

Prototype

@Override
public T getValue() 

Source Link

Document

Gets the value.

Usage

From source file:com.examples.with.different.packagename.ClassHierarchyIncludingInterfaces.java

public static Iterable<Class<?>> hierarchy(final Class<?> type, final Interfaces interfacesBehavior) {
    final Iterable<Class<?>> classes = new Iterable<Class<?>>() {

        @Override//  w  w  w  .  j  a va2  s  .co  m
        public Iterator<Class<?>> iterator() {
            final MutableObject<Class<?>> next = new MutableObject<Class<?>>(type);
            return new Iterator<Class<?>>() {

                @Override
                public boolean hasNext() {
                    return next.getValue() != null;
                }

                @Override
                public Class<?> next() {
                    final Class<?> result = next.getValue();
                    next.setValue(result.getSuperclass());
                    return result;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }

            };
        }

    };
    if (interfacesBehavior != Interfaces.INCLUDE) {
        return classes;
    }
    return new Iterable<Class<?>>() {

        @Override
        public Iterator<Class<?>> iterator() {
            final Set<Class<?>> seenInterfaces = new HashSet<Class<?>>();
            final Iterator<Class<?>> wrapped = classes.iterator();

            return new Iterator<Class<?>>() {
                Iterator<Class<?>> interfaces = Collections.<Class<?>>emptySet().iterator();

                @Override
                public boolean hasNext() {
                    return interfaces.hasNext() || wrapped.hasNext();
                }

                @Override
                public Class<?> next() {
                    if (interfaces.hasNext()) {
                        final Class<?> nextInterface = interfaces.next();
                        seenInterfaces.add(nextInterface);
                        return nextInterface;
                    }
                    final Class<?> nextSuperclass = wrapped.next();
                    final Set<Class<?>> currentInterfaces = new LinkedHashSet<Class<?>>();
                    walkInterfaces(currentInterfaces, nextSuperclass);
                    interfaces = currentInterfaces.iterator();
                    return nextSuperclass;
                }

                private void walkInterfaces(final Set<Class<?>> addTo, final Class<?> c) {
                    for (final Class<?> iface : c.getInterfaces()) {
                        if (!seenInterfaces.contains(iface)) {
                            addTo.add(iface);
                        }
                        walkInterfaces(addTo, iface);
                    }
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }

            };
        }
    };
}

From source file:com.romeikat.datamessie.core.base.util.publishedDates.loading.parallel.CountPublishedDateParallelLoadingStrategy.java

@Override
protected void mergeResults(final MutableObject<Long> previousResult, final MutableObject<Long> nextResult) {
    final long previousValue = previousResult.getValue();
    final long nextValue = nextResult.getValue();
    final long mergedValue = previousValue + nextValue;

    previousResult.setValue(mergedValue);
}

From source file:com.romeikat.datamessie.core.base.service.DocumentService.java

public void deprocessDocumentsOfSource(final StatelessSession statelessSession,
        final TaskExecution taskExecution, final long sourceId, final DocumentProcessingState targetState)
        throws TaskCancelledException {
    // Initialize
    final TaskExecutionWork work = taskExecution.reportWorkStart(
            String.format("Deprocessing documents of source %s to state %s", sourceId, targetState.getName()));
    final StatisticsRebuildingSparseTable statisticsToBeRebuilt = new StatisticsRebuildingSparseTable();

    // Determine minimum downloaded date
    final LocalDate minDownloadedDate = getMinDownloadedDate(statelessSession);

    // Process all download dates one after another, starting with the minimum downloaded date
    final MutableObject<LocalDate> downloadedDate = new MutableObject<LocalDate>(minDownloadedDate);
    while (downloadedDate.getValue() != null) {
        // Deprocess
        deprocessDocumentsOfSourceAndDownloadDate(statelessSession, taskExecution, sourceId, targetState,
                statisticsToBeRebuilt, downloadedDate.getValue());

        // Prepare for next iteration
        final LocalDate nextDownloadedDate = getNextDownloadedDate(downloadedDate.getValue());
        downloadedDate.setValue(nextDownloadedDate);
    }/*from  w  ww  . j a  va 2  s. c  o m*/

    // Rebuild statistics
    final IStatisticsManager statisticsManager = sharedBeanProvider.getSharedBean(IStatisticsManager.class);
    if (statisticsManager != null) {
        statisticsManager.rebuildStatistics(statisticsToBeRebuilt);
    }

    // Done
    taskExecution.reportWorkEnd(work);
}

From source file:io.restassured.module.mockmvc.ResultHandlerTest.java

@Test
public void supports_using_result_handlers_using_the_response_dsl() {
    MutableObject<Boolean> mutableObject = new MutableObject<Boolean>(false);

    RestAssuredMockMvc.given().header(new Header("headerName", "John Doe")).when().get("/header").then()
            .apply(print(), customResultHandler(mutableObject)).statusCode(200)
            .body("headerName", equalTo("John Doe"));

    assertThat(mutableObject.getValue(), is(true));
}

From source file:com.jayway.restassured.module.mockmvc.ResultHandlerTest.java

@Test
public void supports_using_result_handlers_using_the_response_dsl() {
    MutableObject<Boolean> mutableObject = new MutableObject<Boolean>(false);

    given().header(new Header("headerName", "John Doe")).when().get("/header").then()
            .apply(print(), customResultHandler(mutableObject)).statusCode(200)
            .body("headerName", equalTo("John Doe"));

    assertThat(mutableObject.getValue(), is(true));
}

From source file:com.jayway.restassured.module.mockmvc.ResultHandlerTest.java

@Test
public void supports_using_result_handlers_using_the_dsl() {
    MutableObject<Boolean> mutableObject = new MutableObject<Boolean>(false);

    given().resultHandlers(print(), customResultHandler(mutableObject))
            .header(new Header("headerName", "John Doe")).when().get("/header").then().statusCode(200)
            .body("headerName", equalTo("John Doe"));

    assertThat(mutableObject.getValue(), is(true));
}

From source file:io.restassured.module.mockmvc.ResultHandlerTest.java

@Test
public void merges_result_handlers_using_the_dsl() {
    MutableObject<Boolean> mutableObject1 = new MutableObject<Boolean>(false);
    MutableObject<Boolean> mutableObject2 = new MutableObject<Boolean>(false);

    RestAssuredMockMvc.given().header(new Header("headerName", "John Doe")).when().get("/header").then()
            .apply(customResultHandler(mutableObject1)).apply(customResultHandler(mutableObject2))
            .statusCode(200).body("headerName", equalTo("John Doe"));

    assertThat(mutableObject1.getValue(), is(true));
    assertThat(mutableObject2.getValue(), is(true));
}

From source file:io.restassured.module.mockmvc.ResultHandlerTest.java

@Test
public void supports_defining_result_handlers_statically() {
    MutableObject<Boolean> mutableObject1 = new MutableObject<Boolean>(false);
    MutableObject<Boolean> mutableObject2 = new MutableObject<Boolean>(false);
    RestAssuredMockMvc.resultHandlers(customResultHandler(mutableObject1), customResultHandler(mutableObject2));

    RestAssuredMockMvc.given().header(new Header("headerName", "John Doe")).when().get("/header").then()
            .statusCode(200).body("headerName", equalTo("John Doe"));

    assertThat(mutableObject1.getValue(), is(true));
    assertThat(mutableObject2.getValue(), is(true));
}

From source file:com.jayway.restassured.module.mockmvc.ResultHandlerTest.java

@Test
public void supports_defining_result_handlers_statically() {
    MutableObject<Boolean> mutableObject1 = new MutableObject<Boolean>(false);
    MutableObject<Boolean> mutableObject2 = new MutableObject<Boolean>(false);
    RestAssuredMockMvc.resultHandlers(customResultHandler(mutableObject1), customResultHandler(mutableObject2));

    given().header(new Header("headerName", "John Doe")).when().get("/header").then().statusCode(200)
            .body("headerName", equalTo("John Doe"));

    assertThat(mutableObject1.getValue(), is(true));
    assertThat(mutableObject2.getValue(), is(true));
}

From source file:io.restassured.module.mockmvc.ResultHandlerTest.java

@Test
public void merges_statically_defined_result_handlers_with_dsl_defined_using_response_spec() {
    MutableObject<Boolean> mutableObject1 = new MutableObject<Boolean>(false);
    MutableObject<Boolean> mutableObject2 = new MutableObject<Boolean>(false);
    RestAssuredMockMvc.resultHandlers(customResultHandler(mutableObject1));

    RestAssuredMockMvc.given().header(new Header("headerName", "John Doe")).when().get("/header").then()
            .apply(customResultHandler(mutableObject2)).statusCode(200).body("headerName", equalTo("John Doe"));

    assertThat(mutableObject1.getValue(), is(true));
    assertThat(mutableObject2.getValue(), is(true));
}