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

com.trigonic.utils.test.junit.AbstractCartesianProduct Maven / Gradle / Ivy

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