<commit_before>package com.gofish.sentiment.storage;

import io.vertx.core.*;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

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

/**
 * @author <NAME>
 */
public class StorageServiceImpl implements StorageService {

    private static final Logger LOG = LoggerFactory.getLogger(StorageServiceImpl.class);

    private final Vertx vertx;
    private final EventBus eventBus;
    private final String workerAddress;
    private final DeploymentOptions workerOptions;

    private final Map<String, DeliveryOptions> deliveryOptions = new HashMap<>(6);

    public StorageServiceImpl(Vertx vertx, JsonObject config) {
        this.vertx = vertx;
        this.eventBus = vertx.eventBus();
        this.workerAddress = StorageWorker.ADDRESS;
        this.workerOptions = new DeploymentOptions().setConfig(config).setWorker(true);

        initDeliveryOptionsMap();
    }

    @Override
    public void createCollection(String collectionName, Handler<AsyncResult<Void>> resultHandler) {
        JsonObject message = new JsonObject().put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("createCollection"), handleReply(resultHandler, Void.class));
    }

    @Override
    public void createIndex(String collectionName, JsonObject collectionIndex, Handler<AsyncResult<Void>> resultHandler) {
        JsonObject message = new JsonObject()
                .put("collectionName", collectionName)
                .put("indexName", collectionName + "Index")
                .put("collectionIndex", collectionIndex);

        getResult(message, deliveryOptions.get("createIndex"), handleReply(resultHandler, Void.class));
    }

    @Override
    public void getCollections(Handler<AsyncResult<JsonArray>> resultHandler) {
        getResult(new JsonObject(), deliveryOptions.get("getCollections"), handleReply(resultHandler, JsonArray.class));
    }

    @Override
    public void getSentimentResults(String collectionName, Handler<AsyncResult<JsonObject>> resultHandler) {
        JsonObject message = new JsonObject().put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("getSentimentResults"), handleReply(resultHandler, JsonObject.class));
    }

    @Override
    public void hasCollection(String collectionName, Handler<AsyncResult<Boolean>> resultHandler) {
        JsonObject message = new JsonObject().put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("hasCollection"), handleReply(resultHandler, Boolean.class));
    }

    @Override
    public void saveArticles(String collectionName, JsonArray articles, Handler<AsyncResult<JsonObject>> resultHandler) {
        JsonObject message = new JsonObject()
                .put("collectionName", collectionName)
                .put("articles", articles);

        getResult(message, deliveryOptions.get("saveArticles"), handleReply(resultHandler, JsonObject.class));
    }

    @Override
    public void isIndexPresent(String indexName, String collectionName, Handler<AsyncResult<Boolean>> resultHandler) {
        JsonObject message = new JsonObject()
                .put("indexName", indexName)
                .put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("isIndexPresent"), handleReply(resultHandler, Boolean.class));
    }

    private void getResult(JsonObject message, DeliveryOptions deliveryOptions, Handler<AsyncResult<Message<Object>>> replyHandler) {
        String workerVerticle = "com.gofish.sentiment.storage.StorageWorker";
        vertx.deployVerticle(workerVerticle, workerOptions, completionHandler -> {<commit_msg>Removed string dependency on verticle name from getResult() method. Now calls getName() method on class instead.<commit_after>package com.gofish.sentiment.storage;

import io.vertx.core.*;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;

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

/**
 * @author <NAME>
 */
public class StorageServiceImpl implements StorageService {

    private static final Logger LOG = LoggerFactory.getLogger(StorageServiceImpl.class);

    private final Vertx vertx;
    private final EventBus eventBus;
    private final String workerAddress;
    private final DeploymentOptions workerOptions;

    private final Map<String, DeliveryOptions> deliveryOptions = new HashMap<>(6);

    public StorageServiceImpl(Vertx vertx, JsonObject config) {
        this.vertx = vertx;
        this.eventBus = vertx.eventBus();
        this.workerAddress = StorageWorker.ADDRESS;
        this.workerOptions = new DeploymentOptions().setConfig(config).setWorker(true);

        initDeliveryOptionsMap();
    }

    @Override
    public void createCollection(String collectionName, Handler<AsyncResult<Void>> resultHandler) {
        JsonObject message = new JsonObject().put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("createCollection"), handleReply(resultHandler, Void.class));
    }

    @Override
    public void createIndex(String collectionName, JsonObject collectionIndex, Handler<AsyncResult<Void>> resultHandler) {
        JsonObject message = new JsonObject()
                .put("collectionName", collectionName)
                .put("indexName", collectionName + "Index")
                .put("collectionIndex", collectionIndex);

        getResult(message, deliveryOptions.get("createIndex"), handleReply(resultHandler, Void.class));
    }

    @Override
    public void getCollections(Handler<AsyncResult<JsonArray>> resultHandler) {
        getResult(new JsonObject(), deliveryOptions.get("getCollections"), handleReply(resultHandler, JsonArray.class));
    }

    @Override
    public void getSentimentResults(String collectionName, Handler<AsyncResult<JsonObject>> resultHandler) {
        JsonObject message = new JsonObject().put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("getSentimentResults"), handleReply(resultHandler, JsonObject.class));
    }

    @Override
    public void hasCollection(String collectionName, Handler<AsyncResult<Boolean>> resultHandler) {
        JsonObject message = new JsonObject().put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("hasCollection"), handleReply(resultHandler, Boolean.class));
    }

    @Override
    public void saveArticles(String collectionName, JsonArray articles, Handler<AsyncResult<JsonObject>> resultHandler) {
        JsonObject message = new JsonObject()
                .put("collectionName", collectionName)
                .put("articles", articles);

        getResult(message, deliveryOptions.get("saveArticles"), handleReply(resultHandler, JsonObject.class));
    }

    @Override
    public void isIndexPresent(String indexName, String collectionName, Handler<AsyncResult<Boolean>> resultHandler) {
        JsonObject message = new JsonObject()
                .put("indexName", indexName)
                .put("collectionName", collectionName);

        getResult(message, deliveryOptions.get("isIndexPresent"), handleReply(resultHandler, Boolean.class));
    }

    private void getResult(JsonObject message, DeliveryOptions deliveryOptions, Handler<AsyncResult<Message<Object>>> replyHandler) {
        vertx.deployVerticle(StorageWorker.class.getName(), workerOptions, completionHandler -> {
{'fraction_non_alphanumeric': 0.10191082802547771, 'fraction_numerical': 0.00025477707006369424, 'mean_word_length': 4.269127516778523, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, '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': '6543360', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1941, 'n_words': 434}