All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ly.mybatis.mapperservice.service.join.inject.Model Maven / Gradle / Ivy

The newest version!
package com.ly.mybatis.mapperservice.service.join.inject;

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

public class Model {
    private Object source;
    private Object from;
    private Object join;
    private Integer sourceId;
    private Integer fromId;
    private Integer joinId;

    public static  List of(Collection ts) {
        return ts.parallelStream()
                .map(t -> new Model().source(t).from(t).join(t))
                .collect(Collectors.toList());
    }

    public static List merge(Collection merge, Collection by) {
        Map> resultMap = by.parallelStream()
                .collect(Collectors.groupingBy(Model::join));

        return merge.parallelStream()
                .flatMap(m -> {
                    try {
                        return resultMap.getOrDefault(m.join, new ArrayList<>()).parallelStream()
                                .map(model -> m.copy().join(model.from()));
                    } catch (Exception e) {
                        e.printStackTrace();
                        return Stream.empty();
                    }
                })
                .collect(Collectors.toList());
    }

    public Model source(Object source) {
        this.source = source;
        this.sourceId = Optional.ofNullable(source).map(System::identityHashCode).orElse(null);
        return this;
    }

    public Model from(Object from) {
        this.from = from;
        this.fromId = Optional.ofNullable(from).map(System::identityHashCode).orElse(null);
        return this;
    }

    public Model join(Object join) {
        this.join = join;
        this.joinId = Optional.ofNullable(join).map(System::identityHashCode).orElse(null);
        return this;
    }

    public  T from() {
        return (T) from;
    }

    public  T join() {
        return (T) join;
    }

    public  T source() {
        return (T) source;
    }

    public Integer sourceId() {
        return sourceId;
    }

    public Integer fromId() {
        return fromId;
    }

    public Integer joinId() {
        return joinId;
    }

    public Model copy() {
        return new Model().source(source)
                .from(from)
                .join(join);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy