use of com.google.common.base.Splitter in project symja_android_library by axkr.
the class StringMapFunctions method tokenizeAndSort.
/**
* Splits on Whitespace and returns the lexicographically sorted result.
*
* @return a {@link StringColumn}
*/
default StringColumn tokenizeAndSort() {
StringColumn newColumn = StringColumn.create(name() + "[sorted]", this.size());
for (int r = 0; r < size(); r++) {
String value = getString(r);
Splitter splitter = Splitter.on(CharMatcher.whitespace());
splitter = splitter.trimResults();
splitter = splitter.omitEmptyStrings();
List<String> tokens = new ArrayList<>(splitter.splitToList(value));
Collections.sort(tokens);
value = String.join(" ", tokens);
newColumn.set(r, value);
}
return newColumn;
}
use of com.google.common.base.Splitter in project atlas by alibaba.
the class AtlasSymbolIo method exportToJava.
/**
* Exports a symbol table to a java {@code R} class source. This method will create the source
* file and any necessary directories. For example, if the package is {@code a.b} and the class
* name is {@code RR}, this method will generate a file called {@code RR.java} in directory
* {@code directory/a/b} creating directories {@code a} and {@code b} if necessary.
*
* @param table the table to export
* @param directory the directory where the R source should be generated
* @param finalIds should the generated IDs be final?
* @return the generated file
* @throws UncheckedIOException failed to generate the source
*/
@NonNull
public static File exportToJava(@NonNull SymbolTable table, @NonNull File directory, boolean finalIds) {
Preconditions.checkArgument(directory.isDirectory());
/*
* Build the path to the class file, creating any needed directories.
*/
Splitter splitter = Splitter.on('.');
Iterable<String> directories = splitter.split(table.getTablePackage());
File file = directory;
for (String d : directories) {
file = new File(file, d);
}
FileUtils.mkdirs(file);
file = new File(file, SdkConstants.R_CLASS + SdkConstants.DOT_JAVA);
String idModifiers = finalIds ? "public static final" : "public static";
try (PrintWriter pw = new PrintWriter(new BufferedOutputStream(Files.newOutputStream(file.toPath())))) {
pw.println("/* AUTO-GENERATED FILE. DO NOT MODIFY.");
pw.println(" *");
pw.println(" * This class was automatically generated by the");
pw.println(" * gradle plugin from the resource data it found. It");
pw.println(" * should not be modified by hand.");
pw.println(" */");
if (!table.getTablePackage().isEmpty()) {
pw.print("package ");
pw.print(table.getTablePackage());
pw.print(';');
pw.println();
}
pw.println();
pw.println("public final class R {");
final String typeName = SymbolJavaType.INT.getTypeName();
// loop on the resource types so that the order is always the same
for (ResourceType resType : ResourceType.values()) {
List<Symbol> symbols = getSymbolByResourceType(table, resType);
if (symbols.isEmpty()) {
continue;
}
pw.print(" public static final class ");
pw.print(resType.getName());
pw.print(" {");
pw.println();
for (Symbol s : symbols) {
final String name = s.getName();
pw.print(" ");
pw.print(idModifiers);
pw.print(' ');
pw.print(s.getJavaType().getTypeName());
pw.print(' ');
pw.print(name);
pw.print(" = ");
pw.print(s.getValue());
pw.print(';');
pw.println();
// listed in the children list.
if (s.getJavaType() == SymbolJavaType.INT_LIST) {
Preconditions.checkArgument(s.getResourceType() == ResourceType.STYLEABLE, "Only resource type 'styleable'" + " is allowed to have java type 'int[]'");
List<String> children = s.getChildren();
for (int i = 0; i < children.size(); ++i) {
pw.print(" ");
pw.print(idModifiers);
pw.print(' ');
pw.print(typeName);
pw.print(' ');
pw.print(name);
pw.print('_');
pw.print(SymbolUtils.canonicalizeValueResourceName(children.get(i)));
pw.print(" = ");
pw.print(i);
pw.print(';');
pw.println();
}
}
}
pw.print(" }");
pw.println();
}
pw.print('}');
pw.println();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return file;
}
use of com.google.common.base.Splitter in project guava by google.
the class FilesSimplifyPathTest method doExtensiveTest.
private void doExtensiveTest(String resourceName) throws IOException {
Splitter splitter = Splitter.on(CharMatcher.whitespace());
URL url = getClass().getResource(resourceName);
for (String line : Resources.readLines(url, UTF_8)) {
Iterator<String> iterator = splitter.split(line).iterator();
String input = iterator.next();
String expectedOutput = iterator.next();
assertFalse(iterator.hasNext());
assertEquals(expectedOutput, simplifyPath(input));
}
}
use of com.google.common.base.Splitter in project grpc-java by grpc.
the class XdsClient method canonifyResourceName.
static String canonifyResourceName(String resourceName) {
checkNotNull(resourceName, "resourceName");
if (!resourceName.startsWith(XDSTP_SCHEME)) {
return resourceName;
}
URI uri = URI.create(resourceName);
String rawQuery = uri.getRawQuery();
Splitter ampSplitter = Splitter.on('&').omitEmptyStrings();
if (rawQuery == null) {
return resourceName;
}
List<String> queries = ampSplitter.splitToList(rawQuery);
if (queries.size() < 2) {
return resourceName;
}
List<String> canonicalContextParams = new ArrayList<>(queries.size());
for (String query : queries) {
canonicalContextParams.add(query);
}
Collections.sort(canonicalContextParams);
String canonifiedQuery = Joiner.on('&').join(canonicalContextParams);
return resourceName.replace(rawQuery, canonifiedQuery);
}
use of com.google.common.base.Splitter in project zm-mailbox by Zimbra.
the class SmtpConnection method readHelloReplies.
/**
* Reads replies to {@code EHLO} or {@code HELO}.
* <p>
* Returns the reply code. Handles multiple {@code 250} responses.
*
* @param command the command name
* @param firstReply the first reply line returned from sending {@code EHLO} or {@code HELO}
*/
private int readHelloReplies(String command, Reply firstReply) throws IOException {
Reply reply = firstReply;
int line = 1;
serverExtensions.clear();
serverAuthMechanisms.clear();
while (true) {
if (reply.text == null) {
throw new CommandFailedException(command, "Invalid server response at line " + line + ": " + reply);
}
if (reply.code != 250) {
return reply.code;
}
if (line > 1) {
// Parse server extensions.
Matcher matcher = PAT_EXTENSION.matcher(reply.text);
if (matcher.matches()) {
String extName = matcher.group(1).toUpperCase();
serverExtensions.add(extName);
if (extName.equals(AUTH)) {
// Parse auth mechanisms.
Splitter splitter = Splitter.on(CharMatcher.whitespace()).trimResults().omitEmptyStrings();
for (String mechanism : splitter.split(matcher.group(2))) {
serverAuthMechanisms.add(mechanism.toUpperCase());
}
}
}
}
if (reply.last) {
// Last 250 response.
mailIn.trace();
return 250;
} else {
// Multiple response lines.
reply = Reply.parse(mailIn.readLine());
}
line++;
}
}
Aggregations