<commit_before>package net.sandius.rembulan.util;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

public class ReadOnlyArray<T> implements Iterable<T> {

	protected final T[] values;

	private ReadOnlyArray(T[] values) {
		this.values = values;
	}

	public static <T> ReadOnlyArray<T> wrap(T[] values) {
		return new ReadOnlyArray<T>(values);
	}

	public static <T> ReadOnlyArray<T> copyFrom(T[] values) {
		Check.notNull(values);
		return wrap(Arrays.copyOf(values, values.length));
	}

	public static <T> ReadOnlyArray<T> fromCollection(Class<T> clazz, Collection<T> c) {
		Check.notNull(clazz);
		Check.notNull(c);

		@SuppressWarnings("unchecked")
		T[] values = (T[]) Array.newInstance(clazz, c.size());

		Iterator<T> it = c.iterator();
		int i = 0;
		while (it.hasNext()) {
			values[i++] = it.next();
		}

		return wrap(values);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		ReadOnlyArray<?> that = (ReadOnlyArray<?>) o;

		return Arrays.deepEquals(this.values, that.values);
	}

	@Override
	public int hashCode() {
		return Arrays.deepHashCode(values);
	}

	public T get(int idx) {
		return values[idx];
	}

	// FIXME: size or length?
	public int size() {
		return values.length;
	}

	public boolean isEmpty() {
		return size() == 0;
	}

	@Override
	public Iterator<T> iterator() {
		return new Iterator<T>() {
			int i = 0;<commit_msg>Adding the update operation.<commit_after>package net.sandius.rembulan.util;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

public class ReadOnlyArray<T> implements Iterable<T> {

	protected final T[] values;

	private ReadOnlyArray(T[] values) {
		this.values = values;
	}

	public static <T> ReadOnlyArray<T> wrap(T[] values) {
		return new ReadOnlyArray<T>(values);
	}

	public static <T> ReadOnlyArray<T> copyFrom(T[] values) {
		Check.notNull(values);
		return wrap(Arrays.copyOf(values, values.length));
	}

	public static <T> ReadOnlyArray<T> fromCollection(Class<T> clazz, Collection<T> c) {
		Check.notNull(clazz);
		Check.notNull(c);

		@SuppressWarnings("unchecked")
		T[] values = (T[]) Array.newInstance(clazz, c.size());

		Iterator<T> it = c.iterator();
		int i = 0;
		while (it.hasNext()) {
			values[i++] = it.next();
		}

		return wrap(values);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		ReadOnlyArray<?> that = (ReadOnlyArray<?>) o;

		return Arrays.deepEquals(this.values, that.values);
	}

	@Override
	public int hashCode() {
		return Arrays.deepHashCode(values);
	}

	public T get(int idx) {
		return values[idx];
	}

	public ReadOnlyArray<T> update(int idx, T value) {
		if (get(idx) == value) {
			return this;
		}
		else {
			T[] copy = Arrays.copyOf(values, values.length);
			copy[idx] = value;
			return wrap(copy);
		}
	}

	// FIXME: size or length?
	public int size() {
		return values.length;
	}

	public boolean isEmpty() {
		return size() == 0;
	}

	@Override
	public Iterator<T> iterator() {
		return new Iterator<T>() {
			int i = 0;
{'fraction_non_alphanumeric': 0.151947665774606, 'fraction_numerical': 0.001784121320249777, 'mean_word_length': 4.13587786259542, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '6818004', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1178, 'n_words': 294}