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:hmi.worldobjectenvironment.WorldObjectManager.java
/** * Get worldobject with id id. If id is of the form x,y,z returns a new * AbsolutePositionWorldObject representing this global position. *//*from www . j av a 2 s .c o m*/ public WorldObject getWorldObject(String id) { if (worldObjectMap.containsKey(id)) { return worldObjectMap.get(id); } Iterable<String> pos = Splitter.on(',').trimResults().split(id); Iterator<String> iter = pos.iterator(); float worldPos[] = Vec3f.getVec3f(); int i = 0; while (iter.hasNext()) { String val = iter.next(); if (StringUtil.isNumeric(val)) { worldPos[i] = Float.parseFloat(val); } else { return null; } i++; if (i > 3) return null; } if (i == 3) { return new AbsolutePositionWorldObject(worldPos); } return null; }
From source file:google.registry.tools.server.UpdatePremiumListAction.java
@Override protected void savePremiumList() { Optional<PremiumList> existingName = PremiumList.get(name); checkArgument(existingName.isPresent(), "Could not update premium list %s because it doesn't exist.", name); logger.infofmt("Updating premium list for TLD %s", name); logger.infofmt("Got the following input data: %s", inputData); List<String> inputDataPreProcessed = Splitter.on('\n').omitEmptyStrings().splitToList(inputData); PremiumList premiumList = existingName.get().asBuilder().setPremiumListMapFromLines(inputDataPreProcessed) .build();/*from ww w .j a v a2 s .com*/ premiumList.saveAndUpdateEntries(); logger.infofmt("Updated premium list %s with entries %s", premiumList.getName(), premiumList.getPremiumListEntries()); String message = String.format("Saved premium list %s with %d entries.\n", premiumList.getName(), premiumList.getPremiumListEntries().size()); response.setPayload(ImmutableMap.of("status", "success", "message", message)); }
From source file:rs.in.zivanovic.jdepmon.core.VersionComparator.java
@Override public int compare(String o1, String o2) { List<String> comps1 = Splitter.on(CharMatcher.anyOf(SEPARATORS)).splitToList(o1); List<String> comps2 = Splitter.on(CharMatcher.anyOf(SEPARATORS)).splitToList(o2); int res = 0;// www . j a v a 2s.c om int ssize = comps1.size() >= comps2.size() ? comps2.size() : comps1.size(); int i = 0; Comparable comp1, comp2; while (i < ssize) { try { comp1 = Long.parseLong(comps1.get(i)); comp2 = Long.parseLong(comps2.get(i)); } catch (NumberFormatException ex) { comp1 = comps1.get(i).toLowerCase(); comp2 = comps2.get(i).toLowerCase(); } res = comp1.compareTo(comp2); if (res != 0) { break; } i = i + 1; } if (res == 0 && comps1.size() != comps2.size()) { res = comps1.size() > comps2.size() ? -1 : 1; } return res; }
From source file:org.apache.metron.stellar.common.shell.cli.StellarShellOptionsValidator.java
/** * Zookeeper argument should be in the form [HOST|IP]:PORT. * * @param zMulti the zookeeper url fragment *///from www . j a v a 2 s . c o m private static void validateZookeeperOption(String zMulti) throws IllegalArgumentException { for (String z : Splitter.on(",").split(zMulti)) { Matcher matcher = validPortPattern.matcher(z); boolean hasPort = z.contains(":"); if (hasPort && !matcher.matches()) { throw new IllegalArgumentException(String.format("Zookeeper option must have valid port: %s", z)); } if (hasPort && matcher.groupCount() != 2) { throw new IllegalArgumentException( String.format("Zookeeper Option must be in the form of [HOST|IP]:PORT %s", z)); } String name = hasPort ? matcher.group(1) : z; Integer port = hasPort ? Integer.parseInt(matcher.group(2)) : null; if (!hostnameValidator.test(name) && !inetAddressValidator.isValid(name)) { throw new IllegalArgumentException( String.format("Zookeeper Option %s is not a valid host name or ip address %s", name, z)); } if (hasPort && (port == 0 || port > 65535)) { throw new IllegalArgumentException(String.format("Zookeeper Option %s port is not valid", z)); } } }
From source file:org.dcache.macaroons.CaveatValues.java
public static EnumSet<Activity> parseActivityCaveatValue(String value) throws InvalidCaveatException { EnumSet<Activity> activities = EnumSet.noneOf(Activity.class); for (String activity : Splitter.on(',').trimResults().split(value)) { try {//from w ww . j av a 2 s . c om activities.add(Activity.valueOf(activity)); } catch (IllegalArgumentException e) { throw InvalidCaveatException.wrap("Bad activity value", e); } } return activities; }
From source file:org.jclouds.scriptbuilder.domain.AuthorizeRSAPublicKey.java
@Override public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); return new StatementList(ImmutableList.of(exec("{md} ~/.ssh"), appendFile("~/.ssh/authorized_keys", Splitter.on('\n').split(publicKey)), exec("chmod 600 ~/.ssh/authorized_keys"))).render(family); }
From source file:com.b2international.commons.inject.equinox.AbstractGuiceAwareExecutableExtensionFactory.java
@Override public void setInitializationData(final IConfigurationElement config, final String propertyName, final Object data) throws CoreException { if (data instanceof String) { final Iterator<String> configurationStringIterator = Splitter.on(':').limit(2).split((String) data) .iterator();/* w w w . j ava 2 s .c o m*/ clazzName = configurationStringIterator.next(); configurationData = configurationStringIterator.hasNext() ? configurationStringIterator.next() : null; } if (clazzName == null) { throw new IllegalArgumentException("couldn't handle passed data : " + data); } this.config = config; }
From source file:org.jclouds.gogrid.location.GoGridDefaultLocationSupplier.java
@Inject GoGridDefaultLocationSupplier(@Memoized Supplier<Set<? extends Location>> locations, @Named(TEMPLATE) String template) { this.locations = locations; Map<String, String> map = Splitter.on(',').trimResults().withKeyValueSeparator("=").split(template); //TODO: move to real ImplicitLocationSupplier this.defaultDC = checkNotNull(map.get("locationId"), "locationId not in % value: %s", TEMPLATE, template); }
From source file:com.b2international.commons.VersionNumberComparator.java
/** * @throws IllegalArgumentException if either of the arguments are not in the expected format * @see Comparator#compare(Object, Object) *///from ww w . j a v a2 s. c o m @Override public int compare(String version1, String version2) { checkArgument(checkVersionFormat(version1), "Version string format is invalid: " + version1); checkArgument(checkVersionFormat(version2), "Version string format is invalid: " + version2); List<Integer> version1Parts = Lists.transform(ImmutableList.copyOf(Splitter.on('.').split(version1)), new StringToIntegerParserFunction()); List<Integer> version2Parts = Lists.transform(ImmutableList.copyOf(Splitter.on('.').split(version2)), new StringToIntegerParserFunction()); int minLength = Math.min(version1Parts.size(), version2Parts.size()); int maxLength = Math.max(version1Parts.size(), version2Parts.size()); int i = 0; for (; i < minLength; i++) { Integer integer1 = version1Parts.get(i); Integer integer2 = version2Parts.get(i); int compareResult = integer1.compareTo(integer2); if (compareResult != 0) { return compareResult; } } if (minLength != maxLength) { return Ints.compare(version1Parts.size(), version2Parts.size()); } else { return 0; } }