Search in sources :

Example 1 with StorelessUnivariateStatistic

use of org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic in project uPortal by Jasig.

the class JpaStatisticalSummaryTest method testStorelessUnivariateStatistic.

public void testStorelessUnivariateStatistic(StorelessUnivariateStatistic sus, double expected) throws Exception {
    assertEquals(expected, sus.getResult(), 0.1);
    final ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();
    // Configure Jackson to just use fields
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
    mapper.addMixInAnnotations(Object.class, IgnoreTypeMixIn.class);
    final FilterProvider filters = new SimpleFilterProvider().addFilter("storedDataFilter", SimpleBeanPropertyFilter.serializeAllExcept("storedData"));
    final ObjectWriter ssWriter = mapper.writer(filters);
    final ObjectReader ssReader = mapper.reader(sus.getClass());
    final String susString = ssWriter.writeValueAsString(sus);
    System.out.println(susString);
    final StorelessUnivariateStatistic newSus = ssReader.readValue(susString);
    assertEquals(expected, newSus.getResult(), 0.1);
}
Also used : SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider) StorelessUnivariateStatistic(org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FilterProvider(com.fasterxml.jackson.databind.ser.FilterProvider) SimpleFilterProvider(com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 FilterProvider (com.fasterxml.jackson.databind.ser.FilterProvider)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 StorelessUnivariateStatistic (org.apache.commons.math3.stat.descriptive.StorelessUnivariateStatistic)1