<commit_before>/**
 * 
 */
package urllistcompare.util;

import java.util.ArrayList;

/**
 * @author <NAME>
 * @email <EMAIL>
 * 
 * A generic LinkedList that can be used to implement both the lists of URLElement contained within the
 * URLNorm instances and the lists of URLNorm that make up the URLMap hashmap.
 *
 */
public class LinkedList<T>{
	private ListNode head;
	private int length;

	public LinkedList() {
		this.head = null;
		this.length = 0;
	}
	
	public LinkedList(T payload) {
		this.head = new ListNode(payload, null);
		this.length = 1;
	}
	
	/**
	 * Adds a new node to the head of the list.
	 * @param payload
	 */
	public void add(T payload){
		ListNode newNode = new ListNode(payload, head);
		head = newNode;
		length++;
	}
	
	// Returns the ListNode that includes the payload passed as argument, or null.
	private ListNode find(T payload){
		ListNode current = head;
		while(current != null && !current.payload.equals(payload)){
			current = current.next;
		}
		return current;
	}
	
	/**
	 * Checks if a specific payload is in the list
	 * @param payload the element that is being searched for
	 * @return true if found, false if not found
	 */
	public boolean isInList(T payload){
		boolean output = false;
		if(find(payload) != null){
			output = true;
		}
		return output;
	}
	
	/**
	 * Outputs the contents of the list as an ArrayList
	 * @return an ArrayList of the payloads of the list nodes, or null if the list is empty
	 */
	public ArrayList<T> toArrayList(){
		if(head == null) return null; // Faster and safer
		ArrayList<T> output = new ArrayList<T>(length);
		ListNode current = head;
		while(current != null){
			output.add(current.payload);
			current = current.next;
		}
		output.trimToSize();
		return output;
	}
	
	// TODO: complete the functionality
	
	// Inner class that represents the list nodes
	private class ListNode{
		T payload;
		ListNode next;
		
		private ListNode(){
			this.payload = null;
			this.next = null;
		}
		
		private ListNode(T payload, ListNode next){
			this.payload = payload;
			this.next = next;
		}
	}

}<commit_msg>Iterator interface implemented by the LinkedList class, to be tested<commit_after>/**
 * 
 */
package urllistcompare.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * @author <NAME>
 * @email <EMAIL>
 * 
 * A generic LinkedList that can be used to implement both the lists of URLElement contained within the
 * URLNorm instances and the lists of URLNorm that make up the URLMap hashmap.
 *
 */
public class LinkedList<T> implements Iterator{
	private ListNode head, current;
	private int length;

	public LinkedList() {
		head = null;
		length = 0;
		current = head;
	}
	
	public LinkedList(T payload) {
		head = new ListNode(payload, null);
		length = 1;
		current = head;
	}
	
	/**
	 * Adds a new node to the head of the list.
	 * @param payload
	 */
	public void add(T payload){
		ListNode newNode = new ListNode(payload, head);
		head = newNode;
		length++;
	}
	
	// Returns the ListNode that includes the payload passed as argument, or null.
	private ListNode find(T payload){
		ListNode current = head;
		while(current != null && !current.payload.equals(payload)){
			current = current.next;
		}
		return current;
	}
	
	/**
	 * Checks if a specific payload is in the list
	 * @param payload the element that is being searched for
	 * @return true if found, false if not found
	 */
	public boolean isInList(T payload){
		boolean output = false;
		if(find(payload) != null){
			output = true;
		}
		return output;
	}
	
	/**
	 * Outputs the contents of the list as an ArrayList
	 * @return an ArrayList of the payloads of the list nodes, or null if the list is empty
	 */
	public ArrayList<T> toArrayList(){
		if(head == null) return null; // Faster and safer
		ArrayList<T> output = new ArrayList<T>(length);
		ListNode current = head;
		while(current != null){
			output.add(current.payload);
			current = current.next;
		}
		output.trimToSize();
		return output;
	}
	
	// TODO: complete the functionality
	
	// Inner class that represents the list nodes
	private class ListNode{
		T payload;
		ListNode next;
		
		private ListNode(){
			this.payload = null;
			this.next = null;
		}
		
		private ListNode(T payload, ListNode next){
			this.payload = payload;
			this.next = next;
		}
	}
	
	/**
	 * Resets the current iterator to the list head.
	 */
	public void resetCurrent(){
		current = head;
	}

	@Override
	public boolean hasNext() {
		if(current.next == null) return false;
		else return true;
	}

	@Override
	public Object next() {
		if(!hasNext()) throw new NoSuchElementException();
		else current = current.next;
		return current;
	}

}
{'fraction_non_alphanumeric': 0.10423314188470538, 'fraction_numerical': 0.0008508827908955541, 'mean_word_length': 3.278434940855323, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '918381', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1412, 'n_words': 529}