<commit_before>package org.settings;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * @author <NAME>
 */
public final class Group extends Element {
    
    /* Holds all sun groups */
    private final Map<String,Group> subGroups = new LinkedHashMap<>();
    
    /* Holds all keys/values */
    private final Map<String,Object> keys     = new LinkedHashMap<>();
    
    /* Reference to the main data container */
    private Buffer buffer;
    
    /* Reference to the group changer */
    private GroupChanger groupChanger;
    
    
    /**
     * 
     * @param parent
     * @param tok 
     */
    Group(final String parent, final Buffer buffer, final GroupChanger groupChanger, final Tokener tok) {
        this.parent = parent;
        this.buffer = buffer;
        this.groupChanger = groupChanger;
        parse(tok);
    }
    
    /**
     * 
     * @param parent
     * @param name 
     */
    public Group(final String parent, final String name) {
        this.parent = parent;
        this.name   = name;
        this.path   = parent + name + (parent.isEmpty()?"":"/");
    }
    
    /**
     * 
     * @param buffer 
     */
    void setBuffer(final Buffer buffer) {
        this.buffer = buffer;
    }
    
    /**
     * 
     * @return 
     */
    public Collection<Group> childGroups() {
        return Collections.unmodifiableCollection(this.subGroups.values());
    }
    
    /**
     * 
     * @return 
     */
    public Collection<String> childKeys() {
        return Collections.unmodifiableCollection(this.keys.keySet());
    }
    
    /**
     * 
     * @param key
     * @return 
     */
    public boolean hasKey(final String key) {
        return this.keys.containsKey(key);
    }
    
    /**
     * 
     * @param <T>
     * @param key
     * @param value 
     */
    public final <T extends Number> void addKey(final String key, final T value) {
        addObjKey(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    public final void addKey(final String key, final String value) {
        addObjKey(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    public final void addKey(final String key, final boolean value) {
        addObjKey(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    void addObjKey(final String key, final Object value) {
        this.keys.putIfAbsent(key, value);
    }
    
    /**
     * 
     * @param key 
     */
    public void deleteKey(final String key) {
        this.keys.remove(key);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    public void changeValue(final String key, final String value) {
        changeObjValue(key, value);
    }
    
    /**
     * 
     * @param <T>
     * @param key
     * @param value 
     */
    public <T extends Number> void changeValue(final String key, final T value) {
        changeObjValue(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    private void changeObjValue(final String key, final Object value) {
        this.keys.put(key, value);
    }
    
    /**
     * 
     * @param relGroupPath
     * @return 
     */
    public Group getGroup(final String relGroupPath) {
        return this.groupChanger.changeGroup(relGroupPath);
    }
    
    /**
     * 
     * @param group 
     */
    public void addSubGroup(final Group group) {
        this.subGroups.putIfAbsent(group.getPath(), group);
        this.buffer.addGroup(group);
    }
    
    /**
     * 
     * @param name 
     */
    public void addSubGroup(final String name) {
        addSubGroup(new Group(this.path, name));
    }
    
    /**
     * 
     * @param groupName 
     */
    public void deleteSubGroup(final String groupName) {
        final String absolutePath = this.path + groupName + "/";
        this.subGroups.remove(absolutePath);
    }
    <commit_msg>MM: check for subgroup presence when deleting subgroup<commit_after>package org.settings;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 * @author <NAME>
 */
public final class Group extends Element {
    
    /* Holds all sun groups */
    private final Map<String,Group> subGroups = new LinkedHashMap<>();
    
    /* Holds all keys/values */
    private final Map<String,Object> keys     = new LinkedHashMap<>();
    
    /* Reference to the main data container */
    private Buffer buffer;
    
    /* Reference to the group changer */
    private GroupChanger groupChanger;
    
    
    /**
     * 
     * @param parent
     * @param tok 
     */
    Group(final String parent, final Buffer buffer, final GroupChanger groupChanger, final Tokener tok) {
        this.parent = parent;
        this.buffer = buffer;
        this.groupChanger = groupChanger;
        parse(tok);
    }
    
    /**
     * 
     * @param parent
     * @param name 
     */
    public Group(final String parent, final String name) {
        this.parent = parent;
        this.name   = name;
        this.path   = parent + name + (parent.isEmpty()?"":"/");
    }
    
    /**
     * 
     * @param buffer 
     */
    void setBuffer(final Buffer buffer) {
        this.buffer = buffer;
    }
    
    /**
     * 
     * @return 
     */
    public Collection<Group> childGroups() {
        return Collections.unmodifiableCollection(this.subGroups.values());
    }
    
    /**
     * 
     * @return 
     */
    public Collection<String> childKeys() {
        return Collections.unmodifiableCollection(this.keys.keySet());
    }
    
    /**
     * 
     * @param key
     * @return 
     */
    public boolean hasKey(final String key) {
        return this.keys.containsKey(key);
    }
    
    /**
     * 
     * @param <T>
     * @param key
     * @param value 
     */
    public final <T extends Number> void addKey(final String key, final T value) {
        addObjKey(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    public final void addKey(final String key, final String value) {
        addObjKey(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    public final void addKey(final String key, final boolean value) {
        addObjKey(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    void addObjKey(final String key, final Object value) {
        this.keys.putIfAbsent(key, value);
    }
    
    /**
     * 
     * @param key 
     */
    public void deleteKey(final String key) {
        this.keys.remove(key);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    public void changeValue(final String key, final String value) {
        changeObjValue(key, value);
    }
    
    /**
     * 
     * @param <T>
     * @param key
     * @param value 
     */
    public <T extends Number> void changeValue(final String key, final T value) {
        changeObjValue(key, value);
    }
    
    /**
     * 
     * @param key
     * @param value 
     */
    private void changeObjValue(final String key, final Object value) {
        this.keys.put(key, value);
    }
    
    /**
     * 
     * @param relGroupPath
     * @return 
     */
    public Group getGroup(final String relGroupPath) {
        return this.groupChanger.changeGroup(relGroupPath);
    }
    
    /**
     * 
     * @param group 
     */
    public void addSubGroup(final Group group) {
        this.subGroups.putIfAbsent(group.getPath(), group);
        this.buffer.addGroup(group);
    }
    
    /**
     * 
     * @param name 
     */
    public void addSubGroup(final String name) {
        addSubGroup(new Group(this.path, name));
    }
    
    /**
     * 
     * @param groupName 
     */
    public void deleteSubGroup(final String groupName) {
        final String absolutePath = this.path + groupName + "/";
        if (this.subGroups.containsKey(absolutePath) == false) {
            throw new GcfException("no such group to delete: \"" + getPath() + groupName + "/\"");
        }
        
        this.subGroups.remove(absolutePath);
    }
    
{'fraction_non_alphanumeric': 0.1161579457364341, 'fraction_numerical': 0.0, 'mean_word_length': 1.7286847323198942, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 25, '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': '6690368', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2444, 'n_words': 593}