List of usage examples for com.google.common.base Splitter splitToList
@CheckReturnValue
@Beta
public List<String> splitToList(CharSequence sequence)
From source file:org.anarres.dblx.core.model.ModelLoader.java
@Nonnull public Model load() throws IOException { Model model = new Model(modelName); Splitter splitter = Splitter.on(CharMatcher.BREAKING_WHITESPACE); NODES: {/*from w ww . j av a 2 s. c om*/ URL url = Resources.getResource("models/" + modelName + "/nodes.csv"); CharSource source = Resources.asCharSource(url, StandardCharsets.UTF_8); try (Reader in = source.openBufferedStream()) { CSVReader reader = newSVReader(in, '\t', 1); for (String[] line : reader) { String name = line[0]; long x = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[1])); long y = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[2])); long z = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[3])); List<String> tags = splitter.splitToList(line[4]); model.addNode(new Node(name, x, y, z, tags)); } } } BARS: { URL url = Resources.getResource("models/" + modelName + "/bars.csv"); CharSource source = Resources.asCharSource(url, StandardCharsets.UTF_8); try (Reader in = source.openBufferedStream()) { CSVReader reader = newSVReader(in, '\t', 1); for (String[] line : reader) { List<String> tags = splitter.splitToList(line[2]); Bar bar = new Bar(line[0], line[1], tags); model.addEdge(bar); } } } return model; }
From source file:com.facebook.buck.android.exopackage.RealAndroidDevice.java
@VisibleForTesting public static Optional<PackageInfo> parsePathAndPackageInfo(String packageName, String rawOutput) { Iterable<String> lines = Splitter.on(LINE_ENDING).omitEmptyStrings().split(rawOutput); String pmPathPrefix = "package:"; String pmPath = null;/*from w w w. j a v a 2 s .com*/ for (String line : lines) { // Ignore silly linker warnings about non-PIC code on emulators if (!line.startsWith("WARNING: linker: ")) { pmPath = line; break; } } if (pmPath == null || !pmPath.startsWith(pmPathPrefix)) { LOG.warn("unable to locate package path for [" + packageName + "]"); return Optional.empty(); } String packagePrefix = " Package [" + packageName + "] ("; String otherPrefix = " Package ["; boolean sawPackageLine = false; Splitter splitter = Splitter.on('=').limit(2); String codePath = null; String resourcePath = null; String nativeLibPath = null; String versionCode = null; for (String line : lines) { // Just ignore everything until we see the line that says we are in the right package. if (line.startsWith(packagePrefix)) { sawPackageLine = true; continue; } // This should never happen, but if we do see a different package, stop parsing. if (line.startsWith(otherPrefix)) { break; } // Ignore lines before our package. if (!sawPackageLine) { continue; } // Parse key-value pairs. List<String> parts = splitter.splitToList(line.trim()); if (parts.size() != 2) { continue; } switch (parts.get(0)) { case "codePath": codePath = parts.get(1); break; case "resourcePath": resourcePath = parts.get(1); break; case "nativeLibraryPath": nativeLibPath = parts.get(1); break; // Lollipop uses this name. Not sure what's "legacy" about it yet. // Maybe something to do with 64-bit? // Might need to update if people report failures. case "legacyNativeLibraryDir": nativeLibPath = parts.get(1); break; case "versionCode": // Extra split to get rid of the SDK thing. versionCode = parts.get(1).split(" ", 2)[0]; break; default: break; } } if (!sawPackageLine) { return Optional.empty(); } Objects.requireNonNull(codePath, "Could not find codePath"); Objects.requireNonNull(resourcePath, "Could not find resourcePath"); Objects.requireNonNull(nativeLibPath, "Could not find nativeLibraryPath"); Objects.requireNonNull(versionCode, "Could not find versionCode"); if (!codePath.equals(resourcePath)) { throw new IllegalStateException("Code and resource path do not match"); } // Lollipop doesn't give the full path to the apk anymore. Not sure why it's "base.apk". if (!codePath.endsWith(".apk")) { codePath += "/base.apk"; } return Optional.of(new PackageInfo(codePath, nativeLibPath, versionCode)); }
From source file:org.t3as.ner.resource.Configuration.java
/** Constructor. Read in the config file. */ public Configuration(final InputStream config, final boolean tracing) throws IOException, InterruptedException { this.tracing = tracing; final Pattern COLONS = Pattern.compile(":"); final Splitter SPACES = Splitter.on(' ').trimResults().omitEmptyStrings(); final ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); featureMap = new FeatureMap(tracing); try (final BufferedReader br = new BufferedReader(new InputStreamReader(config))) { for (String line; (line = br.readLine()) != null;) { final String s = line.trim(); if (s.startsWith("#")) continue; if (s.trim().isEmpty()) continue; final String[] parts = COLONS.split(s, 2); switch (parts[0]) { case "Feature": final List<String> l = SPACES.limit(4).splitToList(parts[1]); final String featureType = l.get(0); final String entityType = l.get(1); final int weight = Integer.parseInt(l.get(2)); final List<String> resourceNames = SPACES.splitToList(l.get(3)); final Feature f = Feature.generateFeatureByName(featureType, weight, resourceNames); featureMap.addFeature(entityType, f); exec.execute(new FeatureInitialiserRunnable(f)); break; default: throw new IllegalArgumentException("Unexpected config keyword: '" + parts[0] + "'"); }//from w w w .j a va 2s.c o m } } exec.shutdown(); exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); }
From source file:de.tum.in.bluetooth.discovery.BluetoothDeviceDiscovery.java
/** * Used to parse configuration set to discover specified bluetooth enabled * devices// www. jav a2 s. c o m * * @param devices * The Configuration input as Property K-V Format * @return the parsed input as properties */ private Properties loadListOfDevicesToBeDiscovered(final String devices) { final String SEPARATOR = "#"; final String NEW_LINE = "\n"; final Splitter splitter = Splitter.on(SEPARATOR).omitEmptyStrings().trimResults(); final Joiner stringDevicesJoiner = Joiner.on(NEW_LINE).skipNulls(); final Properties properties = new Properties(); final String deviceAsPropertiesFormat = stringDevicesJoiner.join(splitter.splitToList(devices)); if (isNullOrEmpty(deviceAsPropertiesFormat.toString())) { LOGGER.error("No Bluetooth Enabled Device Addess Found"); return properties; } try { properties.load(new StringReader(deviceAsPropertiesFormat)); } catch (final IOException e) { LOGGER.error("Error while parsing list of input bluetooth devices"); } return properties; }
From source file:de.tum.in.bluetooth.discovery.BluetoothDeviceDiscovery.java
/** Used to get all the configurations for the remote bluetooth devices */ private void loadAutoPairingConfiguration(final String deviceList) { if (deviceList == null) { this.m_fleet = null; LOGGER.warn("No device configuration found, ignoring auto-pairing and device filter"); } else {/*from w ww . ja v a 2 s. co m*/ final List<String> devices = Lists.newArrayList(); Device device = null; this.m_fleet = new DeviceList(); final String DEVICE_SPLITTER = "#"; Iterators.addAll(devices, Splitter.on(DEVICE_SPLITTER).split(deviceList).iterator()); for (final String deviceStr : devices) { final String SEPARATOR = ";"; final String NEW_LINE = "\n"; final Splitter splitter = Splitter.on(SEPARATOR).omitEmptyStrings().trimResults(); final Joiner stringDevicesJoiner = Joiner.on(NEW_LINE).skipNulls(); final Properties properties = new Properties(); final String deviceAsPropertiesFormat = stringDevicesJoiner.join(splitter.splitToList(deviceStr)); if (isNullOrEmpty(deviceAsPropertiesFormat.toString())) { LOGGER.error("No Bluetooth Enabled Device Addess Found"); } try { properties.load(new StringReader(deviceAsPropertiesFormat)); } catch (final IOException e) { LOGGER.error("Error while parsing list of input bluetooth devices"); } device = new Device(); device.setId(properties.getProperty("id")); device.setUsername(properties.getProperty("username")); device.setPassword(properties.getProperty("password")); device.setPin(properties.getProperty("pin")); device.setRetry(Boolean.valueOf(properties.getProperty("retry"))); device.setMaxRetry(new BigInteger(properties.getProperty("max-retry"))); this.m_fleet.getDevices().add(device); } } }
From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBConnector.java
private MongoClient client() { mutex.lock();/*from w ww .j a va2 s. c om*/ try { if (__client == null) { final MongoClientOptions options = MongoClientOptions.builder() .readPreference(ReadPreference.nearest()).writeConcern(WriteConcern.ACKNOWLEDGED).build(); final Splitter splitter = on(':').trimResults().omitEmptyStrings().limit(2); final List<ServerAddress> seeds = from(CONFIG_MANAGER.getDbHosts()) .transform(new Function<String, ServerAddress>() { @Override public ServerAddress apply(final String entry) { ServerAddress seed = null; try { final List<String> tokens = splitter.splitToList(entry); switch (tokens.size()) { case 1: seed = new ServerAddress(tokens.get(0), 27017); break; case 2: int port = parseInt(tokens.get(1)); seed = new ServerAddress(tokens.get(0), port); break; default: break; } } catch (Exception e) { LOGGER.error("Invalid host", e); } return seed; } }).filter(notNull()).toList(); // enable/disable authentication (requires MongoDB server to be configured to support authentication) final List<MongoCredential> credentials = newArrayList(); if (!CONFIG_MANAGER.isAnonymousDbAccess()) { credentials.add(createMongoCRCredential(CONFIG_MANAGER.getDbUsername(), CONFIG_MANAGER.getDbName(), CONFIG_MANAGER.getDbPassword().toCharArray())); } __client = new MongoClient(seeds, credentials, options); // check class attributes accessed by reflection try { final Field metadataField = BaseFile.class.getDeclaredField(METADATA_ATTR); checkNotNull(metadataField, "Metadata property (" + METADATA_ATTR + ") not found in file base: " + BaseFile.class.getCanonicalName()); final Class<?> metadataType = metadataField.getType(); checkState(Versionable.class.isAssignableFrom(metadataType), "Metadata does not implements versionable: " + metadataType.getCanonicalName()); checkNotNull(Versionable.class.getDeclaredField(IS_LATEST_VERSION_ATTR), "Version property (" + IS_LATEST_VERSION_ATTR + ") not found in versionable: " + Versionable.class.getCanonicalName()); checkNotNull(metadataType.getDeclaredField(OPEN_ACCESS_LINK_ATTR), "Open access link property (" + OPEN_ACCESS_LINK_ATTR + ") not found in metadata: " + metadataType.getCanonicalName()); checkNotNull(metadataType.getDeclaredField(OPEN_ACCESS_DATE_ATTR), "Open access date property (" + OPEN_ACCESS_DATE_ATTR + ") not found in metadata: " + metadataType.getCanonicalName()); } catch (Exception e) { throw new IllegalStateException( "Object versioning needs a compatible version of the LVL core library, but none is available", e); } } return __client; } finally { mutex.unlock(); } }