org.jooq.lambda.function.Function2 Java Examples

The following examples show how to use org.jooq.lambda.function.Function2. 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: TransposedPreferenceData.java    From RankSys with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Constructor with custom converters between IdxPref and IdPref.
 *
 * @param recommenderData preference data to be transposed
 * @param idPrefFun converter from item IdPref to user IdPref
 * @param idxPrefFun converter from item IdxPref to item IdxPref
 */
public TransposedPreferenceData(FastPreferenceData<U, I> recommenderData,
                                Function2<U, IdPref<I>, IdPref<U>> idPrefFun,
                                Function2<Integer, IdxPref, IdxPref> idxPrefFun) {
    this.d = recommenderData;
    this.idPrefFun = idPrefFun;
    this.idxPrefFun = idxPrefFun;
}
 
Example #2
Source File: JOOLUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenFunction_whenAppliedPartially_shouldAddNumberToPartialArgument() {
    // given
    Function2<Integer, Integer, Integer> addTwoNumbers = (v1, v2) -> v1 + v2;
    addTwoNumbers.toBiFunction();
    Function1<Integer, Integer> addToTwo = addTwoNumbers.applyPartially(2);

    // when
    Integer result = addToTwo.apply(5);

    // then
    assertEquals(result, (Integer) 7);
}
 
Example #3
Source File: AuthSourceHarness.java    From waltz with Apache License 2.0 4 votes vote down vote up
private static int updateDecoratorsForAuthSource(DSLContext dsl, AuthoritativeRatingVantagePoint ratingVantagePoint) {
    System.out.println("Updating decorators for: " + ratingVantagePoint);
    LogicalFlowDecorator lfd = LOGICAL_FLOW_DECORATOR.as("lfd");

    EntityReference vantagePoint = ratingVantagePoint.vantagePoint();
    Long appId = ratingVantagePoint.applicationId();
    EntityReference dataType = ratingVantagePoint.dataType();
    AuthoritativenessRating rating = ratingVantagePoint.rating();

    SelectConditionStep<Record1<Long>> orgUnitSubselect = DSL.select(ENTITY_HIERARCHY.ID)
            .from(ENTITY_HIERARCHY)
            .where(ENTITY_HIERARCHY.KIND.eq(vantagePoint.kind().name()))
            .and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(vantagePoint.id()));

    SelectConditionStep<Record1<Long>> dataTypeSubselect = DSL.select(ENTITY_HIERARCHY.ID)
            .from(ENTITY_HIERARCHY)
            .where(ENTITY_HIERARCHY.KIND.eq(EntityKind.DATA_TYPE.name()))
            .and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(dataType.id()));


    Condition usingAuthSource = LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(appId);
    Condition notUsingAuthSource = LOGICAL_FLOW.SOURCE_ENTITY_ID.ne(appId);

    Function2<Condition, String, Update<LogicalFlowDecoratorRecord>> mkQuery = (appScopingCondition, ratingName) -> dsl
            .update(LOGICAL_FLOW_DECORATOR)
            .set(LOGICAL_FLOW_DECORATOR.RATING, ratingName)
            .where(LOGICAL_FLOW_DECORATOR.ID.in(
                    DSL.select(lfd.ID)
                            .from(lfd)
                            .innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(lfd.LOGICAL_FLOW_ID))
                            .innerJoin(APPLICATION)
                            .on(APPLICATION.ID.eq(LOGICAL_FLOW.TARGET_ENTITY_ID)
                                    .and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name())))
                            .where(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name())
                                    .and(appScopingCondition)
                                    .and(APPLICATION.ORGANISATIONAL_UNIT_ID.in(orgUnitSubselect))
                                    .and(lfd.DECORATOR_ENTITY_KIND.eq(EntityKind.DATA_TYPE.name()))
                                    .and(lfd.DECORATOR_ENTITY_ID.in(dataTypeSubselect)))
                            .and(lfd.RATING.in(AuthoritativenessRating.NO_OPINION.name(), AuthoritativenessRating.DISCOURAGED.name()))

            ));

    Update<LogicalFlowDecoratorRecord> updateAuthSources = mkQuery.apply(usingAuthSource, rating.name());
    Update<LogicalFlowDecoratorRecord> updateNonAuthSources = mkQuery.apply(notUsingAuthSource, AuthoritativenessRating.DISCOURAGED.name());
    int authSourceUpdateCount = updateAuthSources.execute();
    System.out.printf("Updated %s Authoritative decorators for: %s \r\n", authSourceUpdateCount, ratingVantagePoint);
    int nonAuthSourceUpdateCount = updateNonAuthSources.execute();
    System.out.printf("Updated %s Non-Auth decorators for: %s \r\n", nonAuthSourceUpdateCount, ratingVantagePoint);

    return authSourceUpdateCount + nonAuthSourceUpdateCount;
}
 
Example #4
Source File: LogicalFlowDecoratorDao.java    From waltz with Apache License 2.0 4 votes vote down vote up
public int updateDecoratorsForAuthSource(AuthoritativeRatingVantagePoint ratingVantagePoint) {
    LogicalFlowDecorator lfd = LOGICAL_FLOW_DECORATOR.as("lfd");

    EntityReference vantagePoint = ratingVantagePoint.vantagePoint();
    Long appId = ratingVantagePoint.applicationId();
    EntityReference dataType = ratingVantagePoint.dataType();
    AuthoritativenessRating rating = ratingVantagePoint.rating();

    SelectConditionStep<Record1<Long>> orgUnitSubselect = DSL.select(ENTITY_HIERARCHY.ID)
            .from(ENTITY_HIERARCHY)
            .where(ENTITY_HIERARCHY.KIND.eq(vantagePoint.kind().name()))
            .and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(vantagePoint.id()));

    SelectConditionStep<Record1<Long>> dataTypeSubselect = DSL.select(ENTITY_HIERARCHY.ID)
            .from(ENTITY_HIERARCHY)
            .where(ENTITY_HIERARCHY.KIND.eq(DATA_TYPE.name()))
            .and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(dataType.id()));

    Condition usingAuthSource = LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(appId);
    Condition notUsingAuthSource = LOGICAL_FLOW.SOURCE_ENTITY_ID.ne(appId);

    Function2<Condition, String, Update<LogicalFlowDecoratorRecord>> mkQuery = (appScopingCondition, ratingName) -> dsl
            .update(LOGICAL_FLOW_DECORATOR)
            .set(LOGICAL_FLOW_DECORATOR.RATING, ratingName)
            .where(LOGICAL_FLOW_DECORATOR.ID.in(
                    DSL.select(lfd.ID)
                            .from(lfd)
                            .innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(lfd.LOGICAL_FLOW_ID))
                            .innerJoin(APPLICATION)
                            .on(APPLICATION.ID.eq(LOGICAL_FLOW.TARGET_ENTITY_ID)
                                    .and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name())))
                            .where(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name())
                                    .and(appScopingCondition)
                                    .and(APPLICATION.ORGANISATIONAL_UNIT_ID.in(orgUnitSubselect))
                                    .and(lfd.DECORATOR_ENTITY_KIND.eq(DATA_TYPE.name()))
                                    .and(lfd.DECORATOR_ENTITY_ID.in(dataTypeSubselect)))
                            .and(lfd.RATING.in(AuthoritativenessRating.NO_OPINION.name(), AuthoritativenessRating.DISCOURAGED.name()))

            ));

    Update<LogicalFlowDecoratorRecord> updateAuthSources = mkQuery.apply(usingAuthSource, rating.name());
    Update<LogicalFlowDecoratorRecord> updateNonAuthSources = mkQuery.apply(notUsingAuthSource, AuthoritativenessRating.DISCOURAGED.name());
    int authSourceUpdateCount = updateAuthSources.execute();
    int nonAuthSourceUpdateCount = updateNonAuthSources.execute();
    return authSourceUpdateCount + nonAuthSourceUpdateCount;
}