use of com.google.common.base.Splitter in project MinecraftForge by MinecraftForge.
the class FMLDeobfuscatingRemapper method setupLoadOnly.
public void setupLoadOnly(String deobfFileName, boolean loadAll) {
try {
File mapData = new File(deobfFileName);
LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData));
CharSource srgSource = zis.asCharSource(Charsets.UTF_8);
List<String> srgList = srgSource.readLines();
rawMethodMaps = Maps.newHashMap();
rawFieldMaps = Maps.newHashMap();
Builder<String, String> builder = ImmutableBiMap.builder();
Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults();
for (String line : srgList) {
String[] parts = Iterables.toArray(splitter.split(line), String.class);
String typ = parts[0];
if ("CL".equals(typ)) {
parseClass(builder, parts);
} else if ("MD".equals(typ) && loadAll) {
parseMethod(parts);
} else if ("FD".equals(typ) && loadAll) {
parseField(parts);
}
}
classNameBiMap = builder.build();
} catch (IOException ioe) {
FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe);
}
methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size());
fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size());
}
use of com.google.common.base.Splitter in project ratpack by ratpack.
the class ArgsConfigSource method loadProperties.
@Override
protected Properties loadProperties() throws Exception {
Splitter splitter = Splitter.on(separator).limit(2);
Properties properties = new Properties();
for (String arg : args) {
List<String> values = splitter.splitToList(arg);
if (values.size() == 1) {
properties.put(values.get(0), "");
} else {
properties.put(values.get(0), values.get(1));
}
}
return properties;
}
use of com.google.common.base.Splitter in project android by JetBrains.
the class ServiceContext method toValueMap.
/**
* Converts this service context, which is itself backed by a flat map, into a hierarchical map,
* a data structure that freemarker works well with.
* <p/>
* For example, a service context with the values "parent.child1" and "parent.child2" will return
* a map that is nested like so
* <pre>
* parent
* child1
* child2
* </pre>
*/
@NotNull
public Map<String, Object> toValueMap() {
Map<String, Object> valueMap = Maps.newHashMap();
Splitter splitter = Splitter.on('.');
for (String key : myValues.keySet()) {
ObservableValue value = getValue(key);
Map<String, Object> currLevel = valueMap;
Iterator<String> keyParts = splitter.split(key).iterator();
while (keyParts.hasNext()) {
String keyPart = keyParts.next();
if (keyParts.hasNext()) {
if (currLevel.containsKey(keyPart)) {
currLevel = (Map<String, Object>) currLevel.get(keyPart);
} else {
Map<String, Object> nextLevel = Maps.newHashMap();
currLevel.put(keyPart, nextLevel);
currLevel = nextLevel;
}
} else {
// We're the last part of the key
currLevel.put(keyPart, value);
}
}
}
return valueMap;
}
use of com.google.common.base.Splitter in project kotlin by JetBrains.
the class DefaultConfiguration method readConfig.
private void readConfig() {
mSuppressed = new HashMap<String, List<String>>();
mSeverity = new HashMap<String, Severity>();
if (!mConfigFile.exists()) {
return;
}
try {
Document document = XmlUtils.parseUtfXmlFile(mConfigFile, false);
NodeList issues = document.getElementsByTagName(TAG_ISSUE);
Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings();
for (int i = 0, count = issues.getLength(); i < count; i++) {
Node node = issues.item(i);
Element element = (Element) node;
String idList = element.getAttribute(ATTR_ID);
if (idList.isEmpty()) {
formatError("Invalid lint config file: Missing required issue id attribute");
continue;
}
Iterable<String> ids = splitter.split(idList);
NamedNodeMap attributes = node.getAttributes();
for (int j = 0, n = attributes.getLength(); j < n; j++) {
Node attribute = attributes.item(j);
String name = attribute.getNodeName();
String value = attribute.getNodeValue();
if (ATTR_ID.equals(name)) {
// already handled
} else if (ATTR_SEVERITY.equals(name)) {
for (Severity severity : Severity.values()) {
if (value.equalsIgnoreCase(severity.name())) {
for (String id : ids) {
mSeverity.put(id, severity);
}
break;
}
}
} else {
formatError("Unexpected attribute \"%1$s\"", name);
}
}
// Look up ignored errors
NodeList childNodes = element.getChildNodes();
if (childNodes.getLength() > 0) {
for (int j = 0, n = childNodes.getLength(); j < n; j++) {
Node child = childNodes.item(j);
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element ignore = (Element) child;
String path = ignore.getAttribute(ATTR_PATH);
if (path.isEmpty()) {
String regexp = ignore.getAttribute(ATTR_REGEXP);
if (regexp.isEmpty()) {
formatError("Missing required attribute %1$s or %2$s under %3$s", ATTR_PATH, ATTR_REGEXP, idList);
} else {
addRegexp(idList, ids, n, regexp, false);
}
} else {
// handle the file format containing / or \.
if (File.separatorChar == '/') {
path = path.replace('\\', '/');
} else {
path = path.replace('/', File.separatorChar);
}
if (path.indexOf('*') != -1) {
String regexp = globToRegexp(path);
addRegexp(idList, ids, n, regexp, false);
} else {
for (String id : ids) {
List<String> paths = mSuppressed.get(id);
if (paths == null) {
paths = new ArrayList<String>(n / 2 + 1);
mSuppressed.put(id, paths);
}
paths.add(path);
}
}
}
}
}
}
}
} catch (SAXParseException e) {
formatError(e.getMessage());
} catch (Exception e) {
mClient.log(e, null);
}
}
use of com.google.common.base.Splitter in project Railcraft by Railcraft.
the class Railcraft method processIMCRequests.
@Mod.EventHandler
public void processIMCRequests(FMLInterModComms.IMCEvent event) {
Splitter splitter = Splitter.on("@").trimResults();
for (FMLInterModComms.IMCMessage mess : event.getMessages()) {
if (mess.key.equals("ballast")) {
String[] tokens = Iterables.toArray(splitter.split(mess.getStringValue()), String.class);
if (tokens.length != 2) {
Game.log(Level.WARN, String.format("Mod %s attempted to register a ballast, but failed: %s", mess.getSender(), mess.getStringValue()));
continue;
}
String blockName = tokens[0];
Integer metadata = Ints.tryParse(tokens[1]);
if (blockName == null || metadata == null) {
Game.log(Level.WARN, String.format("Mod %s attempted to register a ballast, but failed: %s", mess.getSender(), mess.getStringValue()));
continue;
}
BallastRegistry.registerBallast(Block.getBlockFromName(blockName), metadata);
Game.log(Level.DEBUG, String.format("Mod %s registered %s as a valid ballast", mess.getSender(), mess.getStringValue()));
} else if (mess.key.equals("boiler-fuel-liquid")) {
String[] tokens = Iterables.toArray(splitter.split(mess.getStringValue()), String.class);
if (tokens.length != 2) {
Game.log(Level.WARN, String.format("Mod %s attempted to register a liquid Boiler fuel, but failed: %s", mess.getSender(), mess.getStringValue()));
continue;
}
Fluid fluid = FluidRegistry.getFluid(tokens[0]);
Integer fuel = Ints.tryParse(tokens[1]);
if (fluid == null || fuel == null) {
Game.log(Level.WARN, String.format("Mod %s attempted to register a liquid Boiler fuel, but failed: %s", mess.getSender(), mess.getStringValue()));
continue;
}
FuelManager.addBoilerFuel(fluid, fuel);
Game.log(Level.DEBUG, String.format("Mod %s registered %s as a valid liquid Boiler fuel", mess.getSender(), mess.getStringValue()));
} else if (mess.key.equals("rock-crusher")) {
NBTTagCompound nbt = mess.getNBTValue();
ItemStack input = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("input"));
ICrusherCraftingManager.ICrusherRecipe recipe = RailcraftCraftingManager.rockCrusher.createAndAddRecipe(input, nbt.getBoolean("matchMeta"), nbt.getBoolean("matchNBT"));
for (int i = 0; i < 9; i++) {
if (nbt.hasKey("output" + i)) {
NBTTagCompound outputNBT = nbt.getCompoundTag("output" + i);
recipe.addOutput(ItemStack.loadItemStackFromNBT(outputNBT), outputNBT.getFloat("chance"));
}
}
} else if (mess.key.equals("high-speed-explosion-excluded-entities")) {
NBTTagCompound nbt = mess.getNBTValue();
if (nbt.hasKey("entities")) {
String entities = nbt.getString("entities");
Iterable<String> split = splitter.split(entities);
RailcraftConfig.excludedAllEntityFromHighSpeedExplosions(split);
} else {
Game.log(Level.WARN, "Mod %s attempted to exclude an entity from H.S. explosions, but failed: %s", mess.getSender(), nbt);
}
}
}
}
Aggregations