
com.trigonic.utils.test.junit.AbstractCartesianProduct Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of test-utils Show documentation
Show all versions of test-utils Show documentation
Provides utilities for testing
The newest version!
package com.trigonic.utils.test.junit;
import java.util.AbstractList;
import java.util.List;
public abstract class AbstractCartesianProduct extends AbstractList {
private List head;
private List tail;
public AbstractCartesianProduct(List head, List tail) {
this.head = head;
this.tail = tail;
}
@Override
public E get(int index) {
if (index < 0 || index >= size()) {
throw new IndexOutOfBoundsException();
}
int headIndex = index / tail.size();
int tailIndex = index % tail.size();
return combine(head.get(headIndex), tail.get(tailIndex));
}
@SuppressWarnings("hiding")
protected abstract E combine(T head, T tail);
@Override
public int size() {
return head.size() * tail.size();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy