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

org.babyfish.jimmer.sql.fetcher.impl.DefaultRecursionStrategy Maven / Gradle / Ivy

There is a newer version: 0.9.19
Show newest version
package org.babyfish.jimmer.sql.fetcher.impl;

import org.babyfish.jimmer.sql.fetcher.RecursionStrategy;

import java.util.Map;
import java.util.stream.IntStream;

class DefaultRecursionStrategy implements RecursionStrategy {

    private int depth;

    private static final DefaultRecursionStrategy[] DEFAULTS =
            IntStream.range(0, 10)
                    .mapToObj(DefaultRecursionStrategy::new)
                    .toArray(DefaultRecursionStrategy[]::new);

    private static final DefaultRecursionStrategy UNLIMITED =
            new DefaultRecursionStrategy<>(Integer.MAX_VALUE);

    @SuppressWarnings("unchecked")
    public static  DefaultRecursionStrategy of(int depth) {
        if (depth == Integer.MAX_VALUE) {
            return (DefaultRecursionStrategy) UNLIMITED;
        }
        if (depth < DEFAULTS.length) {
            return (DefaultRecursionStrategy) DEFAULTS[Math.max(depth, 0)];
        }
        return new DefaultRecursionStrategy<>(depth);
    }

    private DefaultRecursionStrategy(int depth) {
        this.depth = depth;
    }

    public int getDepth() {
        return depth;
    }

    @Override
    public boolean isRecursive(Args args) {
        return args.getDepth() < this.depth;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy