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:io.macgyver.plugin.cloud.aws.AWSServiceFactory.java
public static List<Regions> splitToRegionList(String input) { List<Regions> regionList = Lists.newArrayList(); Splitter.onPattern("(,|\\s|;)").omitEmptyStrings().trimResults().splitToList(Strings.nullToEmpty(input)) .forEach(name -> {/*from ww w . jav a2 s . c om*/ try { regionList.add(Regions.fromName(name)); } catch (RuntimeException e) { LoggerFactory.getLogger(AWSServiceFactory.class).warn("could not configure region: " + name, e); } }); return regionList; }
From source file:com.linkedin.flashback.netty.mapper.NettyHttpResponseMapper.java
public static FullHttpResponse from(RecordedHttpResponse recordedHttpResponse) throws IOException { FullHttpResponse fullHttpResponse;//from w w w. j a v a 2 s . co m HttpResponseStatus status = HttpResponseStatus.valueOf(recordedHttpResponse.getStatus()); if (recordedHttpResponse.hasHttpBody()) { ByteBuf content = wrappedBuffer(createHttpBodyBytes(recordedHttpResponse)); fullHttpResponse = new DefaultFullHttpResponse(HTTP_1_1, status, content); } else { fullHttpResponse = new DefaultFullHttpResponse(HTTP_1_1, status); } for (Map.Entry<String, String> header : recordedHttpResponse.getHeaders().entrySet()) { fullHttpResponse.headers().set(header.getKey(), Splitter.onPattern(",\\s*").split(header.getValue())); } return fullHttpResponse; }
From source file:org.apache.james.transport.matchers.utils.MailAddressCollectionReader.java
public static Set<MailAddress> read(String condition) { Preconditions.checkArgument(!Strings.isNullOrEmpty(condition)); return FluentIterable.from(Splitter.onPattern("(,| |\t)").split(condition)).filter(new Predicate<String>() { @Override/*from ww w. ja v a 2s . co m*/ public boolean apply(String s) { return !Strings.isNullOrEmpty(s); } }).transform(new Function<String, MailAddress>() { @Override public MailAddress apply(String s) { try { return new MailAddress(s); } catch (AddressException e) { throw Throwables.propagate(e); } } }).toSet(); }
From source file:com.bsiag.geneclipsetoc.internal.contexts.ContextUtility.java
public static String toXml(List<Context> contexts) { StringBuilder sb = new StringBuilder(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sb.append(NEW_LINE);/*from w w w . ja v a2 s . c o m*/ sb.append("<?NLS TYPE=\"org.eclipse.help.contexts\"?>"); sb.append(NEW_LINE); sb.append("<contexts>"); if (contexts != null) { for (Context context : contexts) { sb.append(NEW_LINE); sb.append(INDENTATION); sb.append("<context"); appendAttr(sb, "id", context.getId()); appendAttr(sb, "title", context.getTitle()); sb.append(">"); if (context.getDescription() != null && context.getDescription().length() > 0) { sb.append(NEW_LINE); sb.append(INDENTATION); sb.append(INDENTATION); sb.append("<description>"); Splitter splitter = Splitter.onPattern("\r?\n"); boolean needNewLine = false; for (String line : splitter.split(context.getDescription())) { if (needNewLine) { sb.append(NEW_LINE); } sb.append(XmlEscapers.xmlAttributeEscaper().escape(line)); needNewLine = true; } sb.append("</description>"); } if (context.getTopics() != null) { for (Topic topic : context.getTopics()) { sb.append(NEW_LINE); sb.append(INDENTATION); sb.append(INDENTATION); sb.append("<topic"); appendAttr(sb, "label", topic.getLabel()); appendAttr(sb, "href", topic.getHref()); sb.append("/>"); } } sb.append(NEW_LINE); sb.append(INDENTATION); sb.append("</context>"); } } sb.append(NEW_LINE); sb.append("</contexts>"); return sb.toString(); }
From source file:co.cask.tigon.sql.internal.StreamSchemaCodec.java
/** * Generate {@link co.cask.tigon.sql.flowlet.StreamSchema} from serialized Schema String. *//*ww w . j a v a 2 s. c o m*/ public static StreamSchema deserialize(String schemaString) { Iterable<String> fieldArray = Splitter.on(';').trimResults().omitEmptyStrings().split(schemaString); StreamSchema.Builder builder = new StreamSchema.Builder(); for (String field : fieldArray) { Iterable<String> defnArray = Splitter.onPattern("\\s+").trimResults().omitEmptyStrings().split(field); List<String> defnList = Lists.newArrayList(defnArray); //We expect FieldType, FieldName (optional : FieldAttribute) Preconditions.checkArgument(defnList.size() >= 2); GDATFieldType type = GDATFieldType.getGDATFieldType(defnList.get(0).toUpperCase()); String fieldName = defnList.get(1); builder.addField(fieldName, type); } return builder.build(); }
From source file:org.apache.phoenix.expression.util.regex.GuavaSplitter.java
public GuavaSplitter(String patternString) { if (patternString != null) { splitter = Splitter.onPattern(patternString); } else { splitter = null; } }
From source file:io.macgyver.plugin.hipchat.HipChatBotContext.java
public HipChatBotContext(HipChatBot bot, JsonNode n) { super(bot);/*from ww w.j a v a2 s . com*/ this.rawMessage = n; this.client = bot.getHipChatClient(); List<String> tmp = Lists.newArrayList( Splitter.onPattern("\\s").trimResults().omitEmptyStrings().splitToList(getRawMessage())); if (tmp.size() > 0) { command = tmp.get(0); if (command.startsWith("/")) { command = command.substring(1); tmp.remove(0); args = tmp; } else { throw new IllegalArgumentException("not a command: " + n); } } else { throw new IllegalArgumentException("not a command: " + n); } }
From source file:com.metamx.common.parsers.RegexParser.java
public RegexParser(final String pattern, final Optional<String> listDelimiter) { this.pattern = pattern; this.listSplitter = Splitter .onPattern(listDelimiter.isPresent() ? listDelimiter.get() : Parsers.DEFAULT_LIST_DELIMITER); this.valueFunction = new Function<String, Object>() { @Override/*from w w w .j a va2 s. c o m*/ public Object apply(String input) { final List retVal = Lists.newArrayList( Iterables.transform(listSplitter.split(input), ParserUtils.nullEmptyStringFunction)); if (retVal.size() == 1) { return retVal.get(0); } else { return retVal; } } }; this.compiled = Pattern.compile(pattern); }
From source file:org.kegbot.app.util.TimeSeries.java
public static TimeSeries fromString(String s) { Builder b = TimeSeries.newBuilder(0, false); for (String pairString : Splitter.onPattern("\\s+").split(s)) { String[] items = pairString.split(":"); if (items.length != 2) { throw new IllegalArgumentException("Pair did not contain exactly two items."); }//from w w w . ja va 2 s. co m long time; try { time = Long.valueOf(items[0]).longValue(); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error parsing time: " + e, e); } long value; try { value = Long.valueOf(items[1]).longValue(); } catch (NumberFormatException e) { throw new IllegalArgumentException("Error parsing value: " + e, e); } b.add(time, value); } return b.build(); }
From source file:org.apache.druid.java.util.common.parsers.RegexParser.java
public RegexParser(final String pattern, final Optional<String> listDelimiter) { this.pattern = pattern; this.listSplitter = Splitter .onPattern(listDelimiter.isPresent() ? listDelimiter.get() : Parsers.DEFAULT_LIST_DELIMITER); this.valueFunction = new Function<String, Object>() { @Override/*from w w w . j a va2 s. com*/ public Object apply(String input) { final List retVal = StreamSupport.stream(listSplitter.split(input).spliterator(), false) .map(Strings::emptyToNull).collect(Collectors.toList()); if (retVal.size() == 1) { return retVal.get(0); } else { return retVal; } } }; this.compiled = Pattern.compile(pattern); }