List of usage examples for com.google.common.base Splitter onPattern
@CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter onPattern(String separatorPattern)
From source file:org.apache.phoenix.expression.function.RegexpSplitFunction.java
private void init() { Expression patternExpression = children.get(1); if (patternExpression instanceof LiteralExpression) { Object patternValue = ((LiteralExpression) patternExpression).getValue(); if (patternValue != null) { initializedSplitter = Splitter.onPattern(patternValue.toString()); }/*from ww w .j ava2 s . c o m*/ } }
From source file:com.mattc.argus2.io.Configs.java
/** * Format a String of either a single line or multiple lines into <br /> * comment format, similar to the Comment Format used in * {@link java.util.Properties}. <br /> * // w w w.j a v a2 s. c o m * @param comment * Unformatted or Formatted Comment Text * @param includeTime * If true, print the current time as a separate comment line. * @return Comment Text formatted properly */ public static String formatComments(String comment, boolean includeTime) { if (includeTime) { comment += String.format("%n%n%s", new DateTime().toString(dtFormatter)); } final Splitter splitter = Splitter.onPattern("\r?\n").trimResults(); final StringBuilder sb = new StringBuilder(); Iterable<String> iterable = splitter.split(comment); iterable = Iterables.transform(iterable, new Function<String, String>() { @Override public String apply(String input) { if (input.startsWith("#")) return input; else if (input.isEmpty()) return "#"; else return "# " + input; } }); for (final String s : iterable) { sb.append(s).append(System.getProperty("line.separator")); } sb.append(System.getProperty("line.separator")); return sb.toString(); }
From source file:org.sonar.db.version.v50.FileSourceDto.java
FileSourceDto(String source, String revisions, String authors, String dates, String utHits, String utConditions, String utCoveredConditions, String itHits, String itConditions, String itCoveredConditions, String overallHits, String overallConditions, String overallCoveredConditions, String duplicationData) { sourceSplitter = Splitter.onPattern("\r?\n|\r").split(source).iterator(); this.revisions = KeyValueFormat.parseIntString(revisions); this.authors = KeyValueFormat.parseIntString(authors); this.dates = KeyValueFormat.parseIntString(dates); this.utHits = KeyValueFormat.parseIntString(utHits); this.utConditions = KeyValueFormat.parseIntString(utConditions); this.utCoveredConditions = KeyValueFormat.parseIntString(utCoveredConditions); this.itHits = KeyValueFormat.parseIntString(itHits); this.itConditions = KeyValueFormat.parseIntString(itConditions); this.itCoveredConditions = KeyValueFormat.parseIntString(itCoveredConditions); this.overallHits = KeyValueFormat.parseIntString(overallHits); this.overallConditions = KeyValueFormat.parseIntString(overallConditions); this.overallCoveredConditions = KeyValueFormat.parseIntString(overallCoveredConditions); this.duplicationGroups = StringUtils.isNotBlank(duplicationData) ? parseDuplicationData(duplicationData) : Collections.<List<Block>>emptyList(); }
From source file:com.google.jimfs.PathType.java
private static Splitter createSplitter(char separator, char... otherSeparators) { if (otherSeparators.length == 0) { return Splitter.on(separator).omitEmptyStrings(); }/*from w w w . j ava2s . com*/ // TODO(cgdecker): When CharMatcher is out of @Beta, us Splitter.on(CharMatcher) StringBuilder patternBuilder = new StringBuilder(); patternBuilder.append("["); appendToRegex(separator, patternBuilder); for (char other : otherSeparators) { appendToRegex(other, patternBuilder); } patternBuilder.append("]"); return Splitter.onPattern(patternBuilder.toString()).omitEmptyStrings(); }
From source file:org.sonar.server.source.DeprecatedSourceDecorator.java
private List<String> splitSourceByLine(String source, String language, @Nullable Integer from, @Nullable Integer to) {//from w ww . ja va 2 s . co m String htmlSource = codeColorizers.toHtml(source, language); List<String> splitSource = newArrayList(Splitter.onPattern("\r?\n|\r").split(htmlSource)); List<String> result = newArrayList(); for (int i = 0; i < splitSource.size(); i++) { int currentLine = i + 1; if (to != null && to < currentLine) { break; } else if (from == null || currentLine >= from) { result.add(splitSource.get(currentLine - 1)); } } return result; }
From source file:com.netflix.config.DynamicListProperty.java
private void setup(String propName, List<T> defaultValue, String delimiterRegex) { setup(propName, defaultValue, Splitter.onPattern(delimiterRegex).omitEmptyStrings().trimResults()); }
From source file:org.thingsboard.server.msa.DockerComposeExecutor.java
public void invokeCompose() { // bail out early if (!CommandLine.executableExists(COMPOSE_EXECUTABLE)) { throw new ContainerLaunchException( "Local Docker Compose not found. Is " + COMPOSE_EXECUTABLE + " on the PATH?"); }//from w ww . jav a 2s. co m final Map<String, String> environment = Maps.newHashMap(env); environment.put(ENV_PROJECT_NAME, identifier); final Stream<String> absoluteDockerComposeFilePaths = composeFiles.stream().map(File::getAbsolutePath) .map(Objects::toString); final String composeFileEnvVariableValue = absoluteDockerComposeFilePaths .collect(joining(File.pathSeparator + "")); log.debug("Set env COMPOSE_FILE={}", composeFileEnvVariableValue); final File pwd = composeFiles.get(0).getAbsoluteFile().getParentFile().getAbsoluteFile(); environment.put(ENV_COMPOSE_FILE, composeFileEnvVariableValue); log.info("Local Docker Compose is running command: {}", cmd); final List<String> command = Splitter.onPattern(" ").omitEmptyStrings() .splitToList(COMPOSE_EXECUTABLE + " " + cmd); try { new ProcessExecutor().command(command).redirectOutput(Slf4jStream.of(log).asInfo()) .redirectError(Slf4jStream.of(log).asError()).environment(environment).directory(pwd) .exitValueNormal().executeNoTimeout(); log.info("Docker Compose has finished running"); } catch (InvalidExitValueException e) { throw new ContainerLaunchException("Local Docker Compose exited abnormally with code " + e.getExitValue() + " whilst running command: " + cmd); } catch (Exception e) { throw new ContainerLaunchException("Error running local Docker Compose command: " + cmd, e); } }
From source file:org.asoem.greyfish.core.utils.EvaluatingMarkovChain.java
public static EvaluatingMarkovChain<String> parse(final String rule, final ExpressionFactory factory) { checkNotNull(rule);/*from w w w.j ava2s . c o m*/ checkNotNull(factory); final ChainBuilder<String> builder = builder(factory); final Splitter splitter = Splitter.onPattern("\r?\n|;").trimResults(); final Iterable<String> lines = splitter.split(rule); for (final String line : lines) { if (line.isEmpty()) { continue; } final Matcher matcher = PATTERN.matcher(line); if (matcher.matches()) { final String state1 = matcher.group(1).trim(); final String state2 = matcher.group(2).trim(); final String p = matcher.group(3).trim(); builder.put(state1, state2, p); } else { throw new IllegalArgumentException("Rule has errors at " + line); } } return builder.build(); }
From source file:org.nmdp.ngs.tools.ExtractExpected.java
@Override public Integer call() throws Exception { BufferedReader reader = null; try {// w w w .j a v a 2s . c om reader = reader(inputHmlFile); Hml hml = HmlReader.read(reader); for (Sample sample : hml.getSample()) { String id = sample.getId(); for (Typing typing : sample.getTyping()) { for (AlleleAssignment alleleAssignment : typing.getAlleleAssignment()) { List<Haploid> HapList = new ArrayList<Haploid>(); for (Object glstring : alleleAssignment.getPropertyAndHaploidAndGenotypeList()) { String classType = glstring.getClass().toString(); String objectType = classType.substring(classType.indexOf("jaxb.") + 5, classType.length()); if (objectType.equals("Haploid") && HaploidBoolean) { Haploid hap = (Haploid) glstring; HapList.add(hap); } else if (objectType.equals("Glstring") && GlstringBoolean) { Glstring gl = (Glstring) glstring; List<String> Alleles = Splitter.onPattern("[+]+") .splitToList(gl.getValue().replaceAll("[\n\r ]", "")); String locus = Alleles.get(0).substring(Alleles.get(0).indexOf("-") - 3, Alleles.get(0).indexOf("*")); int zygosity = (Alleles.get(0).equals(Alleles.get(1))) ? 1 : 2; String ars = (locus.equals("HLA-A")) ? "./tutorial/regions/grch38/hla-a/hla-a.ars.txt" : (locus.equals("HLA-B")) ? "./tutorial/regions/grch38/hla-b/hla-b.ars.txt" : (locus.equals("HLA-C")) ? "./tutorial/regions/grch38/hla-c/hla-a.ars.txt" : (locus.equals("HLA-DRB1")) ? "./tutorial/regions/grch38/hla-drb1/hla-drb1.ars.txt" : (locus.equals("HLA-DQB1")) ? "./tutorial/regions/grch38/hla-dqb1/hla-dqb1.ars.txt" : (locus.equals("HLA-DPB1")) ? "./tutorial/regions/grch38/hla-dpb1/hla-dpb1.ars.txt" : "N/A"; System.out.print(id + ".fastq.contigs.bwa.sorted.bam\t" + locus + "\t" + ars + "\t" + zygosity + "\t" + Alleles.get(0) + "\t" + Alleles.get(1) + "\n"); } } if (HaploidBoolean) { String hlaTyping1 = HapList.get(0).getLocus() + "*" + HapList.get(0).getType(); String hlaTyping2 = HapList.get(1).getLocus() + "*" + HapList.get(1).getType(); String locus = HapList.get(0).getLocus(); if (!HapList.get(0).getLocus().equals(HapList.get(1).getLocus())) { //error } int zygosity = (HapList.get(0).equals(HapList.get(1))) ? 1 : 2; String ars = (locus.equals("HLA-A")) ? "./tutorial/regions/grch38/hla-a/hla-a.ars.txt" : (locus.equals("HLA-B")) ? "./tutorial/regions/grch38/hla-b/hla-b.ars.txt" : (locus.equals("HLA-C")) ? "./tutorial/regions/grch38/hla-c/hla-a.ars.txt" : (locus.equals("HLA-DRB1")) ? "./tutorial/regions/grch38/hla-drb1/hla-drb1.ars.txt" : (locus.equals("HLA-DQB1")) ? "./tutorial/regions/grch38/hla-dqb1/hla-dqb1.ars.txt" : (locus.equals("HLA-DPB1")) ? "./tutorial/regions/grch38/hla-dpb1/hla-dpb1.ars.txt" : "N/A"; System.out.print(id + ".fastq.contigs.bwa.sorted.bam\t" + locus + "\t" + ars + "\t" + zygosity + "\t" + hlaTyping1 + "\t" + hlaTyping2 + "\n"); } } } } return 0; } finally { try { reader.close(); } catch (Exception e) { // ignore } } }
From source file:org.apache.phoenix.expression.function.RegexpSplitFunction.java
private boolean split(Tuple tuple, ImmutableBytesWritable ptr, String sourceStr) { Splitter splitter = initializedSplitter; if (splitter == null) { Expression patternExpression = children.get(1); if (!patternExpression.evaluate(tuple, ptr)) { return false; }//from ww w. j a v a 2 s. co m if (ptr.getLength() == 0) { return true; // ptr is already set to null } String patternStr = (String) PVarchar.INSTANCE.toObject(ptr, patternExpression.getSortOrder()); splitter = Splitter.onPattern(patternStr); } List<String> splitStrings = Lists.newArrayList(splitter.split(sourceStr)); PhoenixArray splitArray = new PhoenixArray(PVarchar.INSTANCE, splitStrings.toArray()); ptr.set(PVarcharArray.INSTANCE.toBytes(splitArray)); return true; }