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

org.matheclipse.generic.nested.IndexFunctionDiagonal Maven / Gradle / Ivy

The newest version!
package org.matheclipse.generic.nested;

import org.matheclipse.generic.interfaces.IIndexFunction;

/**
 * Evaluates to one of two given values. Useful for table generation.
 * 
 * @param 
 */
public class IndexFunctionDiagonal implements IIndexFunction {
	final T[] fValues;

	public IndexFunctionDiagonal(final T[] values) {
		fValues = values;
	}

	public T evaluate(final int[] index) {
		if (isMatched(index)) {
			return fValues[1];
		}
		return fValues[0];
	}

	protected boolean isMatched(final int[] index) {
		for (int i = 1; i < index.length; i++) {
			if (index[i] != index[i - 1]) {
				return false;
			}
		}
		return true;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy