<commit_before>package kcsaba.math.matrix.immutable;

import kcsaba.math.matrix.Matrix;
import kcsaba.math.matrix.Matrix2;
import kcsaba.math.matrix.Matrix3;
import kcsaba.math.matrix.Vector;
import kcsaba.math.matrix.Vector2;
import kcsaba.math.matrix.Vector3;
import kcsaba.math.matrix.Vector4;

/**
 * Factory for creating immutable matrices.
 * @author <NAME>
 */
public final class ImmutableMatrixFactory {

	/**
	 * Returns an immutable matrix with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableMatrix copy(Matrix source) {
		if (source instanceof ImmutableMatrix) return (ImmutableMatrix) source;
		if (source.getColumnCount() == 1) return copy((Vector) source);
		if (source.getRowCount() == 2 && source.getColumnCount() == 2) return new ImmutableMatrix2((Matrix2) source);
		if (source.getRowCount() == 3 && source.getColumnCount() == 3) return new ImmutableMatrix3((Matrix3) source);
		return new ImmutableMatrix(source);
	}

	/**
	 * Returns an immutable matrix with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableMatrix2 copy(Matrix2 source) {
		return new ImmutableMatrix2(source);
	}

	/**
	 * Returns an immutable matrix with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableMatrix3 copy(Matrix3 source) {
		return new ImmutableMatrix3(source);
	}

	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector copy(Vector source) {
		if (source instanceof ImmutableVector) return (ImmutableVector) source;
		switch (source.getRowCount()) {
			case 2: return new ImmutableVector2((Vector2)source);
			case 3: return new ImmutableVector3((Vector3)source);
			case 4: return new ImmutableVector4((Vector4)source);
			default: return new ImmutableVector(source);
		}
	}
	
	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector2 copy(Vector2 source) {
		if (source instanceof ImmutableVector2) return (ImmutableVector2) source;
		return new ImmutableVector2(source);
	}
	
	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector3 copy(Vector3 source) {
		if (source instanceof ImmutableVector3) return (ImmutableVector3) source;
		return new ImmutableVector3(source);
	}
	
	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector4 copy(Vector4 source) {
		if (source instanceof ImmutableVector4) return (ImmutableVector4) source;
		return new ImmutableVector4(source);
	}
	
	private static ImmutableMatrix create(ImmutableData data) {<commit_msg>Add createVector variants to ImmutableMatrixFactory.<commit_after>package kcsaba.math.matrix.immutable;

import kcsaba.math.matrix.Matrix;
import kcsaba.math.matrix.Matrix2;
import kcsaba.math.matrix.Matrix3;
import kcsaba.math.matrix.Vector;
import kcsaba.math.matrix.Vector2;
import kcsaba.math.matrix.Vector3;
import kcsaba.math.matrix.Vector4;

/**
 * Factory for creating immutable matrices.
 * @author <NAME>
 */
public final class ImmutableMatrixFactory {

	/**
	 * Creates a new immutable 2D column vector.
	 * @param x the x coordinate of the new vector
	 * @param y the y coordinate of the new vector
	 * @return the new vector
	 */
	public static ImmutableVector2 createVector(final double x, final double y) {
		return new ImmutableVector2(new ImmutableData() {

			@Override
			public double get(int row, int col) {
				if (col!=0) throw new IndexOutOfBoundsException();
				switch (row) {
					case 0: return x;
					case 1: return y;
					default: throw new IndexOutOfBoundsException();
				}
			}

			@Override
			public int getColumnCount() {
				return 1;
			}

			@Override
			public int getRowCount() {
				return 2;
			}
		});
	}
	
	/**
	 * Creates a new immutable 3D column vector.
	 * @param x the x coordinate of the new vector
	 * @param y the y coordinate of the new vector
	 * @param z the z coordinate of the new vector
	 * @return the new vector
	 */
	public static ImmutableVector3 createVector(final double x, final double y, final double z) {
		return new ImmutableVector3(new ImmutableData() {

			@Override
			public double get(int row, int col) {
				if (col!=0) throw new IndexOutOfBoundsException();
				switch (row) {
					case 0: return x;
					case 1: return y;
					case 2: return z;
					default: throw new IndexOutOfBoundsException();
				}
			}

			@Override
			public int getColumnCount() {
				return 1;
			}

			@Override
			public int getRowCount() {
				return 3;
			}
		});
	}
	
	/**
	 * Creates a new immutable 4D column vector.
	 * @param x the x coordinate of the new vector
	 * @param y the y coordinate of the new vector
	 * @param z the z coordinate of the new vector
	 * @param h the h coordinate of the new vector
	 * @return the new vector
	 */
	public static ImmutableVector4 createVector(final double x, final double y, final double z, final double h) {
		return new ImmutableVector4(new ImmutableData() {

			@Override
			public double get(int row, int col) {
				if (col!=0) throw new IndexOutOfBoundsException();
				switch (row) {
					case 0: return x;
					case 1: return y;
					case 2: return z;
					case 3: return h;
					default: throw new IndexOutOfBoundsException();
				}
			}

			@Override
			public int getColumnCount() {
				return 1;
			}

			@Override
			public int getRowCount() {
				return 4;
			}
		});
	}
	
	/**
	 * Returns an immutable matrix with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableMatrix copy(Matrix source) {
		if (source instanceof ImmutableMatrix) return (ImmutableMatrix) source;
		if (source.getColumnCount() == 1) return copy((Vector) source);
		if (source.getRowCount() == 2 && source.getColumnCount() == 2) return new ImmutableMatrix2((Matrix2) source);
		if (source.getRowCount() == 3 && source.getColumnCount() == 3) return new ImmutableMatrix3((Matrix3) source);
		return new ImmutableMatrix(source);
	}

	/**
	 * Returns an immutable matrix with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableMatrix2 copy(Matrix2 source) {
		return new ImmutableMatrix2(source);
	}

	/**
	 * Returns an immutable matrix with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableMatrix3 copy(Matrix3 source) {
		return new ImmutableMatrix3(source);
	}

	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector copy(Vector source) {
		if (source instanceof ImmutableVector) return (ImmutableVector) source;
		switch (source.getRowCount()) {
			case 2: return copy((Vector2)source);
			case 3: return copy((Vector3)source);
			case 4: return copy((Vector4)source);
			default: return new ImmutableVector(source);
		}
	}
	
	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector2 copy(Vector2 source) {
		if (source instanceof ImmutableVector2) return (ImmutableVector2) source;
		return createVector(source.getX(), source.getY());
	}
	
	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector3 copy(Vector3 source) {
		if (source instanceof ImmutableVector3) return (ImmutableVector3) source;
		return createVector(source.getX(), source.getY(), source.getZ());
	}
	
	/**
	 * Returns an immutable vector with the same values as the argument.
	 * @throws NullPointerException if {@code source} is {@code null}
	 */
	public static ImmutableVector4 copy(Vector4 source) {
		if (source instanceof ImmutableVector4) return (ImmutableVector4) source;
		return createVector(source.getX(), source.getY(), source.getZ(), source.getH());
	}
	
	private static ImmutableMatrix create(ImmutableData data) {
{'fraction_non_alphanumeric': 0.09857676154923005, 'fraction_numerical': 0.01271581894540364, 'mean_word_length': 4.019320843091335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5045338', 'n_tokens_mistral': 2773, 'n_tokens_neox': 2439, 'n_words': 888}