dev.marksman.collectionviews.ImmutableCrossJoinVector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of collection-views Show documentation
Show all versions of collection-views Show documentation
Low overhead, protected views over Java collections
package dev.marksman.collectionviews;
import com.jnape.palatable.lambda.adt.hlist.Tuple2;
import static com.jnape.palatable.lambda.adt.hlist.HList.tuple;
final class ImmutableCrossJoinVector extends ConcreteVector>
implements ImmutableNonEmptyVector> {
private final ImmutableNonEmptyVector first;
private final ImmutableNonEmptyVector second;
private final int size;
private final int stride;
private ImmutableCrossJoinVector(ImmutableNonEmptyVector first, ImmutableNonEmptyVector second) {
this.first = first;
this.second = second;
this.stride = second.size();
this.size = first.size() * stride;
}
@Override
public int size() {
return size;
}
@Override
public Tuple2 unsafeGet(int index) {
if (index < 0 || index >= size) {
throw new IndexOutOfBoundsException();
}
return tuple(first.unsafeGet(index / stride),
second.unsafeGet(index % stride));
}
static ImmutableCrossJoinVector immutableCrossJoinVector(ImmutableNonEmptyVector first, ImmutableNonEmptyVector second) {
return new ImmutableCrossJoinVector<>(first, second);
}
}