dev.marksman.collectionviews.CrossJoinVector 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 CrossJoinVector extends ConcreteVector>
implements NonEmptyVector> {
private final NonEmptyVector first;
private final NonEmptyVector second;
private final int size;
private final int stride;
private CrossJoinVector(NonEmptyVector first, NonEmptyVector 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 CrossJoinVector crossJoinVector(NonEmptyVector first, NonEmptyVector second) {
return new CrossJoinVector<>(first, second);
}
}