org.babyfish.jimmer.sql.fetcher.impl.DefaultRecursionStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql Show documentation
Show all versions of jimmer-sql Show documentation
A revolutionary ORM framework for both java and kotlin
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;
}
}