use of com.google.common.base.Splitter in project MinecraftForge by MinecraftForge.
the class ConfigCategory method write.
public void write(BufferedWriter out, int indent) throws IOException {
String pad0 = getIndent(indent);
String pad1 = getIndent(indent + 1);
String pad2 = getIndent(indent + 2);
if (comment != null && !comment.isEmpty()) {
write(out, pad0, COMMENT_SEPARATOR);
write(out, pad0, "# ", name);
write(out, pad0, "#--------------------------------------------------------------------------------------------------------#");
Splitter splitter = Splitter.onPattern("\r?\n");
for (String line : splitter.split(comment)) {
write(out, pad0, "# ", line);
}
write(out, pad0, COMMENT_SEPARATOR, NEW_LINE);
}
String displayName = name;
if (!allowedProperties.matchesAllOf(name)) {
displayName = '"' + name + '"';
}
write(out, pad0, displayName, " {");
Property[] props = getOrderedValues().toArray(new Property[] {});
for (int x = 0; x < props.length; x++) {
Property prop = props[x];
if (prop.getComment() != null && !prop.getComment().isEmpty()) {
if (x != 0) {
out.newLine();
}
Splitter splitter = Splitter.onPattern("\r?\n");
for (String commentLine : splitter.split(prop.getComment())) {
write(out, pad1, "# ", commentLine);
}
}
String propName = prop.getName();
if (!allowedProperties.matchesAllOf(propName)) {
propName = '"' + propName + '"';
}
if (prop.isList()) {
char type = prop.getType().getID();
write(out, pad1, String.valueOf(type), ":", propName, " <");
for (String line : prop.getStringList()) {
write(out, pad2, line);
}
write(out, pad1, " >");
} else if (prop.getType() == null) {
write(out, pad1, propName, "=", prop.getString());
} else {
char type = prop.getType().getID();
write(out, pad1, String.valueOf(type), ":", propName, "=", prop.getString());
}
}
if (children.size() > 0)
out.newLine();
for (ConfigCategory child : children) {
child.write(out, indent + 1);
}
write(out, pad0, "}", NEW_LINE);
}
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);
}
}
Aggregations