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]);
}
Aggregations