Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Seq.fullOuterJoin() #275

Open
lukaseder opened this issue Dec 14, 2016 · 2 comments
Open

Add Seq.fullOuterJoin() #275

lukaseder opened this issue Dec 14, 2016 · 2 comments

Comments

@lukaseder
Copy link
Member

No description provided.

@jmax01
Copy link

jmax01 commented Dec 14, 2016

Below is a rough example of a workaround:

import static java.util.Optional.*;
import static org.jooq.lambda.Seq.*;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jooq.lambda.Seq;
import org.jooq.lambda.tuple.Tuple2;
import org.junit.Test;

import lombok.Value;

public class JoolTest {

    @Test
    public void matchPositions() {

        List<Position> client1Positions = Stream.of(Position.of("ticker1", "client1", 0.0),
                Position.of("ticker2", "client1", 0.0), Position.of("ticker4", "client1", 0.0))
            .collect(Collectors.toList());

        List<Position> client2Positions = Stream.of(Position.of("ticker1", "client2", 0.0),
                Position.of("ticker3", "client2", 0.0), Position.of("ticker4", "client2", 0.0))
            .collect(Collectors.toList());

        Seq<Tuple2<Position, Position>> leftJoinClient1ToClient2 = seq(client1Positions).leftOuterJoin(client2Positions,
                Position::sameTicker);

        Seq<Tuple2<Position, Position>> rightJoinClient1ToClient2 = seq(client1Positions)
            .rightOuterJoin(client2Positions, Position::sameTicker);

        // Expected Output:
        //
        // (JoolTest.Position(ticker=ticker1, client=client1, notional=0.0), JoolTest.Position(ticker=ticker1,
        // client=client2, notional=0.0))
        // (JoolTest.Position(ticker=ticker2, client=client1, notional=0.0), null)
        // (JoolTest.Position(ticker=ticker4, client=client1, notional=0.0), JoolTest.Position(ticker=ticker4,
        // client=client2, notional=0.0))
        // (null, JoolTest.Position(ticker=ticker3, client=client2, notional=0.0))
        leftJoinClient1ToClient2.concat(rightJoinClient1ToClient2)
            .distinct()
            .stream()
            .forEach(System.out::println);

    }

    @Value(staticConstructor = "of")
    static class Position {

        String ticker;

        String client;

        double notional;

        public boolean sameTicker(Position that) {

            return ofNullable(that).filter(t -> getTicker().equals(t.getTicker()))
                .isPresent();

        }
    }

@lukaseder
Copy link
Member Author

Thanks, @jmax01

YETSDD added a commit to YETSDD/jOOL that referenced this issue May 31, 2020
Add the fullOuterJoin and fullOuterSelfJoin functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants