<commit_before>package org.jvalue.ceps.data;

import java.util.LinkedList;
import java.util.List;

import org.jvalue.ceps.db.DbAccessor;
import org.jvalue.ceps.db.DbAccessorFactory;
import org.jvalue.ceps.utils.Assert;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;


final class DataSourceDb {

	private static final String DB_NAME = "odsSources";

	private static DataSourceDb instance;

	public static DataSourceDb getInstance() {
		if (instance == null) instance = new DataSourceDb();
		return instance;
	}


	private final ObjectMapper mapper = new ObjectMapper();
	private final DbAccessor dbAccessor;

	private DataSourceDb() {
		this.dbAccessor = DbAccessorFactory.getCouchDbAccessor(DB_NAME);
	}


	public void add(DataSource source) {
		Assert.assertNotNull(source);
		dbAccessor.insert(mapper.valueToTree(source));
	}


	public void remove(DataSource source) {
		Assert.assertNotNull(source);
		dbAccessor.delete(mapper.valueToTree(source));
	}


	public List<DataSource> getAll() {
		List<JsonNode> jsonObjects = dbAccessor.getAll();
		List<DataSource> sources = new LinkedList<DataSource>();
		for (JsonNode json : jsonObjects) {
			try {
				sources.add(mapper.treeToValue(json, DataSource.class));
			} catch (JsonProcessingException jpe) {
				throw new IllegalStateException(jpe);<commit_msg>data: DataSourceDb uses injection for DbAccessor<commit_after>package org.jvalue.ceps.data;

import java.util.LinkedList;
import java.util.List;

import org.jvalue.ceps.db.DbAccessor;
import org.jvalue.ceps.db.DbAccessorFactory;
import org.jvalue.ceps.utils.Assert;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;


final class DataSourceDb {

	private static final String DB_NAME = "odsSources";

	private static DataSourceDb instance;

	public static DataSourceDb getInstance() {
		if (instance == null) instance = new DataSourceDb(
				DbAccessorFactory.getCouchDbAccessor(DB_NAME));
		return instance;
	}


	private final ObjectMapper mapper = new ObjectMapper();
	private final DbAccessor dbAccessor;

	private DataSourceDb(DbAccessor dbAccessor) {
		Assert.assertNotNull(dbAccessor);
		this.dbAccessor = dbAccessor;
	}


	public void add(DataSource source) {
		Assert.assertNotNull(source);
		dbAccessor.insert(mapper.valueToTree(source));
	}


	public void remove(DataSource source) {
		Assert.assertNotNull(source);
		dbAccessor.delete(mapper.valueToTree(source));
	}


	public List<DataSource> getAll() {
		List<JsonNode> jsonObjects = dbAccessor.getAll();
		List<DataSource> sources = new LinkedList<DataSource>();
		for (JsonNode json : jsonObjects) {
			try {
				sources.add(mapper.treeToValue(json, DataSource.class));
			} catch (JsonProcessingException jpe) {
				throw new IllegalStateException(jpe);
{'fraction_non_alphanumeric': 0.10199932226363945, 'fraction_numerical': 0.0, 'mean_word_length': 5.473684210526316, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '367697', 'n_tokens_mistral': 968, 'n_tokens_neox': 867, 'n_words': 191}