List of usage examples for com.google.common.base Splitter on
@CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter on(final Pattern separatorPattern)
From source file:ilcc.ccgparser.utils.CCGJNode.java
public CCGJNode(int wId, String lexString) { headId = -1;/* w w w .j a v a2s . co m*/ // (<L (S/S)/NP IN IN In (S_113/S_113)/NP_114>) String wrd, lemma, pos, cpos, feats = ""; ArrayList<String> items = Lists.newArrayList( Splitter.on(CharMatcher.anyOf("<> ")).trimResults().omitEmptyStrings().split(lexString)); String cat = items.get(1); pos = items.get(2); cpos = items.get(3); wrd = items.get(4); lemma = wrd; headWrd = wrd; ccgCat = CCGcat.lexCat(wrd, cat); //System.out.println(ccgCat.getIndCatDeps()); headNode = new SCoNLLNode(wId, wrd, pos, cat); ccgCats = new ArrayList<>(); }
From source file:com.google.javascript.jscomp.deps.PathUtil.java
/** * Removes all ../ and ./ entries from within the given path. If there are extra ..s that move * beyond the first directory given, they are removed. * * Examples:// ww w. j ava 2s. c om * "a/b/../c" results in "a/c" * "./foo/./../bar" results in "bar" * "a/.." results in "" * "a/../../foo" results in "foo" * * @param path The path to remove dots from. * @return The path with all dots collapsed. */ public static String collapseDots(String path) { path = removeExtraneousSlashes(path); // Optimization: Most paths don't contain dots. if (!path.contains(".")) { return path; } List<String> dstFragments = new ArrayList<>(); for (String fragment : Splitter.on('/').split(path)) { if (fragment.equals("..")) { if (!dstFragments.isEmpty()) { dstFragments.remove(dstFragments.size() - 1); } } else if (!fragment.equals(".")) { dstFragments.add(fragment); } } // Special case for Join.join([""]); -> "/" if (dstFragments.size() == 1 && dstFragments.get(0).isEmpty()) { return "/"; } return Joiner.on("/").join(dstFragments); }
From source file:org.apache.metron.performance.sampler.BiasedSampler.java
public static List<Map.Entry<Integer, Integer>> readDistribution(BufferedReader distrFile, boolean quiet) throws IOException { List<Map.Entry<Integer, Integer>> ret = new ArrayList<>(); if (!quiet) { System.out.println("Using biased sampler with the following biases:"); }/* w w w . j a v a 2 s . c o m*/ int sumLeft = 0; int sumRight = 0; for (String line = null; (line = distrFile.readLine()) != null;) { if (line.startsWith("#")) { continue; } Iterable<String> it = Splitter.on(",").split(line.trim()); if (Iterables.size(it) != 2) { throw new IllegalArgumentException( line + " should be a comma separated pair of integers, but was not."); } int left = Integer.parseInt(Iterables.getFirst(it, null)); int right = Integer.parseInt(Iterables.getLast(it, null)); if (left <= 0 || left > 100) { throw new IllegalArgumentException( line + ": " + (left < 0 ? left : right) + " must a positive integer in (0, 100]"); } if (right <= 0 || right > 100) { throw new IllegalArgumentException(line + ": " + right + " must a positive integer in (0, 100]"); } if (!quiet) { System.out.println( "\t" + left + "% of templates will comprise roughly " + right + "% of sample output"); } ret.add(new AbstractMap.SimpleEntry<>(left, right)); sumLeft += left; sumRight += right; } if (sumLeft > 100 || sumRight > 100) { throw new IllegalStateException( "Neither columns must sum to beyond 100. " + "The first column is the % of templates. " + "The second column is the % of the sample that % of template occupies."); } else if (sumLeft < 100 && sumRight < 100) { int left = 100 - sumLeft; int right = 100 - sumRight; if (!quiet) { System.out.println( "\t" + left + "% of templates will comprise roughly " + right + "% of sample output"); } ret.add(new AbstractMap.SimpleEntry<>(left, right)); } return ret; }
From source file:org.jclouds.vcloud.director.v1_5.VCloudDirectorException.java
private static String message(Error error, String from) { Iterable<String> words = Iterables.transform(Splitter.on('_').split(error.getMinorErrorCode()), new Function<String, String>() { @Override//from w w w. jav a2s . c o m public String apply(String input) { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, input); } }); return String.format(MSG_FMT, Joiner.on(' ').join(words), error.getMajorErrorCode(), from, error.getMessage()); }
From source file:io.macgyver.plugin.metrics.RegexMetricFilter.java
public RegexMetricFilter excludes(String s) { Splitter.on(CharMatcher.anyOf(" \n\t\r,;|")).omitEmptyStrings().splitToList(Strings.nullToEmpty(s)) .forEach(it -> {//from w w w . ja va 2 s .c o m exclude(Pattern.compile(it)); }); return this; }
From source file:org.elasticlib.console.command.CommandProvider.java
private static boolean matches(Command command, List<String> argList) { Iterator<String> parts = Splitter.on(' ').split(command.name()).iterator(); Iterator<String> args = argList.iterator(); while (parts.hasNext()) { if (!args.hasNext() || !parts.next().equals(args.next())) { return false; }/*from w w w.j a va 2s .com*/ } return true; }
From source file:org.jclouds.azurecompute.arm.functions.StorageProfileToStorageAccountName.java
@Override public String apply(StorageProfile input) { String storageAccountNameURI = input.osDisk().vhd().uri(); return Iterables.get(Splitter.on(".").split(URI.create(storageAccountNameURI).getHost()), 0); }
From source file:org.opencloudb.server.response.SelectVariables.java
public static void execute(ServerConnection c, String sql) { String subSql = sql.substring(sql.indexOf("SELECT") + 6); List<String> splitVar = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(subSql); splitVar = convert(splitVar);/* w w w . j a v a 2s .c o m*/ int FIELD_COUNT = splitVar.size(); ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT); FieldPacket[] fields = new FieldPacket[FIELD_COUNT]; int i = 0; byte packetId = 0; header.packetId = ++packetId; for (int i1 = 0, splitVarSize = splitVar.size(); i1 < splitVarSize; i1++) { String s = splitVar.get(i1); fields[i] = PacketUtil.getField(s, Fields.FIELD_TYPE_VAR_STRING); fields[i++].packetId = ++packetId; } ByteBuffer buffer = c.allocate(); // write header buffer = header.write(buffer, c, true); // write fields for (FieldPacket field : fields) { buffer = field.write(buffer, c, true); } EOFPacket eof = new EOFPacket(); eof.packetId = ++packetId; // write eof buffer = eof.write(buffer, c, true); // write rows //byte packetId = eof.packetId; RowDataPacket row = new RowDataPacket(FIELD_COUNT); for (int i1 = 0, splitVarSize = splitVar.size(); i1 < splitVarSize; i1++) { String s = splitVar.get(i1); String value = variables.get(s) == null ? "" : variables.get(s); row.add(value.getBytes()); } row.packetId = ++packetId; buffer = row.write(buffer, c, true); // write lastEof EOFPacket lastEof = new EOFPacket(); lastEof.packetId = ++packetId; buffer = lastEof.write(buffer, c, true); // write buffer c.write(buffer); }
From source file:com.vmware.vchs.utils.BillingUtils.java
public static void checkFileSizeWithGCS(BackupResource backupResource) { String backupFileName = Iterables .getLast(Splitter.on("/").trimResults().omitEmptyStrings().split(backupResource.getResourceUri())); int backupFileSize = new GCSClient().getSizeOfFile(backupFileName); assertThat(Math.round(backupFileSize / 1024)).isEqualTo((int) backupResource.getSize()); }
From source file:com.cloudera.crunch.impl.mr.run.CrunchInputs.java
public static Map<Class<? extends InputFormat>, Map<Integer, List<Path>>> getFormatNodeMap(JobContext job) { Map<Class<? extends InputFormat>, Map<Integer, List<Path>>> formatNodeMap = Maps.newHashMap(); Configuration conf = job.getConfiguration(); for (String input : Splitter.on(RECORD_SEP).split(conf.get(RuntimeParameters.MULTI_INPUTS))) { List<String> fields = ImmutableList.copyOf(SPLITTER.split(input)); Class<? extends InputFormat> inputFormatClass; try {//ww w . j a v a2 s. c o m inputFormatClass = (Class<? extends InputFormat>) conf.getClassByName(fields.get(0)); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } if (!formatNodeMap.containsKey(inputFormatClass)) { formatNodeMap.put(inputFormatClass, Maps.<Integer, List<Path>>newHashMap()); } Integer nodeIndex = Integer.valueOf(fields.get(1)); if (!formatNodeMap.get(inputFormatClass).containsKey(nodeIndex)) { formatNodeMap.get(inputFormatClass).put(nodeIndex, Lists.<Path>newLinkedList()); } formatNodeMap.get(inputFormatClass).get(nodeIndex).add(new Path(fields.get(2))); } return formatNodeMap; }