org.jooq.lambda.tuple.Tuple4 Java Examples

The following examples show how to use org.jooq.lambda.tuple.Tuple4. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChangeInitiativeGenerator.java    From waltz with Apache License 2.0 6 votes vote down vote up
private static ChangeInitiativeRecord buildChangeInitiativeRecord(Tuple4<Long, ChangeInitiativeKind, Long, String> t, List<Long> ouIds) {
    ChangeInitiativeRecord record = new ChangeInitiativeRecord();
    record.setDescription(t.v4);
    record.setName(t.v4);
    record.setProvenance("dummy");
    record.setExternalId("EXT" + t.v1 + (t.v3 != null ? "_" + t.v3 : ""));
    record.setKind(t.v2.name());
    record.setLifecyclePhase(randomPick(LifecyclePhase.values()).name());
    record.setId(t.v1);
    record.setParentId(t.v3);
    record.setStartDate(new Date(Instant.now().toEpochMilli()));
    record.setEndDate(new Date(
            Instant.now()
                .plusSeconds(RND.nextInt(60 * 60 * 24 * 365 * 2))
                .toEpochMilli()));
    record.setOrganisationalUnitId(randomPick(ouIds));
    record.setProvenance(SampleDataGenerator.SAMPLE_DATA_PROVENANCE);
    return record;

}
 
Example #2
Source File: SimplePreferenceData.java    From RankSys with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Loads an instance of the class from a stream of tuples possibly containing extra information.
 *
 * @param <U> type of user
 * @param <I> type of item
 * @param <O> type of additional information
 * @param tuples stream of user-item-value triples
 * @param uPrefFun creator of preference objects
 * @param iPrefFun creator of preference objects
 * @return a preference data object
 */
public static <U, I, O> SimplePreferenceData<U, I> load(Stream<Tuple4<U, I, Double, O>> tuples,
                                                        Function4<U, I, Double, O, ? extends IdPref<I>> uPrefFun,
                                                        Function4<U, I, Double, O, ? extends IdPref<U>> iPrefFun) {
    AtomicInteger numPreferences = new AtomicInteger(0);
    Map<U, List<IdPref<I>>> userMap = new HashMap<>();
    Map<I, List<IdPref<U>>> itemMap = new HashMap<>();

    tuples.forEach(t -> {
        numPreferences.incrementAndGet();
        userMap.computeIfAbsent(t.v1, v1 -> new ArrayList<>()).add(uPrefFun.apply(t));
        itemMap.computeIfAbsent(t.v2, v2 -> new ArrayList<>()).add(iPrefFun.apply(t));
    });

    return new SimplePreferenceData<>(userMap, itemMap, numPreferences.intValue());
}
 
Example #3
Source File: AllocationHarness.java    From waltz with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
        DSLContext dsl = ctx.getBean(DSLContext.class);

        AllocationSchemeService schemesService = ctx.getBean(AllocationSchemeService.class);
        MeasurableService measurableService = ctx.getBean(MeasurableService.class);
        MeasurableCategoryDao categoryDao  = ctx.getBean(MeasurableCategoryDao.class);
        MeasurableRatingService ratingService = ctx.getBean(MeasurableRatingService.class);
        ApplicationService applicationService = ctx.getBean(ApplicationService.class);

        Tuple4<Application, MeasurableCategory, List<Measurable>, AllocationScheme> stuff = setup(
                dsl,
                schemesService,
                measurableService,
                categoryDao,
                applicationService);

        addRating(ratingService, stuff, 0);
        addRating(ratingService, stuff, 1);
//        addRating(ratingService, stuff, 2);

//        addAllocation(dsl, stuff, 0, 50);
        addAllocation(dsl, stuff, 1, 20);

        Long measurableCategory = stuff.v2.id().get();


        dumpRatings(dsl, stuff.v4);
        dumpAllocs(dsl, stuff.v4);

        doDiff(dsl, measurableCategory);

        System.out.println(ratingService.findByCategory(measurableCategory));
    }
 
Example #4
Source File: AllocationHarness.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static void addAllocation(DSLContext dsl,
                                  Tuple4<Application, MeasurableCategory, List<Measurable>, AllocationScheme> stuff,
                                  int measurableIdx,
                                  int percentage) {
    AllocationRecord allocationRecord = dsl.newRecord(ALLOCATION);
    allocationRecord.setAllocationSchemeId(stuff.v4.id().get());
    allocationRecord.setEntityId(stuff.v1.entityReference().id());
    allocationRecord.setEntityKind(stuff.v1.entityReference().kind().name());
    allocationRecord.setAllocationPercentage(percentage);
    allocationRecord.setMeasurableId(stuff.v3.get(measurableIdx).id().get());
    allocationRecord.setLastUpdatedBy("admin");
    allocationRecord.setProvenance(PROVENANCE);

    allocationRecord.insert();
}
 
Example #5
Source File: AllocationHarness.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static void addRating(MeasurableRatingService ratingService, Tuple4<Application, MeasurableCategory, List<Measurable>, AllocationScheme> stuff, int measurableIdx) {
    SaveMeasurableRatingCommand command1 = ImmutableSaveMeasurableRatingCommand.builder()
            .entityReference(stuff.v1.entityReference())
            .measurableId(stuff.v3.get(measurableIdx).id().get())
            .provenance(PROVENANCE)
            .rating('G')
            .lastUpdate(UserTimestamp.mkForUser("admin"))
            .build();

    ratingService.save(command1);
}
 
Example #6
Source File: AllocationHarness.java    From waltz with Apache License 2.0 5 votes vote down vote up
private static Tuple4<Application, MeasurableCategory, List<Measurable>, AllocationScheme> setup(DSLContext dsl,
                                                                                                 AllocationSchemeService schemesService,
                                                                                                 MeasurableService measurableService,
                                                                                                 MeasurableCategoryDao categoryDao,
                                                                                                 ApplicationService applicationService) {
    deleteAll(dsl);
    Application app = mkApp(dsl, applicationService);
    MeasurableCategory category = mkCategory(dsl, categoryDao);
    List<Measurable> measurables = mkMeasurables(measurableService, category);
    AllocationScheme scheme = mkScheme(schemesService, category);

    return Tuple.tuple(app,category,measurables,scheme);
}
 
Example #7
Source File: PersonResolver.java    From waltz with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIBaseConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);

    InvolvementNameToIdResolver involvementNameToIdResolver = new InvolvementNameToIdResolver(dsl);
    PersonNameToEmpIdResolver personNameToEmpIdResolver = new PersonNameToEmpIdResolver(dsl);
    OrgNameToIdResolver orgNameToIdResolver = new OrgNameToIdResolver(dsl);

    Siphon<Tuple4<String, String, Optional<Long>, Optional<String>>> noOrgSiphon = mkSiphon(t -> !t.v3.isPresent());
    Siphon<Tuple4<String, String, Optional<Long>, Optional<String>>> noPersonSiphon = mkSiphon(t -> !t.v4.isPresent());


    Set<Tuple3<Long, String, Long>> orgEmpInvTuples = involvementNameToIdResolver
            .resolve(involvementKindName)
            .map(involvementKindId -> data
                    .stream()
                    .flatMap(t -> Stream
                            .of(t.v2.split(" / "))
                            .map(name -> tuple(t.v1, name)))
                    .distinct()
                    .map(t -> t.concat(orgNameToIdResolver.resolve(t.v1)))
                    .map(t -> t.concat(personNameToEmpIdResolver.resolve(t.v2)))
                    .filter(noOrgSiphon)
                    .filter(noPersonSiphon)
                    .map(t -> t
                            .skip2() // throw away raw-data
                            .map1(Optional::get) // empId
                            .map2(Optional::get) // orgId
                            .concat(involvementKindId))
                    .collect(Collectors.toSet()))
            .orElseThrow(() -> new IllegalArgumentException(format("Cannot find involvement kind: %s", involvementKindName)));

    dump("No Org", noOrgSiphon, t -> t.v1);
    dump("No Person", noPersonSiphon, t -> t.v2);

    Set<InvolvementRecord> records = map(orgEmpInvTuples, t -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), t.v1, t.v2, provenance, t.v3, true));
    dsl.batchInsert(records).execute();

}
 
Example #8
Source File: ChangeInitiativeGenerator.java    From waltz with Apache License 2.0 5 votes vote down vote up
private List<ChangeInitiativeRecord> createCiRecords(List<Long> ouIds) {
    AtomicLong idCtr = new AtomicLong();
    return IntStream.range(0, NUM_CHANGE_INITIATIVES)
            .boxed()
            .flatMap(i -> {
                long initiativeId = idCtr.incrementAndGet();
                Tuple4<Long, ChangeInitiativeKind, Long, String> initiative = tuple(initiativeId, INITIATIVE, null, mkName());

                Stream<Tuple4<Long, ChangeInitiativeKind, Long, String>> children = IntStream
                        .range(0, RND.nextInt(4))
                        .boxed()
                        .flatMap(x -> {
                            long programmeId = idCtr.incrementAndGet();
                            Stream<Tuple4<Long, ChangeInitiativeKind, Long, String>> programmes = Stream.of(tuple(programmeId, PROGRAMME, initiativeId, mkName()));
                            Stream<Tuple4<Long, ChangeInitiativeKind, Long, String>> projects = IntStream
                                    .range(0, RND.nextInt(4))
                                    .boxed()
                                    .map(y -> tuple(idCtr.incrementAndGet(), PROJECT, programmeId, mkName()));

                            return Stream.concat(
                                    programmes, projects);
                        });

                return Stream.concat(Stream.of(initiative), children);
            })
            .map(t -> buildChangeInitiativeRecord(t, ouIds))
            .collect(toList());
}
 
Example #9
Source File: DefaultNamePolicyTest.java    From json2java4idea with Apache License 2.0 4 votes vote down vote up
@Parameters(name = "{0}")
public static Collection<Tuple4<DefaultNamePolicy, String, TypeName, String>> fixtures() {
    return Arrays.asList(
            Tuple.tuple(
                    DefaultNamePolicy.CLASS,
                    "class_name",
                    TypeName.OBJECT,
                    "ClassName"
            ),
            Tuple.tuple(
                    DefaultNamePolicy.METHOD,
                    "method_name",
                    TypeName.OBJECT,
                    "getMethodName"
            ),
            Tuple.tuple(
                    DefaultNamePolicy.METHOD,
                    "method_name",
                    TypeName.BOOLEAN,
                    "isMethodName"
            ),
            Tuple.tuple(
                    DefaultNamePolicy.METHOD,
                    "method_name",
                    ClassName.get(Boolean.class),
                    "isMethodName"
            ),
            Tuple.tuple(
                    DefaultNamePolicy.FIELD,
                    "field_name",
                    TypeName.OBJECT,
                    "fieldName"
            ),
            Tuple.tuple(
                    DefaultNamePolicy.PARAMETER,
                    "parameter_name",
                    TypeName.OBJECT,
                    "parameterName"
            )
    );
}
 
Example #10
Source File: DefaultNamePolicyTest.java    From json2java4idea with Apache License 2.0 4 votes vote down vote up
public EnumTest(@Nonnull Tuple4<DefaultNamePolicy, String, TypeName, String> fixture) {
    underTest = fixture.v1();
    name = fixture.v2();
    type = fixture.v3();
    expected = fixture.v4();
}
 
Example #11
Source File: SimplePreferenceData.java    From RankSys with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Loads a SimplePreferenceData from a stream of user-item-value triples.
 *
 * @param <U> user type
 * @param <I> item type
 * @param tuples user-item-value triples
 * @return instance of SimplePreferenceData containing the information in the input
 */
public static <U, I> SimplePreferenceData<U, I> load(Stream<Tuple3<U, I, Double>> tuples) {
    return load((Stream<Tuple4<U, I, Double, Void>>) tuples.map(t -> t.concat((Void) null)),
            (u, i, v, o) -> new IdPref<>(i, v), (u, i, v, o) -> new IdPref<>(u, v));
}