mug

Disclaimer: This is not an official Google product.

Mug

A small Java 8+ utilities library (javadoc), widely used in Google’s internal Java codebase, with 0 deps (Proto, BigQuery, Guava addons are in separate artifacts).

Highlights

More tools - [`Iteration`](https://github.com/google/mug/wiki/Iteration-Explained) - implement lazy stream with recursive code - [`BinarySearch`](./mug-guava/src/main/java/com/google/mu/collect/README.md) - solve LeetCode binary search problems → `BinarySearch.inSortedArrayWithTolerance(doubleArray, 0.0001).find(target)` - [`StructuredConcurrency`](/mug/mug/src/main/java/com/google/mu/util/concurrent/) - simple structured concurrency on virtual threads → `concurrently(() -> fetchArm(), () -> fetchLeg(), (arm, leg) -> makeRobot(arm, leg))` - [`MoreStreams`](https://google.github.io/mug/apidocs/com/google/mu/util/stream/MoreStreams.html) → `whileNotNull(queue::poll).filter(...).map(...)` - [`Optionals`](https://google.github.io/mug/apidocs/com/google/mu/util/Optionals.html) → `return optionally(obj.hasFoo(), obj::getFoo);` - [`Parser Combinator`](https://google.github.io/mug/apidocs/com/google/common/labs/parse/Parser.html) → `zeroOrMore(noneOf("\\'")).immediatelyBetween("'", "'").parse(input);`
Installation ##### Maven Add the following to pom.xml: ``` com.google.mug mug 9.3 ``` Add `mug-errorprone` to your annotationProcessorPaths: ``` maven-compiler-plugin com.google.errorprone error_prone_core 2.23.0 com.google.mug mug-errorprone 9.3 ``` SafeSql ([javadoc](https://google.github.io/mug/apidocs/com/google/mu/safesql/package-summary.html)): ``` com.google.mug mug-safesql 9.3 ``` Dot Parse Combinators ([javadoc](https://google.github.io/mug/apidocs/com/google/common/labs/parse/package-summary.html)): ``` com.google.mug dot-parse 9.3 ``` Protobuf utils ([javadoc](https://google.github.io/mug/apidocs/com/google/mu/protobuf/util/package-summary.html)): ``` com.google.mug mug-protobuf 9.3 ``` ##### Gradle Add to build.gradle: ``` implementation 'com.google.mug:mug:9.3' implementation 'com.google.mug:mug-safesql:9.3' implementation 'com.google.mug:dot-parse:9.3' implementation 'com.google.mug:mug-guava:9.3' implementation 'com.google.mug:mug-protobuf:9.3' ```