Search in sources :

Example 51 with BiFunction

use of java.util.function.BiFunction in project waltz by khartec.

the class EntityStatisticGenerator method createIntStatsFor.

private void createIntStatsFor(EntityStatisticDefinition defn, Application[] applications, EntityStatisticValueDao valueDao, int bound, BiFunction<StatisticValueState, Integer, String> outcomeFn) {
    Random rnd = new Random(System.currentTimeMillis());
    List<EntityStatisticValue> values = streamAppRefs(applications).map(appRef -> {
        StatisticValueState state = randomPick(StatisticValueState.values());
        int v = state == StatisticValueState.PROVIDED ? rnd.nextInt(bound) : 0;
        // naughty
        v = rnd.nextInt(bound);
        return ImmutableEntityStatisticValue.builder().entity(appRef).state(state).statisticId(defn.id().get()).current(true).createdAt(LocalDateTime.now()).value(Integer.toString(v)).outcome(outcomeFn.apply(state, v)).provenance(PROVENANCE).build();
    }).collect(toList());
    valueDao.bulkSaveValues(values);
}
Also used : IntStream(java.util.stream.IntStream) EntityHierarchyService(com.khartec.waltz.service.entity_hierarchy.EntityHierarchyService) ImmutableEntityReference(com.khartec.waltz.model.ImmutableEntityReference) BiFunction(java.util.function.BiFunction) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LocalDateTime(java.time.LocalDateTime) OrganisationalUnitDao(com.khartec.waltz.data.orgunit.OrganisationalUnitDao) EntityReference(com.khartec.waltz.model.EntityReference) Random(java.util.Random) EntityKind(com.khartec.waltz.model.EntityKind) ENTITY_STATISTIC_DEFINITION(com.khartec.waltz.schema.tables.EntityStatisticDefinition.ENTITY_STATISTIC_DEFINITION) DIConfiguration(com.khartec.waltz.service.DIConfiguration) Map(java.util.Map) DSLContext(org.jooq.DSLContext) EntityStatisticValueDao(com.khartec.waltz.data.entity_statistic.EntityStatisticValueDao) Application(com.khartec.waltz.model.application.Application) ApplicationDao(com.khartec.waltz.data.application.ApplicationDao) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) IOException(java.io.IOException) EntityStatisticDefinitionDao(com.khartec.waltz.data.entity_statistic.EntityStatisticDefinitionDao) com.khartec.waltz.model.entity_statistic(com.khartec.waltz.model.entity_statistic) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) ENTITY_STATISTIC_VALUE(com.khartec.waltz.schema.tables.EntityStatisticValue.ENTITY_STATISTIC_VALUE) Random(java.util.Random)

Aggregations

BiFunction (java.util.function.BiFunction)51 List (java.util.List)25 HashMap (java.util.HashMap)24 Map (java.util.Map)24 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)21 Collectors (java.util.stream.Collectors)18 Collections (java.util.Collections)15 Arrays (java.util.Arrays)14 Set (java.util.Set)14 Function (java.util.function.Function)14 Collection (java.util.Collection)13 IOException (java.io.IOException)12 IntStream (java.util.stream.IntStream)12 Mockito.mock (org.mockito.Mockito.mock)12 Before (org.junit.Before)11 Stream (java.util.stream.Stream)10 HashSet (java.util.HashSet)8 TimeUnit (java.util.concurrent.TimeUnit)8 Logger (org.apache.logging.log4j.Logger)8