Search in sources :

Example 41 with Splitter

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);
}
Also used : Splitter(com.google.common.base.Splitter)

Example 42 with Splitter

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());
}
Also used : CharSource(com.google.common.io.CharSource) Splitter(com.google.common.base.Splitter) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 43 with Splitter

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;
}
Also used : Splitter(com.google.common.base.Splitter) Properties(java.util.Properties)

Example 44 with Splitter

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;
}
Also used : Splitter(com.google.common.base.Splitter) ObservableValue(com.android.tools.idea.ui.properties.ObservableValue) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with Splitter

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);
    }
}
Also used : Splitter(com.google.common.base.Splitter) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Severity(com.android.tools.klint.detector.api.Severity) Document(org.w3c.dom.Document) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXParseException(org.xml.sax.SAXParseException) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Aggregations

Splitter (com.google.common.base.Splitter)86 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)11 HashSet (java.util.HashSet)10 File (java.io.File)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 BufferedReader (java.io.BufferedReader)4 NonNull (com.android.annotations.NonNull)3 URI (java.net.URI)3 URL (java.net.URL)3 ItemStack (net.minecraft.item.ItemStack)3 StringColumn (tech.tablesaw.api.StringColumn)3 CharMatcher (com.google.common.base.CharMatcher)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 CharSource (com.google.common.io.CharSource)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2