Disclaimer: This is not an official Google product.
A small Java 8+ string processing and streams library (javadoc), widely used in Google's internal Java codebase, with 0 deps (Proto, BigQuery, Guava addons are in separate artifacts).
- โ
Substringโ composable substring extraction & manipulation
โSubstring.between("(", ")").from("call(foo)") โ "foo" - โ
StringFormatโ compile-time-safe bidirectional parsing/formatting
โnew StringFormat("/home/{user}/{date}").parse(filePath, (user, date) -> ...) - โ
Parserโ replace your regex
โzeroOrMore(noneOf("\\'")).immediatelyBetween("'", "'").parse(input); - โ
BiStreamโ streamsMapand pair-wise collections
โBiStream.zip(keys, values).toMap() - โ
SafeSqlโ library-enforced safe, composable SQL template
โSafeSql.of("select id, `{col}` from Users where id = {id}", col, id)
More tools
DateTimeFormatsโ parse datetimes by example
โDateTimeFormatter format = formatOf("2024-03-14 10:00:00.123 America/New_York")Iteration- implement lazy stream with recursive codeBinarySearch- solve LeetCode binary search problems
โBinarySearch.inSortedArrayWithTolerance(doubleArray, 0.0001).find(target)StructuredConcurrency- simple structured concurrency on virtual threads
โconcurrently(() -> fetchArm(), () -> fetchLeg(), (arm, leg) -> makeRobot(arm, leg))MoreStreams
โwhileNotNull(queue::poll).filter(...).map(...)Optionals
โreturn optionally(obj.hasFoo(), obj::getFoo);
Installation
Add the following to pom.xml:
<dependency>
<groupId>com.google.mug</groupId>
<artifactId>mug</artifactId>
<version>9.7</version>
</dependency>
Add mug-errorprone to your annotationProcessorPaths:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.23.0</version>
</path>
<path>
<groupId>com.google.mug</groupId>
<artifactId>mug-errorprone</artifactId>
<version>9.7</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
SafeSql (javadoc):
<dependency>
<groupId>com.google.mug</groupId>
<artifactId>mug-safesql</artifactId>
<version>9.7</version>
</dependency>
Dot Parse Combinators (javadoc):
<dependency>
<groupId>com.google.mug</groupId>
<artifactId>dot-parse</artifactId>
<version>9.7</version>
</dependency>
Protobuf utils (javadoc):
<dependency>
<groupId>com.google.mug</groupId>
<artifactId>mug-protobuf</artifactId>
<version>9.7</version>
</dependency>
Add to build.gradle:
implementation 'com.google.mug:mug:9.7'
implementation 'com.google.mug:mug-safesql:9.7'
implementation 'com.google.mug:dot-parse:9.7'
implementation 'com.google.mug:mug-guava:9.7'
implementation 'com.google.mug:mug-protobuf:9.7'