List of usage examples for com.google.common.base Splitter split
@CheckReturnValue public Iterable<String> split(final CharSequence sequence)
From source file:com.google.gerrit.server.index.change.ChangeField.java
public static Set<String> getFileParts(ChangeData cd) throws OrmException { List<String> paths = cd.currentFilePaths(); if (paths == null) { return ImmutableSet.of(); }/*from w w w. j a v a2 s .com*/ 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; }
From source file:annis.CommonHelper.java
public static Match extractMatch(SDocument doc) throws URISyntaxException { Splitter idSplit = Splitter.on(',').trimResults(); Match m = null;/* w w w .j av a2 s.c o m*/ // get the matched node IDs SFeature featIDs = doc.getSFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_MATCHEDIDS); if (featIDs != null) { LinkedList<URI> idList = new LinkedList<>(); for (String rawID : idSplit.split(featIDs.getSValueSTEXT())) { idList.add(new URI(rawID)); } SFeature featAnnos = doc.getSFeature(AnnisConstants.ANNIS_NS, AnnisConstants.FEAT_MATCHEDANNOS); if (featAnnos == null) { m = new Match(idList); } else { m = new Match(idList, idSplit.splitToList(featAnnos.getSValueSTEXT())); } } return m; }
From source file:com.mapr.synth.samplers.VinSampler.java
private static Map<String, String> mapResource(String name) throws IOException { final Splitter onTab = Splitter.on("\t"); return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<Map<String, String>>() { final Map<String, String> r = Maps.newHashMap(); @Override// w ww.j av a 2 s . com public boolean processLine(String line) throws IOException { Iterator<String> pieces = onTab.split(line).iterator(); String key = pieces.next(); r.put(key, pieces.next()); return true; } @Override public Map<String, String> getResult() { return r; } }); }
From source file:com.mapr.synth.samplers.VinSampler.java
private static SetMultimap<String, String> multiMapResource(String name) throws IOException { final Splitter onTab = Splitter.on("\t"); return Resources.readLines(Resources.getResource(name), Charsets.UTF_8, new LineProcessor<SetMultimap<String, String>>() { final SetMultimap<String, String> r = HashMultimap.create(); @Override//from w ww.j a v a 2 s .c o m public boolean processLine(String line) throws IOException { Iterator<String> pieces = onTab.split(line).iterator(); String key = pieces.next(); r.put(key, pieces.next()); return true; } @Override public SetMultimap<String, String> getResult() { return r; } }); }
From source file:org.apache.giraph.hive.HiveGiraphRunner.java
/** * @param outputTablePartitionString table partition string * @return Map//from www .j ava 2 s .c om */ public static Map<String, String> parsePartitionValues(String outputTablePartitionString) { if (outputTablePartitionString == null) { return null; } Splitter commaSplitter = Splitter.on(',').omitEmptyStrings().trimResults(); Splitter equalSplitter = Splitter.on('=').omitEmptyStrings().trimResults(); Map<String, String> partitionValues = Maps.newHashMap(); for (String keyValStr : commaSplitter.split(outputTablePartitionString)) { List<String> keyVal = Lists.newArrayList(equalSplitter.split(keyValStr)); if (keyVal.size() != 2) { throw new IllegalArgumentException( "Unrecognized partition value format: " + outputTablePartitionString); } partitionValues.put(keyVal.get(0), keyVal.get(1)); } return partitionValues; }
From source file:co.cask.cdap.internal.app.runtime.batch.distributed.MapReduceContainerHelper.java
/** * Returns a list of path to be used for the MapReduce framework classpath. * * @param hConf the configuration for the job. * @param result a list for appending MR framework classpath * @return the same {@code result} list from the argument *//*w w w. java2 s . co m*/ public static List<String> getMapReduceClassPath(Configuration hConf, List<String> result) { String framework = hConf.get(MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH); // For classpath config get from the hConf, we splits it with both "," and ":" because one can set // the conf with something like "path1,path2:path3" and // it should become "path1:path2:path3" in the target JVM process Splitter splitter = Splitter.on(Pattern.compile(",|" + File.pathSeparatorChar)).trimResults() .omitEmptyStrings(); // If MR framework is non specified, use yarn.application.classpath and mapreduce.application.classpath // Otherwise, only use the mapreduce.application.classpath if (framework == null) { String yarnClassPath = hConf.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH, Joiner.on(",").join(YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)); Iterables.addAll(result, splitter.split(yarnClassPath)); } // Add MR application classpath Iterables.addAll(result, splitter.split(hConf.get(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH, MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH))); return result; }
From source file:edu.wisc.ssec.mcidasv.util.SystemState.java
/** * Return McIDAS-V's classpath.// w ww . ja va 2 s .c om * * <p>This may differ from what is reported by * {@code System.getProperty("java.class.path")}. This is because McIDAS-V * specifies its classpath using {@code META-INF/MANIFEST.MF} in * {@code mcidasv.jar}. * </p> * * <p>This is used by console_init.py to figure out where the VisAD, * IDV, and McIDAS-V JAR files are located.</p> * * @return Either a list of strings containing the path to each JAR file * in the classpath, or an empty list. */ public static List<String> getMcvJarClasspath() { String jarDir = System.getProperty("user.dir"); if (jarDir == null) { jarDir = PosixModule.getcwd().toString(); } // 64 chosen because we're currently at 38 JARs. List<String> jars = arrList(64); try { String mcvJar = getMcvJarname(jarDir); Path p = Paths.get(jarDir, mcvJar); String path = "jar:file:" + p.toString() + "!/META-INF/MANIFEST.MF"; InputStream stream = IOUtil.getInputStream(path); if (stream != null) { Manifest manifest = new Manifest(stream); Attributes attrs = manifest.getMainAttributes(); if (attrs != null) { String classpath = attrs.getValue("Class-Path"); Splitter split = Splitter.on(' ').trimResults().omitEmptyStrings(); for (String jar : split.split(classpath)) { jars.add(Paths.get(jarDir, jar).toFile().toString()); } } } } catch (IOException | NullPointerException e) { logger.warn("Exception occurred:", e); } return jars; }
From source file:me.taylorkelly.mywarp.bukkit.util.FormattingUtils.java
/** * Creates a not numbered list from the given strings. Each string represents an independent entry on the list. * Strings that are longer than the given width will be split above several lines. */*from w w w . ja v a2 s . co m*/ * @param listChar the character that will be displayed as bullet point before each entry * @param maxWidth the maximal width of each entry * @param entries the list's entries * @return the list */ public static String toList(char listChar, int maxWidth, List<String> entries) { StrBuilder ret = new StrBuilder(); String listPrefix = listChar + " "; Splitter splitter = Splitter.on(' ').trimResults().omitEmptyStrings(); for (String entry : entries) { if (!ret.isEmpty()) { ret.appendNewLine(); // reset colors from the previous entry ret.append(ChatColor.RESET); } List<String> entryParts = new LinkedList<String>(); entryParts.add(listPrefix); Iterables.addAll(entryParts, splitter.split(entry)); ret.append(wrappedJoin(entryParts, " ", maxWidth)); } return ret.toString(); }
From source file:eu.esdihumboldt.hale.io.gml.geometry.GMLGeometryUtil.java
/** * Parse coordinates from a GML CoordinatesType instance. * /* w w w . j a va2 s .c om*/ * @param coordinates the coordinates instance * @return the coordinates or <code>null</code> if the instances contains no * coordinates * @throws ParseException if parsing the coordinates fails */ public static Coordinate[] parseCoordinates(Instance coordinates) throws ParseException { // XXX should the type be checked to match CoordinatesType? Object value = coordinates.getValue(); if (value != null) { try { String coordinatesString = ConversionUtil.getAs(value, String.class); if (coordinatesString.isEmpty()) { return null; } // determine symbols String decimal = getCoordinatesDecimal(coordinates); String cs = getCoordinateSeparator(coordinates); String ts = getTupleSeparator(coordinates); Splitter coordinateSplitter = Splitter.on(cs).trimResults(); Splitter tupleSplitter = Splitter.on(ts).trimResults(); NumberFormat format = NumberFormat.getInstance(Locale.US); if (format instanceof DecimalFormat) { DecimalFormat decFormat = ((DecimalFormat) format); DecimalFormatSymbols symbols = decFormat.getDecimalFormatSymbols(); symbols.setDecimalSeparator(decimal.charAt(0)); decFormat.setDecimalFormatSymbols(symbols); } List<Coordinate> coordList = new ArrayList<Coordinate>(); // split into tuples Iterable<String> tuples = tupleSplitter.split(coordinatesString.trim()); for (String tuple : tuples) { Coordinate coord = parseTuple(tuple, coordinateSplitter, format); if (coord != null) { coordList.add(coord); } } return coordList.toArray(new Coordinate[coordList.size()]); } catch (ConversionException e) { log.error("Error parsing geometry coordinates", e); } } return null; }
From source file:org.dcache.nfs.ExportPathCreator.java
public void init() throws IOException { Inode root = vfs.getRootInode();/*from ww w . jav a 2 s . com*/ 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); } } } }