<commit_before>package com.netflix.fenzo.triggers.persistence;

import com.netflix.fenzo.triggers.Trigger;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * In-memory implementation of {@code TriggerDao}
 */
public class InMemoryTriggerDao implements TriggerDao {

    private final ConcurrentMap<String, Map<String,Trigger>> groupedTriggers = new ConcurrentHashMap<String, Map<String,Trigger>>();
    private final ConcurrentMap<String, Trigger> triggers = new ConcurrentHashMap<String, Trigger>();

    @Override
    public void createTrigger(String triggerGroup, Trigger trigger) {
        Map triggerMap = new HashMap();
        triggerMap.put(trigger.getId(), trigger);
        Map existingTriggerMap = groupedTriggers.putIfAbsent(triggerGroup, triggerMap);
        if (existingTriggerMap != null) {
            synchronized (groupedTriggers) {
                groupedTriggers.get(triggerGroup).put(trigger.getId(), trigger);
            }
        }
        triggers.put(trigger.getId(), trigger);
    }

    @Override
    public Trigger getTrigger(String triggerId) {
        return triggers.get(triggerId);
    }

    @Override
    public void updateTrigger(String triggerGroup, Trigger trigger) {
        createTrigger(triggerGroup, trigger);
    }

    @Override
    public void deleteTrigger(String triggerGroup, Trigger trigger) {
        groupedTriggers.get(triggerGroup).remove(trigger.getId());
        triggers.remove(trigger.getId());
    }

    @Override
    public List<Trigger> getTriggers(String triggerGroup) {
        return (List<Trigger>) groupedTriggers.get(triggerGroup).values();
    }

    @Override
    public List<Trigger> getTriggers() {
        return (List<Trigger>) triggers.values();
    }
}<commit_msg>Update InMemoryTriggerDao to not use two concurrentmap's for storing triggers<commit_after>package com.netflix.fenzo.triggers.persistence;

import com.netflix.fenzo.triggers.Trigger;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * In-memory implementation of {@code TriggerDao}
 */
public class InMemoryTriggerDao implements TriggerDao {

    private final ConcurrentMap<String, ConcurrentMap<String,Trigger>> groupedTriggers = new ConcurrentHashMap<String, ConcurrentMap<String,Trigger>>();

    @Override
    public void createTrigger(String triggerGroup, Trigger trigger) {
        ConcurrentMap<String, Trigger> triggerMap = new ConcurrentHashMap<String, Trigger>();
        triggerMap.put(trigger.getId(), trigger);
        Map existingTriggerMap = groupedTriggers.putIfAbsent(triggerGroup, triggerMap);
        if (existingTriggerMap != null) {
            synchronized (groupedTriggers) {
                groupedTriggers.get(triggerGroup).put(trigger.getId(), trigger);
            }
        }
    }

    @Override
    public Trigger getTrigger(String triggerId) {
        for (Iterator<String> iterator1 = groupedTriggers.keySet().iterator(); iterator1.hasNext();) {
            ConcurrentMap<String, Trigger> triggersMap = groupedTriggers.get(iterator1.next());
            for (Iterator<String> iterator2 = triggersMap.keySet().iterator(); iterator2.hasNext();) {
                String storedTriggerId = iterator2.next();
                if (triggerId.equals(storedTriggerId)) {
                    return triggersMap.get(storedTriggerId);
                }
            }
        }
        return null;
    }

    @Override
    public void updateTrigger(String triggerGroup, Trigger trigger) {
        createTrigger(triggerGroup, trigger);
    }

    @Override
    public void deleteTrigger(String triggerGroup, Trigger trigger) {
        groupedTriggers.get(triggerGroup).remove(trigger.getId());
    }

    @Override
    public List<Trigger> getTriggers(String triggerGroup) {
        return new ArrayList<Trigger>(groupedTriggers.get(triggerGroup).values());
    }

    @Override
    public List<Trigger> getTriggers() {
        List<Trigger> triggerList = new ArrayList<Trigger>();
        for (Iterator<String> iterator1 = groupedTriggers.keySet().iterator(); iterator1.hasNext();) {
            ConcurrentMap<String, Trigger> triggersMap = groupedTriggers.get(iterator1.next());
            triggerList.addAll(triggersMap.values());
        }
        return triggerList;
    }
}
{'fraction_non_alphanumeric': 0.10523978685612789, 'fraction_numerical': 0.0019982238010657193, 'mean_word_length': 3.455984174085064, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '381198', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1228, 'n_words': 248}