List of usage examples for com.google.common.base Splitter split
@CheckReturnValue public Iterable<String> split(final CharSequence sequence)
From source file:annis.service.objects.Match.java
public static Match parseFromString(String raw, char separator) { Match match = new Match(); Splitter splitter = matchSplitter; if (separator != ' ') { splitter = Splitter.on(separator).trimResults().omitEmptyStrings(); }/*from w w w.jav a2s . co m*/ for (String singleMatch : splitter.split(raw)) { URI uri; String id = ""; String anno = null; if (singleMatch.startsWith("salt:/")) { id = singleMatch; } else { // split into the annotation namespace/name and the salt URI List<String> components = annoIDSplitter.splitToList(singleMatch); int componentsSize = components.size(); Preconditions.checkArgument(componentsSize == 3 || componentsSize == 2, "A match containing " + "annotation information always has to have the form " + "ns::name::salt:/.... or name::salt:/...."); String ns = ""; String name = ""; if (componentsSize == 3) { id = components.get(2); ns = components.get(0); name = components.get(1); } else if (componentsSize == 2) { id = components.get(1); name = components.get(0); } if (ns.isEmpty()) { anno = name; } else { anno = ns + "::" + name; } } try { uri = new java.net.URI(id).normalize(); if (!"salt".equals(uri.getScheme()) || uri.getFragment() == null) { throw new URISyntaxException("not a Salt id", uri.toString()); } } catch (URISyntaxException ex) { log.error("Invalid syntax for ID " + singleMatch, ex); continue; } match.addSaltId(uri, anno); } return match; }
From source file:org.dcache.nfs.ExportFile.java
private static ImmutableMultimap<Integer, FsExport> parse(URI exportFile) throws IOException { ImmutableListMultimap.Builder<Integer, FsExport> exportsBuilder = ImmutableListMultimap.builder(); for (String line : Files.readAllLines(Paths.get(exportFile))) { line = line.trim();//from w w w .j a v a2 s . c om if (line.length() == 0) { continue; } if (line.charAt(0) == '#') { continue; } if (line.charAt(0) != '/') { _log.warn("Ignoring entry with non absolute export path: " + line); continue; } int pathEnd = line.indexOf(' '); String path; if (pathEnd < 0) { FsExport export = new FsExport.FsExportBuilder().build(line); exportsBuilder.put(export.getIndex(), export); continue; } else { path = line.substring(0, pathEnd); } Splitter splitter = Splitter.on(' ').omitEmptyStrings().trimResults(); for (String hostAndOptions : splitter.split(line.substring(pathEnd + 1))) { try { FsExport.FsExportBuilder exportBuilder = new FsExport.FsExportBuilder(); Iterator<String> s = Splitter.on(CharMatcher.anyOf("(,)")).omitEmptyStrings().trimResults() .split(hostAndOptions).iterator(); String host = s.next(); exportBuilder.forClient(host); while (s.hasNext()) { String option = s.next(); if (option.equals("rw")) { exportBuilder.rw(); continue; } if (option.equals("ro")) { exportBuilder.ro(); continue; } if (option.equals("root_squash")) { exportBuilder.notTrusted(); continue; } if (option.equals("no_root_squash")) { exportBuilder.trusted(); continue; } if (option.equals("acl")) { exportBuilder.withAcl(); continue; } if (option.equals("noacl") || option.equals("no_acl")) { exportBuilder.withoutAcl(); continue; } if (option.equals("all_squash")) { exportBuilder.allSquash(); continue; } if (option.startsWith("sec=")) { String secFlavor = option.substring(4); exportBuilder.withSec(FsExport.Sec.valueOf(secFlavor.toUpperCase())); continue; } if (option.startsWith("anonuid=")) { int anonuid = Integer.parseInt(option.substring(8)); exportBuilder.withAnonUid(anonuid); continue; } if (option.startsWith("anongid=")) { int anongid = Integer.parseInt(option.substring(8)); exportBuilder.withAnonGid(anongid); continue; } if (option.equals("dcap")) { exportBuilder.withDcap(); continue; } if (option.equals("no_dcap")) { exportBuilder.withoutDcap(); continue; } if (option.equals("all_root")) { exportBuilder.withAllRoot(); continue; } if (option.equals("pnfs")) { exportBuilder.withPnfs(); continue; } if (option.equals("nopnfs") || option.equals("no_pnfs")) { exportBuilder.withoutPnfs(); continue; } throw new IllegalArgumentException("Unsupported option: " + option); } FsExport export = exportBuilder.build(path); exportsBuilder.put(export.getIndex(), export); } catch (IllegalArgumentException e) { _log.error("Invalid export entry [" + hostAndOptions + "] : " + e.getMessage()); } } } /* * sort in reverse order to get smallest network first */ return exportsBuilder .orderValuesBy(Ordering.from(HostEntryComparator::compare).onResultOf(FsExport::client).reverse()) .build(); }
From source file:ch.raffael.contracts.processor.util.ClassName.java
private static String internalClassName(String name, String type, Splitter splitter, String originalName) throws IllegalClassNameException { StringBuilder buf = new StringBuilder(name.length()); for (String seg : splitter.split(name)) { if (!isValidIdentifier(seg)) { throw new IllegalClassNameException(type + ": " + originalName); }/* w ww . ja v a 2 s . com*/ if (buf.length() > 0) { buf.append('/'); } buf.append(seg); } return buf.toString(); }
From source file:com.android.build.gradle.tasks.annotations.ExtractAnnotationsDriver.java
private static List<File> getFiles(String value) { List<File> files = Lists.newArrayList(); Splitter splitter = Splitter.on(pathSeparatorChar).omitEmptyStrings().trimResults(); for (String path : splitter.split(value)) { if (path.startsWith("@")) { // Special syntax for providing files in a list File sourcePath = new File(path.substring(1)); if (!sourcePath.exists()) { abort(sourcePath + " does not exist"); }//from www. j a va 2 s. co m try { for (String line : Files.readLines(sourcePath, Charsets.UTF_8)) { line = line.trim(); if (!line.isEmpty()) { File file = new File(line); if (!file.exists()) { System.err.println( "Warning: Could not find file " + line + " listed in " + sourcePath); } files.add(file); } } continue; } catch (IOException e) { e.printStackTrace(); System.exit(-1); } } File file = new File(path); if (!file.exists()) { abort(file + " does not exist"); } files.add(file); } return files; }
From source file:org.apache.fluo.recipes.test.FluoITHelper.java
/** * A helper method for parsing test data. Each string passed in is split using the specified * splitter into four fields for row, family, qualifier, and value. */// w ww.jav a2s.c o m public static List<RowColumnValue> parse(Splitter splitter, String... data) { ArrayList<RowColumnValue> ret = new ArrayList<>(); for (String line : data) { Iterable<String> cols = splitter.split(line); if (Iterables.size(cols) != 4) { throw new IllegalArgumentException("Bad input " + line); } Iterator<String> iter = cols.iterator(); RowColumnValue rcv = new RowColumnValue(Bytes.of(iter.next()), new Column(iter.next(), iter.next()), Bytes.of(iter.next())); ret.add(rcv); } return ret; }
From source file:org.corpus_tools.peppermodules.annis.tests.TabFileComparator.java
private static List<String> removeIgnoredColumns(Collection<String> originalLines, Set<Integer> ignoreColumns, String placeholder) {/*from w ww .j a v a 2s .com*/ List<String> result = new ArrayList<>(originalLines.size()); Splitter splitter = Splitter.on('\t'); Joiner joiner = Joiner.on("\t"); if (ignoreColumns == null) { ignoreColumns = new HashSet<>(); } for (String l : originalLines) { List<String> newLine = new LinkedList<>(); int columnNr = 0; for (String cell : splitter.split(l)) { if (ignoreColumns.contains(columnNr)) { if (placeholder != null) { newLine.add(placeholder); } } else { newLine.add(cell); } columnNr++; } result.add(joiner.join(newLine)); } return result; }
From source file:ee.ria.xroad.common.messagelog.MessageLogProperties.java
/** * Given one parameter parses it to collection of ClientIds. Parameter * should be of format FI/GOV/1710128-9/MANSIKKA, FI/GOV/1710128-9/MUSTIKKA, that is: * comma separated list of slash-separated subsystem identifiers. * @param clientIdParameters/*from w ww . j av a2 s . co m*/ * @return */ private static Collection<ClientId> parseClientIdParameters(String clientIdParameters) { Collection<ClientId> toReturn = new ArrayList<>(); Iterable<String> splitSubsystemParams = Splitter.on(",").trimResults().omitEmptyStrings() .split(clientIdParameters); Splitter codeSplitter = Splitter.on("/").trimResults(); for (String oneSubsystemParam : splitSubsystemParams) { List<String> codes = Lists.newArrayList(codeSplitter.split(oneSubsystemParam)); if (codes.size() != NUM_COMPONENTS) { throw new IllegalStateException( " SOAP body logging override parameter should be comma-separated list of four " + "slash-separated codes" + " identifying one subsystem," + " for example \"FI/ORG/1234567-1/subsystem1\", detected bad value: " + oneSubsystemParam); } ClientId id = ClientId.create(codes.get(FIRST_COMPONENT), codes.get(SECOND_COMPONENT), codes.get(THIRD_COMPONENT), codes.get(FOURTH_COMPONENT)); toReturn.add(id); } return toReturn; }
From source file:io.prestosql.cli.ClientOptions.java
public static Set<String> parseClientTags(String clientTagsString) { Splitter splitter = Splitter.on(',').trimResults().omitEmptyStrings(); return ImmutableSet.copyOf(splitter.split(nullToEmpty(clientTagsString))); }
From source file:org.opendaylight.openflowjava.util.ByteBufUtils.java
/** * Converts String into byte[]/*from www .ja va2 s. c o m*/ * @param hexSrc input String * @param withSpaces if there are spaces in string * @return byte[] filled with input data */ public static byte[] hexStringToBytes(final String hexSrc, final boolean withSpaces) { final Splitter splitter = withSpaces ? HEXSTRING_SPLITTER : HEXSTRING_NOSPACE_SPLITTER; List<String> byteChips = Lists.newArrayList(splitter.split(hexSrc)); byte[] result = new byte[byteChips.size()]; int i = 0; for (String chip : byteChips) { result[i] = (byte) Short.parseShort(chip, 16); i++; } return result; }
From source file:com.google.gerrit.server.index.SchemaUtil.java
public static Set<String> getNameParts(String name, Iterable<String> emails) { Splitter at = Splitter.on('@'); Splitter s = Splitter.on(CharMatcher.anyOf("@.- /_")).omitEmptyStrings(); HashSet<String> parts = new HashSet<>(); for (String email : emails) { if (email == null) { continue; }//from w w w. java 2 s . c om String lowerEmail = email.toLowerCase(Locale.US); parts.add(lowerEmail); Iterables.addAll(parts, at.split(lowerEmail)); Iterables.addAll(parts, s.split(lowerEmail)); } if (name != null) { Iterables.addAll(parts, s.split(name.toLowerCase(Locale.US))); } return parts; }