<commit_before>package de.fernunihagen.dna.jkn.scalephant.storage;

import java.util.HashMap;
import java.util.Map;

public class StorageInterface {

	/**
	 * A map with all created storage instances
	 */
	protected static final Map<String, StorageManager> instances;
	
	/**
	 * The used storage configuration
	 */
	protected static StorageConfiguration storageConfiguration;
	
	static {
		storageConfiguration = new StorageConfiguration();
		instances = new HashMap<String, StorageManager>();
	}
	
	/**
	 * Get the storage manager for a given table. If the storage manager does not 
	 * exist, it will be created
	 * 
	 * @return
	 */
	public static synchronized StorageManager getStorageManager(final String table) {

		if(instances.containsKey(table)) {
			return instances.get(table);
		}
		
		final StorageManager storageManager = new StorageManager(table, storageConfiguration);
		storageManager.init();
		
		instances.put(table, storageManager);
		
		return storageManager;
	}
	
	/**
	 * Shut down the storage manager for a given relation
	 * @param table
	 * @return
	 */
	public static synchronized boolean shutdown(final String table) {
		if(! instances.containsKey(table)) {
			return false;
		}
		
		final StorageManager storageManager = instances.remove(table);
		storageManager.shutdown();
		
		return true;
	}
	
	/**
	 * Is a storage manager for the relation active?
	 * @param table
	 * @return
	 */
	public static synchronized boolean isStorageManagerActive(final String table) {
		return instances.containsKey(table);
	}
	
	/**
	 * Shutdown all instances
	 * 
	 */
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		
		if(instances != null) {
			for(final String table : instances.keySet()) {
				final StorageManager storageManager = instances.get(table);
				storageManager.shutdown();<commit_msg>Added list all tables method<commit_after>package de.fernunihagen.dna.jkn.scalephant.storage;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StorageInterface {

	/**
	 * A map with all created storage instances
	 */
	protected static final Map<String, StorageManager> instances;
	
	/**
	 * The used storage configuration
	 */
	protected static StorageConfiguration storageConfiguration;
	
	static {
		storageConfiguration = new StorageConfiguration();
		instances = new HashMap<String, StorageManager>();
	}
	
	/**
	 * Get the storage manager for a given table. If the storage manager does not 
	 * exist, it will be created
	 * 
	 * @return
	 */
	public static synchronized StorageManager getStorageManager(final String table) {

		if(instances.containsKey(table)) {
			return instances.get(table);
		}
		
		final StorageManager storageManager = new StorageManager(table, storageConfiguration);
		storageManager.init();
		
		instances.put(table, storageManager);
		
		return storageManager;
	}
	
	/**
	 * Shut down the storage manager for a given relation
	 * @param table
	 * @return
	 */
	public static synchronized boolean shutdown(final String table) {
		if(! instances.containsKey(table)) {
			return false;
		}
		
		final StorageManager storageManager = instances.remove(table);
		storageManager.shutdown();
		
		return true;
	}
	
	/**
	 * Is a storage manager for the relation active?
	 * @param table
	 * @return
	 */
	public static synchronized boolean isStorageManagerActive(final String table) {
		return instances.containsKey(table);
	}
	
	/**
	 * Returns a list with all known tables
	 * 
	 * @return
	 */
	public static List<String> getAllTables() {
		final List<String> allTables = new ArrayList<String>();
		
		final File folder = new File(storageConfiguration.getDataDir());
		
		for (final File fileEntry : folder.listFiles()) {
	        if (fileEntry.isDirectory()) {
	           allTables.add(fileEntry.getName());
	        } 
	    }
		
		return allTables;
	}
	
	/**
	 * Shutdown all instances
	 * 
	 */
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		
		if(instances != null) {
			for(final String table : instances.keySet()) {
				final StorageManager storageManager = instances.get(table);
				storageManager.shutdown();
{'fraction_non_alphanumeric': 0.09838403041825095, 'fraction_numerical': 0.0, 'mean_word_length': 3.734533183352081, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '6101598', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1095, 'n_words': 341}