Search in sources :

Example 31 with Splitter

use of com.google.common.base.Splitter in project guava by hceylan.

the class FilesSimplifyPathTest method doExtensiveTest.

private void doExtensiveTest(String resourceName) throws IOException {
    Splitter splitter = Splitter.on(CharMatcher.WHITESPACE);
    URL url = getClass().getResource(resourceName);
    for (String line : Resources.readLines(url, UTF_8)) {
        Iterator<String> iterator = splitter.split(line).iterator();
        String input = iterator.next();
        String expectedOutput = iterator.next();
        assertFalse(iterator.hasNext());
        assertEquals(expectedOutput, simplifyPath(input));
    }
}
Also used : Splitter(com.google.common.base.Splitter) URL(java.net.URL)

Example 32 with Splitter

use of com.google.common.base.Splitter in project platformlayer by platformlayer.

the class IpsecPresharedKey method handler.

@Handler
public void handler(OpsTarget target) throws OpsException {
    if (OpsContext.isConfigure()) {
        File pskFile = new File("/etc/racoon/psk.txt");
        String psk = target.readTextFile(pskFile);
        if (psk == null) {
            psk = "# Managed by PlatformLayer\n";
        }
        boolean found = false;
        // TODO: Extend MapSplitter / add some helper functions??
        Splitter keyValueSpliter = Splitter.on(CharMatcher.WHITESPACE).limit(2).omitEmptyStrings().trimResults();
        Map<String, String> psks = Maps.newHashMap();
        for (String line : Splitter.on("\n").trimResults().omitEmptyStrings().split(psk)) {
            if (line.startsWith("#")) {
                continue;
            }
            List<String> tokens = Lists.newArrayList(keyValueSpliter.split(line));
            if (tokens.size() != 2) {
                throw new OpsException("Cannot parse PSK line: " + line);
            }
            String key = tokens.get(0);
            String value = tokens.get(1);
            if (psks.containsKey(key)) {
                // (We could check to see if they're the same, but this is generally not good)
                throw new OpsException("Found duplicate PSK");
            }
            psks.put(key, value);
            if (!key.equals(id)) {
                continue;
            }
            if (value.equals(secret.plaintext())) {
                found = true;
            }
        }
        if (!found) {
            psk = psk + "\n";
            psk += id + " " + secret.plaintext() + "\n";
            FileUpload.upload(target, pskFile, psk);
            target.executeCommand(Command.build("racoonctl reload-config"));
        }
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) Splitter(com.google.common.base.Splitter) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 33 with Splitter

use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.

the class ChangeField method getFileParts.

public static Set<String> getFileParts(ChangeData cd) {
    List<String> paths = cd.currentFilePaths();
    Splitter s = Splitter.on('/').omitEmptyStrings();
    Set<String> r = new HashSet<>();
    for (String path : paths) {
        for (String part : s.split(path)) {
            r.add(part);
        }
    }
    return r;
}
Also used : Splitter(com.google.common.base.Splitter) HashSet(java.util.HashSet)

Example 34 with Splitter

use of com.google.common.base.Splitter in project xtext-core by eclipse.

the class PreferenceTaskTagProvider method parseTags.

public static List<TaskTag> parseTags(String names, String priorities) {
    Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
    List<String> tags = toList(splitter.split(names));
    List<String> prios = toList(splitter.split(priorities));
    List<TaskTag> elements = new ArrayList<>();
    for (int i = 0; i < tags.size(); i++) {
        TaskTag taskTag = new TaskTag();
        taskTag.setName(tags.get(i));
        Priority priority = Priority.NORMAL;
        if (prios.size() >= i) {
            try {
                priority = Priority.valueOf(prios.get(i));
            } catch (IllegalArgumentException ignore) {
            }
        }
        taskTag.setPriority(priority);
        elements.add(taskTag);
    }
    return elements;
}
Also used : Splitter(com.google.common.base.Splitter) ArrayList(java.util.ArrayList)

Example 35 with Splitter

use of com.google.common.base.Splitter in project cuba by cuba-platform.

the class AppComponents method load.

private void load(AppComponent component) {
    Document doc = getDescriptorDoc(component);
    String dependsOnAttr = doc.getRootElement().attributeValue("dependsOn");
    if (!StringUtils.isEmpty(dependsOnAttr)) {
        for (String depCompId : splitCommaSeparatedValue(dependsOnAttr)) {
            AppComponent depComp = get(depCompId);
            if (depComp == null) {
                depComp = new AppComponent(depCompId);
                load(depComp);
                components.add(depComp);
            }
            component.addDependency(depComp);
        }
    }
    for (Element moduleEl : doc.getRootElement().elements("module")) {
        String blocksAttr = moduleEl.attributeValue("blocks");
        if (StringUtils.isEmpty(blocksAttr)) {
            continue;
        }
        List<String> blocks = splitCommaSeparatedValue(blocksAttr);
        if (blocks.contains("*") || blocks.contains(block)) {
            for (Element propertyEl : moduleEl.elements("property")) {
                String name = propertyEl.attributeValue("name");
                String value = propertyEl.attributeValue("value");
                String existingValue = component.getProperty(name);
                if (value.startsWith("\\+")) {
                    if (existingValue != null) {
                        log.debug("Overwrite value of property {} from {} to {}", name, existingValue, value);
                    }
                    component.setProperty(name, value.substring(1), false);
                    continue;
                }
                if (!value.startsWith("+")) {
                    if (existingValue != null) {
                        log.debug("Overwrite value of property {} from {} to {}", name, existingValue, value);
                    }
                    component.setProperty(name, value, false);
                    continue;
                }
                String cleanValue = value.substring(1);
                if (existingValue != null) {
                    StringBuilder newValue = new StringBuilder(existingValue);
                    Splitter splitter = Splitter.on(AppProperties.SEPARATOR_PATTERN).omitEmptyStrings();
                    List<String> existingParts = splitter.splitToList(existingValue);
                    for (String part : splitter.split(cleanValue)) {
                        if (!existingParts.contains(part)) {
                            newValue.append(" ").append(part);
                        }
                    }
                    component.setProperty(name, newValue.toString(), true);
                } else {
                    component.setProperty(name, cleanValue, true);
                }
            }
        }
    }
}
Also used : Splitter(com.google.common.base.Splitter) Element(org.dom4j.Element) Document(org.dom4j.Document)

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