Example usage for com.google.common.base Splitter on

List of usage examples for com.google.common.base Splitter on

Introduction

In this page you can find the example usage for com.google.common.base Splitter on.

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter on(final Pattern separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching pattern to be a separator.

Usage

From source file:org.dcache.nfs.ExportPathCreator.java

public void init() throws IOException {
    Inode root = vfs.getRootInode();/*from www.  j a va 2  s .  c om*/
    for (FsExport export : exportFile.getExports()) {
        String path = export.getPath();
        Splitter splitter = Splitter.on('/').omitEmptyStrings();
        Inode inode = root;
        for (String s : splitter.split(path)) {

            Inode child;
            try {
                child = vfs.lookup(inode, s);
            } catch (NoEntException e) {
                child = vfs.create(inode, Stat.Type.DIRECTORY, s, Subjects.ROOT, 0777);
            }
        }
    }
}

From source file:com.android.tools.idea.gradle.project.sync.errors.JavaHeapSpaceErrorHandler.java

@Override
@Nullable//  ww w  .j ava2s  .  c om
protected String findErrorMessage(@NotNull Throwable rootCause, @NotNull NotificationData notification,
        @NotNull Project project) {
    String text = rootCause.getMessage();
    List<String> message = Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text);
    int lineCount = message.size();
    String firstLine = message.get(0);
    String newMsg = null;

    if (isNotEmpty(firstLine) && firstLine.endsWith("Java heap space")) {
        newMsg = firstLine + ".";
    } else if (isNotEmpty(firstLine) && lineCount > 1
            && firstLine.startsWith("Unable to start the daemon process")) {
        String cause = null;
        for (int i = 1; i < lineCount; i++) {
            String line = message.get(i);
            if ("Error occurred during initialization of VM".equals(line)) {
                // The cause of the error is in the next line.
                if (i < lineCount - 1) {
                    cause = message.get(i + 1);
                    break;
                }
            }
        }
        if (cause != null && cause.startsWith("Could not reserve enough space for object heap")) {
            firstLine = trimEnd(firstLine, ".");
            if (!cause.endsWith(".")) {
                cause += ".";
            }
            newMsg = firstLine + ": " + decapitalize(cause);
        }
    }
    if (isNotEmpty(newMsg)) {
        newMsg += "\nPlease assign more memory to Gradle in the project's gradle.properties file.\n"
                + "For example, the following line, in the gradle.properties file, sets the maximum Java heap size to 1,024 MB:\n"
                + "<em>org.gradle.jvmargs=-Xmx1024m</em>";
        if (rootCause instanceof OutOfMemoryError) {
            newMsg = "Out of memory: " + newMsg;
            updateUsageTracker(OUT_OF_MEMORY);
        } else {
            updateUsageTracker();
        }
        return newMsg;
    }
    return null;
}

From source file:org.jclouds.virtualbox.util.MachineNameOrIdAndNicSlot.java

public static MachineNameOrIdAndNicSlot fromString(String machineNameOrIdAndNicSlotString) {
    Iterable<String> splittedString = Splitter.on(SEPARATOR).split(machineNameOrIdAndNicSlotString);
    checkState(Iterables.size(splittedString) == 2);
    String machineNameOrId = Strings.nullToEmpty(Iterables.get(splittedString, 0));
    String nicSlotString = Strings.nullToEmpty(Iterables.get(splittedString, 1));
    checkArgument(!nicSlotString.startsWith("+"), "Unparseable slot number: %s", nicSlotString);
    try {//w  w w .j av  a 2 s . com
        long slot = Long.parseLong(nicSlotString);
        checkArgument(isValidSlot(slot), "Slot number out of range: %s", nicSlotString);
        return new MachineNameOrIdAndNicSlot(machineNameOrId, slot);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Unparseable slot number: " + nicSlotString);
    }
}

From source file:com.android.tools.idea.npw.project.AndroidGradleModuleUtils.java

/**
 * Given a file and a project, return the Module corresponding to the containing Gradle project for the file.  If the file is not
 * contained by any project then return null
 *///from   w w  w.  j  a  v  a  2 s.com
@Nullable
public static Module getContainingModule(File file, Project project) {
    VirtualFile vFile = VfsUtil.findFileByIoFile(file, false);
    if (vFile == null) {
        return null;
    }
    Module bestMatch = null;
    int bestMatchValue = Integer.MAX_VALUE;
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        GradleFacet facet = GradleFacet.getInstance(module);
        if (facet != null) {
            GradleModuleModel gradleModuleModel = facet.getGradleModuleModel();
            assert gradleModuleModel != null;
            VirtualFile buildFile = gradleModuleModel.getBuildFile();
            if (buildFile != null) {
                VirtualFile root = buildFile.getParent();
                if (VfsUtilCore.isAncestor(root, vFile, true)) {
                    String relativePath = VfsUtilCore.getRelativePath(vFile, root, '/');
                    if (relativePath != null) {
                        int value = Iterables.size(Splitter.on('/').split(relativePath));
                        if (value < bestMatchValue) {
                            bestMatch = module;
                            bestMatchValue = value;
                        }
                    }
                }
            }
        }
    }
    return bestMatch;
}

From source file:org.apache.rocketmq.console.service.impl.OpsServiceImpl.java

@Override
public Map<String, Object> homePageInfo() {
    Map<String, Object> homePageInfoMap = Maps.newHashMap();
    homePageInfoMap.put("namesvrAddrList", Splitter.on(";").splitToList(rMQConfigure.getNamesrvAddr()));
    homePageInfoMap.put("useVIPChannel", Boolean.valueOf(rMQConfigure.getIsVIPChannel()));
    return homePageInfoMap;
}

From source file:com.bennavetta.aeneas.cli.zookeeper.CreateNodes.java

@Override
protected int execute() {
    for (String nodeSpec : nodes) {
        if (nodeSpec.contains("=")) {
            Iterable<String> parts = Splitter.on('=').split(nodeSpec);
            if (Iterables.size(parts) != 2) {
                System.err.println("Invalid node specification: " + nodeSpec);
                return 1;
            }//  www  .  ja  v  a2  s.c  o m

            String containerName = Iterables.get(parts, 0);
            Iterable<String> ports = Splitter.on(';').split(Iterables.get(parts, 1));
            if (Iterables.size(ports) != 3) {
                System.err.println("Invalid port specification: " + nodeSpec);
            }

            int peerPort = Integer.parseInt(Iterables.get(ports, 0));
            int electionPort = Integer.parseInt(Iterables.get(ports, 1));
            int clientPort = Integer.parseInt(Iterables.get(ports, 2));

            System.out.println(createNode(containerName, peerPort, electionPort, clientPort));
        } else {
            int id = Integer.parseInt(nodeSpec);
            String containerName = ZooKeeperNodes.containerName(id);
            int peerPort = ZooKeeperNodes.peerPort(id);
            int electionPort = ZooKeeperNodes.electionPort(id);
            int clientPort = ZooKeeperNodes.clientPort(id);

            System.out.println(createNode(containerName, peerPort, electionPort, clientPort));
        }
    }

    return 0;
}

From source file:org.apache.metron.dataloads.extractor.csv.CSVExtractor.java

private static Map.Entry<String, Integer> getColumnMapEntry(String column, int i) {
    if (column.contains(":")) {
        Iterable<String> tokens = Splitter.on(':').split(column);
        String col = Iterables.getFirst(tokens, null);
        Integer pos = Integer.parseInt(Iterables.getLast(tokens));
        return new AbstractMap.SimpleEntry<>(col, pos);
    } else {//w ww  .  j  a  v a  2  s  . c o m
        return new AbstractMap.SimpleEntry<>(column, i);
    }

}

From source file:com.google.devtools.kythe.platform.java.filemanager.CompilationUnitFileTree.java

public CompilationUnitFileTree(Iterable<CompilationUnit.FileInput> inputs) {
    // Build a directory map from the list of required inputs.
    for (CompilationUnit.FileInput input : inputs) {
        String path = input.getInfo().getPath();
        String digest = input.getInfo().getDigest();
        putDigest(path, digest);/*from   w  ww  .jav a2s . co  m*/

        StringBuilder pathBuilder = new StringBuilder();
        for (String dir : Splitter.on('/').split(PathUtil.dirname(path))) {
            pathBuilder.append(dir);
            putDigest(pathBuilder.toString(), DIRECTORY_DIGEST);
            pathBuilder.append('/');
        }
    }
}

From source file:com.android.tools.idea.gradle.project.sync.errors.DaemonContextMismatchErrorHandler.java

@Override
@Nullable/*ww  w.  j  a va2s.c  om*/
protected String findErrorMessage(@NotNull Throwable rootCause, @NotNull NotificationData notification,
        @NotNull Project project) {
    String text = rootCause.getMessage();
    List<String> message = Splitter.on('\n').omitEmptyStrings().trimResults().splitToList(text);
    String firstLine = message.get(0);
    if (isNotEmpty(firstLine)
            && firstLine.contains("The newly created daemon process has a different context than expected.")
            && message.size() > 3 && "Java home is different.".equals(message.get(2))) {
        String expectedAndActual = parseExpectedAndActualJavaHomes(text);
        if (isNotEmpty(expectedAndActual)) {
            updateUsageTracker();
            return firstLine + "\n" + message.get(2) + "\n" + expectedAndActual + "\n"
                    + "Please configure the JDK to match the expected one.";
        }
    }
    return null;
}

From source file:com.proofpoint.http.server.ClientAddressExtractor.java

public String clientAddressFor(HttpServletRequest request) {
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (Enumeration<String> e = request.getHeaders("X-FORWARDED-FOR"); e != null && e.hasMoreElements();) {
        String forwardedFor = e.nextElement();
        builder.addAll(Splitter.on(',').trimResults().omitEmptyStrings().split(forwardedFor));
    }/*from ww  w  .j  a v a 2  s  .  c o m*/
    if (request.getRemoteAddr() != null) {
        builder.add(request.getRemoteAddr());
    }
    String clientAddress = null;
    ImmutableList<String> clientAddresses = builder.build();
    for (String address : Lists.reverse(clientAddresses)) {
        try {
            if (!trustedNetworks.containsAddress(InetAddresses.forString(address))) {
                clientAddress = address;
                break;
            }
            clientAddress = address;
        } catch (IllegalArgumentException ignored) {
            break;
        }
    }
    if (clientAddress == null) {
        clientAddress = request.getRemoteAddr();
    }
    return clientAddress;
}