<commit_before>/*
 * Copyright (C) 2003, 2004  <NAME>, Essiembre Consultant Inc.
 * 
 * This file is part of Essiembre ResourceBundle Editor.
 * 
 * Essiembre ResourceBundle Editor is free software; you can redistribute it 
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * Essiembre ResourceBundle Editor is distributed in the hope that it will be 
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with Essiembre ResourceBundle Editor; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA  02111-1307  USA
 */
package com.essiembre.eclipse.i18n.resourcebundle.editors;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.eclipse.swt.widgets.Text;

/**
 * Grouping of all related resource bundles.
 * @author <NAME>
 * @version $Author$ $Revision$ $Date$
 */
public class Bundles {

    /** All bundles in this group. */
    private List bundles = new ArrayList();
    
    /**
     * Constructor.
     */
    public Bundles() {
        super();
    }

    /**
     * Gets the bundle at specified index.
     * @parm index position assigned to bundle
     * @return Returns the bundle.
     */
    public Bundle getBundle(int index) {
        return (Bundle) bundles.get(index);
    }

    /**
     * Gets the bundle associated to given text box.
     * @parm textBox a <code>Text</code> widget
     * @return Returns the bundle.
     */
    public Bundle getBundle(Text textBox) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            if (bundle.getTextBox().equals(textBox)) {
                return bundle;
            }
        }
        return null;
    }

    /**
     * Gets the bundle index.
     * @parm bundle The bundle to get its index.
     * @return Returns the index
     */
    public int getBundleIndex(Bundle bundle) {
        return bundles.indexOf(bundle);
    }
    
    /**
     * Add a bundle at given index.
     * @parm index position assigned to bundle
     * @param bundle The bundle to add.
     */
    public void addBundle(int index, Bundle bundle) {
        this.bundles.add(index, bundle);
    }

    /**
     * Adds a bundle after last existing bundle.
     * @param bundle The bundle to add.
     */
    public void addBundle(Bundle bundle) {
        this.bundles.add(bundle);
    }
    
    /**
     * Refreshes text boxes contained in all bundles with value found
     * under the given resource bundle key.
     * @param key resource bundle key to get value from.
     */
    public void refreshTextBoxes(String key) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            ((Bundle) iter.next()).refreshTextBox(key);
        }
    }

    /**
     * Refreshes all bundle data based on editors content.
     */
    public void refreshData() {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            ((Bundle) iter.next()).refreshData();
        }
    }

    
    /**
     * Gets all resource bundle keys.
     * @return <code>List</code> of resource bundle keys.
     */
    public List getKeys() {
        Set keys = new TreeSet();
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            keys.addAll(((Bundle) iter.next()).getKeys());
        }
        return Collections.unmodifiableList(new ArrayList(keys));
    }

    /**
     * Add a resource bundle key.  If a bundle already has the supplied
     * key, it is left unchanged.
     * @param key resource bundle key
     */
    public void addKey(String key) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            Map data = bundle.getData();
            if (!data.containsKey(key)) {
                data.put(key, null);
                bundle.refreshEditor();
            }
        }
    }

    /**
     * Removes a resource bundle key from all bundles.
     * @param key resource bundle key
     */
    public void removeKey(String key) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            bundle.getData().remove(key);
            bundle.refreshEditor();
        }
    }

    /**
     * Modifies a resource bundle key in all bundles.
     * @param oldKey resource bundle key to modify
     * @param newKey replacement key for resource bundle key to modify
     */
    public void modifyKey(String oldKey, String newKey) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            String value = (String) bundle.getData().get(oldKey);
            bundle.getData().remove(oldKey);
            bundle.getData().put(newKey, value);
            bundle.refreshEditor();
        }
    }

    
    /**
     * Gets the number of bundles in this bundle group.
     * @return The number of bundles in this bundle group.
     */
    public int count() {
        return bundles.size();
    }
}<commit_msg>Added isValueMissing.<commit_after>/*
 * Copyright (C) 2003, 2004  <NAME>, Essiembre Consultant Inc.
 * 
 * This file is part of Essiembre ResourceBundle Editor.
 * 
 * Essiembre ResourceBundle Editor is free software; you can redistribute it 
 * and/or modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * Essiembre ResourceBundle Editor is distributed in the hope that it will be 
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with Essiembre ResourceBundle Editor; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA  02111-1307  USA
 */
package com.essiembre.eclipse.i18n.resourcebundle.editors;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.eclipse.swt.widgets.Text;

/**
 * Grouping of all related resource bundles.
 * @author <NAME>
 * @version $Author$ $Revision$ $Date$
 */
public class Bundles {

    /** All bundles in this group. */
    private List bundles = new ArrayList();
    
    /**
     * Constructor.
     */
    public Bundles() {
        super();
    }

    /**
     * Gets the bundle at specified index.
     * @parm index position assigned to bundle
     * @return Returns the bundle.
     */
    public Bundle getBundle(int index) {
        return (Bundle) bundles.get(index);
    }

    /**
     * Gets the bundle associated to given text box.
     * @parm textBox a <code>Text</code> widget
     * @return Returns the bundle.
     */
    public Bundle getBundle(Text textBox) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            if (bundle.getTextBox().equals(textBox)) {
                return bundle;
            }
        }
        return null;
    }

    /**
     * Gets the bundle index.
     * @parm bundle The bundle to get its index.
     * @return Returns the index
     */
    public int getBundleIndex(Bundle bundle) {
        return bundles.indexOf(bundle);
    }
    
    /**
     * Add a bundle at given index.
     * @parm index position assigned to bundle
     * @param bundle The bundle to add.
     */
    public void addBundle(int index, Bundle bundle) {
        this.bundles.add(index, bundle);
    }

    /**
     * Adds a bundle after last existing bundle.
     * @param bundle The bundle to add.
     */
    public void addBundle(Bundle bundle) {
        this.bundles.add(bundle);
    }
    
    /**
     * Refreshes text boxes contained in all bundles with value found
     * under the given resource bundle key.
     * @param key resource bundle key to get value from.
     */
    public void refreshTextBoxes(String key) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            ((Bundle) iter.next()).refreshTextBox(key);
        }
    }

    /**
     * Refreshes all bundle data based on editors content.
     */
    public void refreshData() {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            ((Bundle) iter.next()).refreshData();
        }
    }

    
    /**
     * Gets all resource bundle keys.
     * @return <code>List</code> of resource bundle keys.
     */
    public List getKeys() {
        Set keys = new TreeSet();
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            keys.addAll(((Bundle) iter.next()).getKeys());
        }
        return Collections.unmodifiableList(new ArrayList(keys));
    }

    /**
     * Add a resource bundle key.  If a bundle already has the supplied
     * key, it is left unchanged.
     * @param key resource bundle key
     */
    public void addKey(String key) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            Map data = bundle.getData();
            if (!data.containsKey(key)) {
                data.put(key, null);
                bundle.refreshEditor();
            }
        }
    }

    /**
     * Removes a resource bundle key from all bundles.
     * @param key resource bundle key
     */
    public void removeKey(String key) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            bundle.getData().remove(key);
            bundle.refreshEditor();
        }
    }

    /**
     * Modifies a resource bundle key in all bundles.
     * @param oldKey resource bundle key to modify
     * @param newKey replacement key for resource bundle key to modify
     */
    public void modifyKey(String oldKey, String newKey) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            String value = (String) bundle.getData().get(oldKey);
            bundle.getData().remove(oldKey);
            bundle.getData().put(newKey, value);
            bundle.refreshEditor();
        }
    }

    
    /**
     * Gets the number of bundles in this bundle group.
     * @return The number of bundles in this bundle group.
     */
    public int count() {
        return bundles.size();
    }
    
    /**
     * Is there one or more values missing for the given key.
     * @param key the key to check for missing values
     * @return <code>true</code> if missing
     */
    public boolean isValueMissing(String key) {
        for (Iterator iter = bundles.iterator(); iter.hasNext();) {
            Bundle bundle = (Bundle) iter.next();
            String value = (String) bundle.getData().get(key);
            if (value == null || value.trim().length() == 0) {
                return true;
            }
        }
        return false;
    }
}
{'fraction_non_alphanumeric': 0.10600858369098712, 'fraction_numerical': 0.004549356223175966, 'mean_word_length': 2.1938048245614037, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6541294', 'n_tokens_mistral': 3219, 'n_tokens_neox': 3094, 'n_words': 1115}