public abstract class Combination<A extends State> {

    private A reference;
    private List<A> neighborhood;

    protected Combination(A reference, A... neighbors) throws InvalidStateException {
        if (reference == null || neighbors == null) {
            throw new InvalidStateException();
        }
        this.reference = reference;
        this.neighborhood = new ArrayList<A>();
        for (int i = 0; i < neighbors.length; i++) {
            this.neighborhood.add(neighbors[i]);
        }
    }

    public A getReferenceState() {
        return this.reference;
    }

    public List<A> getNeighborhood() {
        return this.neighborhood;
    }
} public final class DimensionalCombination extends Combination<DimensionalState> {

	public DimensionalCombination(DimensionalState reference, DimensionalState... neighbors) throws InvalidStateException {
		super(reference, neighbors);
	}

} public final class DimensionalState extends State {

	public DimensionalState(String name, int value) {
		super(name, value);
	}

} public final class DimensionalTransition extends Transition<DimensionalCombination,DimensionalState> {

	public DimensionalTransition(DimensionalCombination combination, DimensionalState state) throws InvalidCombinationException, InvalidStateException {
		super(combination, state);
	}

} public abstract class State {

    private String name;
    private int value;

    protected State(String name, int value) {
        if (name == null) {
            throw new IllegalArgumentException();
        }
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return this.name;
    }

    public int getValue() {
        return this.value;
    }

} public abstract class Transition<O extends Combination, A extends State> {

    private O combination;
    private A state;

    protected Transition(O combination, A state) throws InvalidCombinationException, InvalidStateException {
        if (combination == null) {
            throw new InvalidCombinationException();
        }
        if (state == null) {
            throw new InvalidStateException();
        }
        this.combination = combination;
        this.state = state;
    }

    public O getCombination() {
        return this.combination;
    }

    public A getState() {
        return this.state;
    }

} public class InvalidAbsoluteTimeLimitException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = 8503779819489685979L;

} public class InvalidCombinationException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = 884762124844706448L;

} public class InvalidDimensionalAmountException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = 1514291655215196494L;

} public class InvalidDimensionalSpaceException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = -859556206406629948L;

} public class InvalidInitialConditionException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = 3070196019858178183L;

} public class InvalidRelativeTimeLimitException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = -8421027467680752602L;

} public class InvalidSpaceException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = 9045617613507195324L;

} public class InvalidStateException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = -7435119307025647318L;

} public class InvalidTimeException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = 4810377526354040415L;

} public class InvalidTransitionException extends Exception {

    /**
     * Serialization management
     */
    private static final long serialVersionUID = 1848434169756515614L;

}
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Test;
import com.ghjansen.cas.core.ca.Combination;
import com.ghjansen.cas.core.ca.DimensionalCombination;
import com.ghjansen.cas.core.ca.DimensionalState;
import com.ghjansen.cas.core.ca.DimensionalTransition;
import com.ghjansen.cas.core.ca.State;
import com.ghjansen.cas.core.ca.Transition;
import com.ghjansen.cas.core.exception.InvalidAbsoluteTimeLimitException;
import com.ghjansen.cas.core.exception.InvalidCombinationException;
import com.ghjansen.cas.core.exception.InvalidDimensionalAmountException;
import com.ghjansen.cas.core.exception.InvalidDimensionalSpaceException;
import com.ghjansen.cas.core.exception.InvalidInitialConditionException;
import com.ghjansen.cas.core.exception.InvalidRelativeTimeLimitException;
import com.ghjansen.cas.core.exception.InvalidSpaceException;
import com.ghjansen.cas.core.exception.InvalidStateException;
import com.ghjansen.cas.core.exception.InvalidTimeException;
import com.ghjansen.cas.core.exception.InvalidTransitionException;
/*
 * CAS - Cellular Automata Simulator
 * Copyright (C) 2016  Guilherme Humberto Jansen
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.ghjansen.cas.core.physics;




/**
 * @author Guilherme Humberto Jansen (contact.ghjansen@gmail.com)
 */
public class UniverseTest {

	@Test
	public void dimensionalUniverseConstructor() throws CloneNotSupportedException, InvalidAbsoluteTimeLimitException,
			InvalidRelativeTimeLimitException, InvalidStateException, InvalidTransitionException, InvalidCombinationException, InvalidDimensionalAmountException,
			InvalidInitialConditionException, InvalidDimensionalSpaceException, InvalidSpaceException, InvalidTimeException {
		final DimensionalTime dimensionalTime = new DimensionalTime(1000, 1000);
		final Cell dimensionalCell = getNewValidDimensionalCell();
		final ArrayList<Cell> firstDimension = new ArrayList<Cell>();
		firstDimension.add(dimensionalCell);
		final DimensionalSpace dimensionalSpace = new DimensionalSpace(dimensionalTime, firstDimension, true);
		Universe dimensionalUniverse = new DimensionalUniverse(dimensionalSpace, dimensionalTime);
		Assert.assertTrue(dimensionalUniverse.getSpace().equals(dimensionalSpace));
		Assert.assertTrue(dimensionalUniverse.getTime().equals(dimensionalTime));
	}
	
	@Test(expected = InvalidSpaceException.class)
	public void dimensionalUniverseConstructorInvalidSpace() throws CloneNotSupportedException,
			InvalidAbsoluteTimeLimitException, InvalidRelativeTimeLimitException, InvalidSpaceException, InvalidTimeException{
		final DimensionalTime dimensionalTime = new DimensionalTime(1000, 1000);
		new DimensionalUniverse(null, dimensionalTime);
	}
	
	@Test(expected = InvalidTimeException.class)
	public void dimensionalUniverseConstructorInvalidTime() throws CloneNotSupportedException, InvalidAbsoluteTimeLimitException, InvalidRelativeTimeLimitException, InvalidStateException, InvalidTransitionException, InvalidCombinationException, InvalidDimensionalAmountException, InvalidInitialConditionException, InvalidDimensionalSpaceException, InvalidSpaceException, InvalidTimeException{
		final DimensionalTime dimensionalTime = new DimensionalTime(1000, 1000);
		final Cell dimensionalCell = getNewValidDimensionalCell();
		final ArrayList<Cell> firstDimension = new ArrayList<Cell>();
		firstDimension.add(dimensionalCell);
		final DimensionalSpace dimensionalSpace = new DimensionalSpace(dimensionalTime, firstDimension, true);
		new DimensionalUniverse(dimensionalSpace, null);
	}

	private Cell getNewValidDimensionalCell() throws InvalidStateException, InvalidTransitionException, InvalidCombinationException {
		final DimensionalState dimensionalBlackState = new DimensionalState("black", 0);
		final DimensionalState dimensionalWhiteState = new DimensionalState("white", 1);
		final DimensionalCombination dimensionalCombination = new DimensionalCombination(dimensionalWhiteState,