<commit_before>package org.xcsp.common;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.IntBinaryOperator;
import java.util.function.IntConsumer;
import java.util.function.IntFunction;
import java.util.function.IntPredicate;
import java.util.function.IntUnaryOperator;
import java.util.stream.IntStream;

import org.xcsp.common.Interfaces.IVar;
import org.xcsp.common.Interfaces.Intx2Consumer;
import org.xcsp.common.Interfaces.Intx2Function;
import org.xcsp.common.Interfaces.Intx2Predicate;
import org.xcsp.common.Interfaces.Intx3Consumer;
import org.xcsp.common.Interfaces.Intx3Function;
import org.xcsp.common.Interfaces.Intx4Consumer;
import org.xcsp.common.Interfaces.Intx4Function;
import org.xcsp.common.Interfaces.Intx5Consumer;
import org.xcsp.common.Interfaces.Intx5Function;

public class Range implements Iterable<Integer> {
	public int minIncluded, maxIncluded, step;

	public Range(int minIncluded, int maxIncluded, int step) {
		this.minIncluded = minIncluded;
		this.maxIncluded = maxIncluded;
		this.step = step;
		Utilities.control(step > 0 && minIncluded <= maxIncluded, "Bad values of parameters");
	}

	public Range(int minIncluded, int maxIncluded) {
		this(minIncluded, maxIncluded, 1);
	}

	public Range(int length) {
		this(0, length - 1, 1);
	}

	public Rangesx2 range(int minIncluded, int maxIncluded, int step) {
		return new Rangesx2(this, new Range(minIncluded, maxIncluded, step));
	}

	public Rangesx2 range(int minIncluded, int maxIncluded) {
		return new Rangesx2(this, new Range(minIncluded, maxIncluded));
	}

	public Rangesx2 range(int length) {
		return new Rangesx2(this, new Range(length));
	}

	public boolean isBasic() {
		return minIncluded == 0 && step == 1;
	}

	public boolean contains(int i) {
		return minIncluded <= i && i <= maxIncluded && ((i - minIncluded) % step == 0);
	}

	public int length() {
		return (maxIncluded - minIncluded + 1) / step;
	}

	public int[] toArray(IntUnaryOperator op) {
		// return IntStream.iterate(minIncluded, n -> n + step).takeWhile(n -> n <= maxIncluded).toArray(); // WAIT FOR JDK9
		List<Integer> list = new ArrayList<>();
		for (int i : this)
			list.add(op.applyAsInt(i));
		return list.stream().mapToInt(i -> i).toArray();
	}

	public int[] toArray() {
		return toArray(i -> i);
	}

	private <T extends IVar> List<T> selectVars(IntFunction<T> op, List<T> list) {
		for (int i : this) {
			T x = op.apply(i);
			if (x != null)
				list.add(x);
		}
		return list;
	}

	public <T extends IVar> T[] selectVars(IntFunction<T> f) {
		return Utilities.convert(selectVars(f, new ArrayList<>()));
	}

	public int[] select(IntPredicate p) {
		List<Integer> list = new ArrayList<>();
		for (int i : this)
			if (p.test(i))
				list.add(i);
		return list.stream().mapToInt(i -> i).toArray();
	}

	public int[] generate(IntFunction<Integer> f) {
		List<Integer> list = new ArrayList<>();
		for (int i : this) {
			Integer v = f.apply(i);
			if (v != null)
				list.add(v);
		}
		return list.stream().mapToInt(i -> i).toArray();
	}

	public void execute(IntConsumer c) {
		for (int i : this)
			c.accept(i);
	}

	@Override
	public Iterator<Integer> iterator() {
		return new Iterator<Integer>() {
			int cursor = minIncluded;

			public boolean hasNext() {
				return cursor <= maxIncluded;
			}

			public Integer next() {
				assert hasNext();
				int v = cursor;
				cursor += step;
				return v;
			}
		};
	}

	public static abstract class Ranges {
		public Range[] items;

		protected Ranges(Range[] items) {
			this.items = items;
		}

		public boolean contains(int... indexes) {
			Utilities.control(indexes.length == items.length, "bad number of indexes");
			return IntStream.range(0, indexes.length).allMatch(i -> items[i].contains(indexes[i]));
		}
	}

	public static class Rangesx2 extends Ranges {
		public Rangesx2(Range range1, Range range2) {
			super(new Range[] { range1, range2 });
		}

		public Rangesx3 range(int minIncluded, int maxIncluded, int step) {
			return new Rangesx3(items[0], items[1], new Range(minIncluded, maxIncluded, step));
		}

		public Rangesx3 range(int minIncluded, int maxIncluded) {
			return new Rangesx3(items[0], items[1], new Range(minIncluded, maxIncluded));
		}

		public Rangesx3 range(int length) {
			return new Rangesx3(items[0], items[1], new Range(length));
		}

		private <T extends IVar> List<T> selectVars(Intx2Function<T> op, List<T> list) {
			for (int i : items[0])
				items[1].selectVars(j -> op.apply(i, j), list);
			return list;
		}

		public <T extends IVar> T[] selectVars(Intx2Function<T> f) {
			return Utilities.convert(selectVars(f, new ArrayList<>()));
		}

		public void execute(Intx2Consumer c2) {
			for (int i : items[0])
				items[1].execute(j -> c2.accept(i, j));
		}

		public int[][] toArray(IntBinaryOperator op) {<commit_msg>Minor modifiation in class Range<commit_after>package org.xcsp.common;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.IntBinaryOperator;
import java.util.function.IntConsumer;
import java.util.function.IntFunction;
import java.util.function.IntPredicate;
import java.util.function.IntUnaryOperator;
import java.util.stream.IntStream;

import org.xcsp.common.Interfaces.IVar;
import org.xcsp.common.Interfaces.Intx2Consumer;
import org.xcsp.common.Interfaces.Intx2Function;
import org.xcsp.common.Interfaces.Intx2Predicate;
import org.xcsp.common.Interfaces.Intx3Consumer;
import org.xcsp.common.Interfaces.Intx3Function;
import org.xcsp.common.Interfaces.Intx4Consumer;
import org.xcsp.common.Interfaces.Intx4Function;
import org.xcsp.common.Interfaces.Intx5Consumer;
import org.xcsp.common.Interfaces.Intx5Function;

public class Range implements Iterable<Integer> {
	public int minIncluded, maxIncluded, step;

	public Range(int minIncluded, int maxIncluded, int step) {
		this.minIncluded = minIncluded;
		this.maxIncluded = maxIncluded;
		this.step = step;
		Utilities.control(step > 0 && minIncluded <= maxIncluded, "Bad values of parameters");
	}

	public Range(int minIncluded, int maxIncluded) {
		this(minIncluded, maxIncluded, 1);
	}

	public Range(int length) {
		this(0, length - 1, 1);
	}

	public Rangesx2 range(int minIncluded, int maxIncluded, int step) {
		return new Rangesx2(this, new Range(minIncluded, maxIncluded, step));
	}

	public Rangesx2 range(int minIncluded, int maxIncluded) {
		return new Rangesx2(this, new Range(minIncluded, maxIncluded));
	}

	public Rangesx2 range(int length) {
		return new Rangesx2(this, new Range(length));
	}

	public boolean isBasic() {
		return minIncluded == 0 && step == 1;
	}

	public boolean contains(int i) {
		return minIncluded <= i && i <= maxIncluded && ((i - minIncluded) % step == 0);
	}

	public int length() {
		return (maxIncluded - minIncluded + 1) / step;
	}

	public int[] toArray(IntUnaryOperator op) {
		// return IntStream.iterate(minIncluded, n -> n + step).takeWhile(n -> n <= maxIncluded).toArray(); // WAIT FOR JDK9
		List<Integer> list = new ArrayList<>();
		for (int i : this)
			list.add(op.applyAsInt(i));
		return list.stream().mapToInt(i -> i).toArray();
	}

	public int[] toArray() {
		return toArray(i -> i);
	}

	private <T extends IVar> List<T> selectVars(IntFunction<T> op, List<T> list) {
		for (int i : this) {
			T x = op.apply(i);
			if (x != null)
				list.add(x);
		}
		return list;
	}

	public <T extends IVar> T[] selectVars(IntFunction<T> f) {
		return Utilities.convert(selectVars(f, new ArrayList<>()));
	}

	public int[] select(IntPredicate p) {
		List<Integer> list = new ArrayList<>();
		for (int i : this)
			if (p.test(i))
				list.add(i);
		return list.stream().mapToInt(i -> i).toArray();
	}

	public int[] generate(IntFunction<Integer> f) {
		List<Integer> list = new ArrayList<>();
		for (int i : this) {
			Integer v = f.apply(i);
			if (v != null)
				list.add(v);
		}
		return list.stream().mapToInt(i -> i).toArray();
	}

	public void execute(IntConsumer c) {
		for (int i : this)
			c.accept(i);
	}

	@Override
	public Iterator<Integer> iterator() {
		return new Iterator<Integer>() {
			int cursor = minIncluded;

			public boolean hasNext() {
				return cursor <= maxIncluded;
			}

			public Integer next() {
				assert hasNext();
				int v = cursor;
				cursor += step;
				return v;
			}
		};
	}

	public static abstract class Ranges {
		public Range[] items;

		protected Ranges(Range[] items) {
			this.items = items;
		}

		public boolean contains(int... indexes) {
			Utilities.control(indexes.length == items.length, "bad number of indexes");
			return IntStream.range(0, indexes.length).allMatch(i -> items[i].contains(indexes[i]));
		}
	}

	public static class Rangesx2 extends Ranges {
		public Rangesx2(Range range1, Range range2) {
			super(new Range[] { range1, range2 });
		}

		public Rangesx3 range(int minIncluded, int maxIncluded, int step) {
			return new Rangesx3(items[0], items[1], new Range(minIncluded, maxIncluded, step));
		}

		public Rangesx3 range(int minIncluded, int maxIncluded) {
			return new Rangesx3(items[0], items[1], new Range(minIncluded, maxIncluded));
		}

		public Rangesx3 range(int length) {
			return new Rangesx3(items[0], items[1], new Range(length));
		}

		private <T extends IVar> List<T> selectVars(Intx2Function<T> op, List<T> list) {
			for (int i : items[0])
				items[1].selectVars(j -> op.apply(i, j), list);
			return list;
		}

		public <T extends IVar> T[] selectVars(Intx2Function<T> f) {
			return Utilities.convert(selectVars(f, new ArrayList<>()));
		}

		public <T extends IVar> T[][] selectVars2D(Intx2Function<T> op) {
			T[] vars = selectVars(op);
			int m = items[0].length();
			Utilities.control(vars.length % m == 0, "Bad value of m");
			T[][] t = (T[][]) Array.newInstance(vars[0].getClass(), vars.length / m, m);
			IntStream.range(0, t.length).forEach(i -> IntStream.range(0, m).forEach(j -> t[i][j] = vars[i * m + j]));
			return t;
		}

		public void execute(Intx2Consumer c2) {
			for (int i : items[0])
				items[1].execute(j -> c2.accept(i, j));
		}

		public int[][] toArray(IntBinaryOperator op) {
{'fraction_non_alphanumeric': 0.14130649299388198, 'fraction_numerical': 0.01115058219853957, 'mean_word_length': 4.085298544907175, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 75, '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': '6527640', 'n_tokens_mistral': 3870, 'n_tokens_neox': 3535, 'n_words': 881}