<commit_before>/*******************************************************************************
 * Copyright (c) 2008 IBM Corporation & CWI
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> (<EMAIL>) - initial API and implementation
 *    <NAME> (<EMAIL>)
 ********************************************************************************/

package org.eclipse.imp.pdb.facts.impl.reference;

import java.util.Iterator;
import java.util.LinkedList;

import org.eclipse.imp.pdb.facts.IList;
import org.eclipse.imp.pdb.facts.IListWriter;
import org.eclipse.imp.pdb.facts.IValue;
import org.eclipse.imp.pdb.facts.exceptions.FactTypeUseException;
import org.eclipse.imp.pdb.facts.exceptions.UnexpectedElementTypeException;
import org.eclipse.imp.pdb.facts.impl.Value;
import org.eclipse.imp.pdb.facts.impl.Writer;
import org.eclipse.imp.pdb.facts.type.Type;
import org.eclipse.imp.pdb.facts.type.TypeFactory;
import org.eclipse.imp.pdb.facts.visitors.IValueVisitor;
import org.eclipse.imp.pdb.facts.visitors.VisitorException;

public class List extends Value implements IList {
	private final Type eltType;
	private final LinkedList<IValue> content;
	private int fHash = 0;

	public List(Type eltType, LinkedList<IValue> listContent) {
		super(TypeFactory.getInstance().listType(eltType));
		
		this.eltType = eltType;
		this.content = listContent;
	}

	public Type getElementType(){
		return eltType;
	}

	public Iterator<IValue> iterator(){
		return content.iterator();
	}

	public int length(){
		return content.size();
	}

	public boolean isEmpty(){
		return content.isEmpty();
	}

	public IValue get(int i){
		return content.get(i);
	}
	
	public IList sublist(int offset, int length) {
		if (offset < 0 || length < 0 || offset + length >= content.size()) {
			throw new IndexOutOfBoundsException();
		}
		ListWriter w = new ListWriter(getElementType());
		for (int i = offset; i < offset + length; i++) {
			w.insert(content.get(i));
		}
		return w.done();
	}
	
	public IList put(int i, IValue elem) throws IndexOutOfBoundsException {<commit_msg>fixed off by one error<commit_after>/*******************************************************************************
 * Copyright (c) 2008 IBM Corporation & CWI
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> (<EMAIL>) - initial API and implementation
 *    <NAME> (<EMAIL>)
 ********************************************************************************/

package org.eclipse.imp.pdb.facts.impl.reference;

import java.util.Iterator;
import java.util.LinkedList;

import org.eclipse.imp.pdb.facts.IList;
import org.eclipse.imp.pdb.facts.IListWriter;
import org.eclipse.imp.pdb.facts.IValue;
import org.eclipse.imp.pdb.facts.exceptions.FactTypeUseException;
import org.eclipse.imp.pdb.facts.exceptions.UnexpectedElementTypeException;
import org.eclipse.imp.pdb.facts.impl.Value;
import org.eclipse.imp.pdb.facts.impl.Writer;
import org.eclipse.imp.pdb.facts.type.Type;
import org.eclipse.imp.pdb.facts.type.TypeFactory;
import org.eclipse.imp.pdb.facts.visitors.IValueVisitor;
import org.eclipse.imp.pdb.facts.visitors.VisitorException;

public class List extends Value implements IList {
	private final Type eltType;
	private final LinkedList<IValue> content;
	private int fHash = 0;

	public List(Type eltType, LinkedList<IValue> listContent) {
		super(TypeFactory.getInstance().listType(eltType));
		
		this.eltType = eltType;
		this.content = listContent;
	}

	public Type getElementType(){
		return eltType;
	}

	public Iterator<IValue> iterator(){
		return content.iterator();
	}

	public int length(){
		return content.size();
	}

	public boolean isEmpty(){
		return content.isEmpty();
	}

	public IValue get(int i){
		return content.get(i);
	}
	
	public IList sublist(int offset, int length) {
		if (offset < 0 || length < 0 || offset + length > content.size()) {
			throw new IndexOutOfBoundsException();
		}
		ListWriter w = new ListWriter(getElementType());
		for (int i = offset; i < offset + length; i++) {
			w.insert(content.get(i));
		}
		return w.done();
	}
	
	public IList put(int i, IValue elem) throws IndexOutOfBoundsException {
{'fraction_non_alphanumeric': 0.18107989464442492, 'fraction_numerical': 0.004828797190517998, 'mean_word_length': 4.790343074968233, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1559472', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1350, 'n_words': 342}