<commit_before>package transaction;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.HashSet;
import java.util.concurrent.ConcurrentLinkedQueue;

import transaction.Lock.Token.LockType;

import com.rits.cloning.Cloner;

/**
 * An object used to lock a resource
 * @author <NAME>
 *
 * @param <T> The type of the locked resource
 */
public class Lock<T> {
	
	/**
	 * An object returned by a {@link Lock}, used to determine locking ownerships
	 * @author <NAME>
	 *
	 */
	public static class Token {
		
		/**
		 * Type of a lock (READ or WRITE)
		 * @author <NAME>
		 *
		 */
		public enum LockType {
			READ, WRITE
		}
		
		private String id;
		private LockType type;
		
		/**
		 * Create a new lock with
		 * @param type The type of the lock
		 */
		public Token(LockType type) {
			id = new BigInteger(130, new SecureRandom()).toString(32);
			this.type = type;
		}
		
		/**
		 * Get the type of the lock
		 * @return The {@link LockType}
		 */
		public LockType getLockType() {
			return type;
		}
		
		/**
		 * Determine if the input Token is identical to this one
		 * @param other The other token
		 * @return True if equal, false otherwise
		 */
		public boolean equals(Token other) {
			return id.equals(other.getId());
		}
		
		/**
		 * Get the ID of the token
		 * @return The ID
		 */
		protected String getId() {
			return id;
		}
		
		@Override
		public String toString() {
			return id;
		}
	}
	
	private boolean writeMode = false; 
	
	private HashSet<Token> currentLocks = new HashSet<Token>();
	private ConcurrentLinkedQueue<Token> pendingQueue = new ConcurrentLinkedQueue<Token>();
	
	protected T lockedData;
	protected Cloner cloner = new Cloner();
	
	/**
	 * Create a new lock with its stored data
	 * @param data The resource to be made lockable
	 */
	public Lock(T data) {
		lockedData = cloner.deepClone(data);
	}
	
	/**
	 * Get a copy of the stored resource
	 * @return A deep copy of the resource within the lock
	 * @throws LockException 
	 */<commit_msg>Make objects volatile and concurrency safe<commit_after>package transaction;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;

import transaction.Lock.Token.LockType;

import com.rits.cloning.Cloner;

/**
 * An object used to lock a resource
 * @author <NAME>
 *
 * @param <T> The type of the locked resource
 */
public class Lock<T> {
	
	/**
	 * An object returned by a {@link Lock}, used to determine locking ownerships
	 * @author <NAME>
	 *
	 */
	public static class Token {
		
		/**
		 * Type of a lock (READ or WRITE)
		 * @author <NAME>
		 *
		 */
		public enum LockType {
			READ, WRITE
		}
		
		private String id;
		private LockType type;
		
		/**
		 * Create a new lock with
		 * @param type The type of the lock
		 */
		public Token(LockType type) {
			id = new BigInteger(130, new SecureRandom()).toString(32);
			this.type = type;
		}
		
		/**
		 * Get the type of the lock
		 * @return The {@link LockType}
		 */
		public LockType getLockType() {
			return type;
		}
		
		/**
		 * Determine if the input Token is identical to this one
		 * @param other The other token
		 * @return True if equal, false otherwise
		 */
		public boolean equals(Token other) {
			return id.equals(other.getId());
		}
		
		/**
		 * Get the ID of the token
		 * @return The ID
		 */
		protected String getId() {
			return id;
		}
		
		@Override
		public String toString() {
			return id;
		}
	}
	
	private boolean writeMode = false; 
	
	private volatile Set<Token> currentLocks = new HashSet<Token>();
	private volatile ConcurrentLinkedQueue<Token> pendingQueue = new ConcurrentLinkedQueue<Token>();
	
	protected T lockedData;
	protected Cloner cloner = new Cloner();
	
	/**
	 * Create a new lock with its stored data
	 * @param data The resource to be made lockable
	 */
	public Lock(T data) {
		lockedData = cloner.deepClone(data);
	}
	
	/**
	 * Get a copy of the stored resource
	 * @return A deep copy of the resource within the lock
	 * @throws LockException 
	 */
{'fraction_non_alphanumeric': 0.10342316096139839, 'fraction_numerical': 0.0024277737314882253, 'mean_word_length': 2.9539347408829175, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '3276648', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1203, 'n_words': 447}