use of com.google.common.base.Splitter in project BuildCraft by BuildCraft.
the class IMCHandlerTransport method processBlacklistFacadeIMC.
// TODO: Merge with AddFacadeIMC
public static void processBlacklistFacadeIMC(IMCEvent event, IMCMessage m) {
try {
if (m.isStringMessage()) {
Splitter splitter = Splitter.on("@").trimResults();
String[] array = Iterables.toArray(splitter.split(m.getStringValue()), String.class);
if (array.length <= 0 || array.length >= 3) {
BCLog.logger.info(String.format("Received an invalid blacklist-facade request %s from mod %s", m.getStringValue(), m.getSender()));
} else {
String blockName = array[0];
Integer metaId = array.length == 1 ? -1 : Ints.tryParse(array[1]);
if (Strings.isNullOrEmpty(blockName) || metaId == null) {
BCLog.logger.info(String.format("Received an invalid blacklist-facade request %s from mod %s", m.getStringValue(), m.getSender()));
} else {
Block block = Block.blockRegistry.getObject(new ResourceLocation(blockName));
if (metaId < 0) {
ItemFacade.blacklistFacade(block);
} else {
ItemFacade.blacklistFacade(block.getStateFromMeta(metaId));
}
}
}
} else if (m.isItemStackMessage()) {
ItemStack modItemStack = m.getItemStackValue();
Block block = Block.getBlockFromItem(modItemStack.getItem());
if (block != null) {
if (modItemStack.getItemDamage() < 0) {
ItemFacade.blacklistFacade(block);
} else {
ItemFacade.blacklistFacade(block.getStateFromMeta(modItemStack.getItemDamage()));
}
}
}
} catch (Throwable e) {
}
}
use of com.google.common.base.Splitter in project cdap by caskdata.
the class MapReduceContainerHelper method addMapReduceClassPath.
/**
* Adds the classpath to be used in MapReduce job execution based on the given {@link Configuration}.
*
* @param hConf the configuration for the job.
* @param result a list for appending MR framework classpath
* @return the same {@code result} list from the argument
*/
public static <T extends Collection<String>> T addMapReduceClassPath(Configuration hConf, T result) {
String framework = hConf.get(MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH);
// For classpath config get from the hConf, we splits it with both "," and ":" because one can set
// the conf with something like "path1,path2:path3" and
// it should become "path1:path2:path3" in the target JVM process
Splitter splitter = Splitter.on(Pattern.compile(",|" + File.pathSeparatorChar)).trimResults().omitEmptyStrings();
// Otherwise, only use the mapreduce.application.classpath
if (framework == null) {
Iterable<String> yarnAppClassPath = Arrays.asList(hConf.getTrimmedStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH, YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
Iterables.addAll(result, yarnAppClassPath);
}
// Add MR application classpath
Iterables.addAll(result, splitter.split(hConf.get(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH, MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH)));
return result;
}
use of com.google.common.base.Splitter in project zemberek-nlp by ahmetaa.
the class AmbiguityStats method ambiguousWordStats.
public void ambiguousWordStats(String filename) throws IOException {
List<String> lines = readAll(filename);
Histogram<String> uniques = new Histogram<>(1000000);
int total = 0;
Splitter splitter = Splitter.on(" ").omitEmptyStrings().trimResults();
for (String line : lines) {
for (String s : splitter.split(line)) {
List<WordAnalysis> results = parser.getWordAnalyzer().analyze(TurkishAlphabet.INSTANCE.normalize(s));
total++;
if (total % 50000 == 0) {
System.out.println("Processed: " + total);
}
if (results.size() > 1) {
uniques.add(s);
}
}
}
System.out.println("Total: " + total);
Stats st = new Stats(0.002);
st.allCounts = (int) uniques.totalCount();
st.allUniques = uniques.size();
for (String s : uniques.getSortedList()) {
int count = uniques.getCount(s);
if (st.overCutoff(count)) {
String p1 = percentStr3(count, st.allCounts);
st.significantCounts += count;
st.significantUniques++;
System.out.println(s + " : " + count + " " + pp(p1));
}
}
st.dump();
}
use of com.google.common.base.Splitter in project zemberek-nlp by ahmetaa.
the class AmbiguityStats method noParse.
public void noParse(String... filename) throws IOException {
Histogram<String> uniques = new Histogram<>(1000000);
int total = 0;
for (String file : filename) {
List<String> lines = readAll(file);
Splitter splitter = Splitter.on(" ").omitEmptyStrings().trimResults();
for (String line : lines) {
for (String s : splitter.split(line)) {
List<WordAnalysis> results = parser.getWordAnalyzer().analyze(TurkishAlphabet.INSTANCE.normalize(s));
total++;
if (total % 50000 == 0) {
System.out.println("Processed: " + total);
}
if (results.size() == 0) {
uniques.add(s);
}
}
}
System.out.println("Total: " + total);
}
Stats st = new Stats(0.0002);
st.allCounts = (int) uniques.totalCount();
st.allUniques = uniques.size();
for (String s : uniques.getSortedList()) {
int count = uniques.getCount(s);
if (count > 5) {
st.significantCounts += count;
st.significantUniques++;
System.out.println(s + " : " + count);
}
}
st.dump();
}
use of com.google.common.base.Splitter in project netvirt by opendaylight.
the class ElanBridgeManager method getMultiValueMap.
@Override
public Map<String, String> getMultiValueMap(String multiKeyValueStr) {
if (Strings.isNullOrEmpty(multiKeyValueStr)) {
return Collections.emptyMap();
}
Map<String, String> valueMap = new HashMap<>();
Splitter splitter = Splitter.on(OTHER_CONFIG_PARAMETERS_DELIMITER);
for (String keyValue : splitter.split(multiKeyValueStr)) {
String[] split = keyValue.split(OTHER_CONFIG_KEY_VALUE_DELIMITER, 2);
if (split.length == 2) {
valueMap.put(split[0], split[1]);
}
}
return valueMap;
}
Aggregations