<commit_before>package com.thinkaurelius.titan.graphdb.transaction;

import cern.colt.list.ObjectArrayList;
import cern.colt.map.OpenLongObjectHashMap;
import com.thinkaurelius.titan.graphdb.vertices.InternalTitanVertex;

import java.util.ArrayList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class StandardVertexCache extends OpenLongObjectHashMap implements VertexCache {
	
	private static final long serialVersionUID = 1609323162410880217L;
	private static final int defaultCacheSize = 10;
	
	ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
	Lock readLock = rwl.readLock();
	Lock writeLock = rwl.writeLock();
	
	public StandardVertexCache() {
		super(defaultCacheSize);
	}

	
	@Override
	public boolean contains(long id) {
		readLock.lock();
		boolean contains = super.containsKey(id);
		readLock.unlock();
		return contains;
	}
	
	@Override
	public InternalTitanVertex get(long id) {
		readLock.lock();
		InternalTitanVertex node = (InternalTitanVertex)super.get(Long.valueOf(id));
		readLock.unlock();
		return node;
	}
	
	@Override
	public void add(InternalTitanVertex vertex, long id) {
		writeLock.lock();
		assert !containsKey(Long.valueOf(id));
		put(id, vertex);
		writeLock.unlock();
	}

    @Override
    public Iterable<InternalTitanVertex> getAll() {
        ArrayList<InternalTitanVertex> vertices = new ArrayList<InternalTitanVertex>(super.size()+2);
        readLock.lock();
        ObjectArrayList all = super.values();
        for (int i=0;i<all.size();i++) vertices.add((InternalTitanVertex)all.get(i));
        readLock.unlock();
        return vertices;
    }
    
    @Override
    public boolean remove(long vertexid) {
        writeLock.lock();
        boolean removed = super.removeKey(vertexid);
        writeLock.unlock();
        return removed;
    }


    @Override
	public synchronized void close() {
		clear();
	}


	
}
<commit_msg>Moved unlocking into finally block to avoid potential deadlocks on failure<commit_after>package com.thinkaurelius.titan.graphdb.transaction;

import cern.colt.list.ObjectArrayList;
import cern.colt.map.OpenLongObjectHashMap;
import com.thinkaurelius.titan.graphdb.vertices.InternalTitanVertex;

import java.util.ArrayList;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class StandardVertexCache extends OpenLongObjectHashMap implements VertexCache {
	
	private static final long serialVersionUID = 1609323162410880217L;
	private static final int defaultCacheSize = 10;
	
	ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
	Lock readLock = rwl.readLock();
	Lock writeLock = rwl.writeLock();
	
	public StandardVertexCache() {
		super(defaultCacheSize);
	}

	
	@Override
	public boolean contains(long id) {
		readLock.lock();
        try {
    		return super.containsKey(id);
        } finally {
		    readLock.unlock();
        }
	}
	
	@Override
	public InternalTitanVertex get(long id) {
		readLock.lock();
        try {
		    return (InternalTitanVertex)super.get(Long.valueOf(id));
        } finally {
		    readLock.unlock();
        }
	}
	
	@Override
	public void add(InternalTitanVertex vertex, long id) {
		writeLock.lock();
        try {
            assert !containsKey(Long.valueOf(id));
            put(id, vertex);
        } finally {
		    writeLock.unlock();
        }
	}

    @Override
    public Iterable<InternalTitanVertex> getAll() {
        ArrayList<InternalTitanVertex> vertices = new ArrayList<InternalTitanVertex>(super.size()+2);
        readLock.lock();
        try {
            ObjectArrayList all = super.values();
            for (int i=0;i<all.size();i++) vertices.add((InternalTitanVertex)all.get(i));
        } finally {
            readLock.unlock();
        }
        return vertices;
    }
    
    @Override
    public boolean remove(long vertexid) {
        writeLock.lock();
        try {
            return super.removeKey(vertexid);
        } finally {
            writeLock.unlock();
        }
    }


    @Override
	public synchronized void close() {
		clear();
	}


	
}

{'fraction_non_alphanumeric': 0.10533980582524272, 'fraction_numerical': 0.01116504854368932, 'mean_word_length': 3.351636747624076, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '3024398', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1219, 'n_words': 251}