Search in sources :

Example 1 with TIntLongHashMap

use of gnu.trove.TIntLongHashMap in project intellij-community by JetBrains.

the class PropertiesSeparatorManager method guessSeparator.

//returns most probable separator in properties files
private static String guessSeparator(final ResourceBundleImpl resourceBundle) {
    final TIntLongHashMap charCounts = new TIntLongHashMap();
    for (PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
        if (propertiesFile == null)
            continue;
        List<IProperty> properties = propertiesFile.getProperties();
        for (IProperty property : properties) {
            String key = property.getUnescapedKey();
            if (key == null)
                continue;
            for (int i = 0; i < key.length(); i++) {
                char c = key.charAt(i);
                if (!Character.isLetterOrDigit(c)) {
                    charCounts.put(c, charCounts.get(c) + 1);
                }
            }
        }
    }
    final char[] mostProbableChar = new char[] { '.' };
    charCounts.forEachKey(new TIntProcedure() {

        long count = -1;

        public boolean execute(int ch) {
            long charCount = charCounts.get(ch);
            if (charCount > count) {
                count = charCount;
                mostProbableChar[0] = (char) ch;
            }
            return true;
        }
    });
    if (mostProbableChar[0] == 0) {
        mostProbableChar[0] = '.';
    }
    return Character.toString(mostProbableChar[0]);
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) TIntLongHashMap(gnu.trove.TIntLongHashMap) IProperty(com.intellij.lang.properties.IProperty) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile)

Aggregations

IProperty (com.intellij.lang.properties.IProperty)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 TIntLongHashMap (gnu.trove.TIntLongHashMap)1 TIntProcedure (gnu.trove.TIntProcedure)1