https://github.com/google/mug
A small Java 8 library (string manipulation, BiStream, Structured Concurrency, SQL Templates)
https://github.com/google/mug
sql-injection-proof sql-template stream-api streams string-manipulation structured-concurrency
Last synced: 29 days ago
JSON representation
A small Java 8 library (string manipulation, BiStream, Structured Concurrency, SQL Templates)
- Host: GitHub
- URL: https://github.com/google/mug
- Owner: google
- License: apache-2.0
- Created: 2017-02-14T17:01:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-12-29T06:34:40.000Z (about 2 months ago)
- Last Synced: 2026-01-01T02:58:14.196Z (about 1 month ago)
- Topics: sql-injection-proof, sql-template, stream-api, streams, string-manipulation, structured-concurrency
- Language: Java
- Homepage:
- Size: 86 MB
- Stars: 455
- Watchers: 12
- Forks: 78
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
Disclaimer: This is not an official Google product.
# Mug ()
A small Java 8+ string processing and streams library ([javadoc](http://google.github.io/mug/apidocs/index.html)), widely used in Google's internal Java codebase, with **0 deps** (Proto, BigQuery, Guava addons are in separate artifacts). 
## Highlights
- ✅ [`Substring`](https://github.com/google/mug/wiki/Substring-Explained) – composable substring extraction & manipulation
→ `Substring.between("(", ")").from("call(foo)") → "foo"`
- ✅ [`StringFormat`](https://github.com/google/mug/wiki/StringFormat-Explained) – compile-time-safe bidirectional parsing/formatting
→ `new StringFormat("/home/{user}/{date}").parse(filePath, (user, date) -> ...)`
- ✅ [`Parser`](https://google.github.io/mug/apidocs/com/google/common/labs/parse/Parser.html) – no more regex
→ `zeroOrMore(noneOf("\\'")).immediatelyBetween("'", "'").parse(input);`
- ✅ [`BiStream`](./mug/src/main/java/com/google/mu/util/stream/README.md) – streams `Map` and pair-wise collections
→ `BiStream.zip(keys, values).toMap()`
- ✅ [`SafeSql`](./mug-safesql/src/main/java/com/google/mu/safesql/README.md) – _library-enforced_ **safe**, **composable** SQL template
→ ```SafeSql.of("select id, `{col}` from Users where id = {id}", col, id)```
More tools
- [`DateTimeFormats`](./mug/src/main/java/com/google/mu/time/README.md) – parse datetimes by example
→ `DateTimeFormatter format = formatOf("2024-03-14 10:00:00.123 America/New_York")`
- [`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/src/main/java/com/google/mu/util/concurrent/README.md) - 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);`
Installation
##### Maven
Add the following to pom.xml:
```
com.google.mug
mug
9.7
```
Add `mug-errorprone` to your annotationProcessorPaths:
```
maven-compiler-plugin
com.google.errorprone
error_prone_core
2.23.0
com.google.mug
mug-errorprone
9.7
```
SafeSql ([javadoc](https://google.github.io/mug/apidocs/com/google/mu/safesql/package-summary.html)):
```
com.google.mug
mug-safesql
9.7
```
Dot Parse Combinators ([javadoc](https://google.github.io/mug/apidocs/com/google/common/labs/parse/package-summary.html)):
```
com.google.mug
dot-parse
9.7
```
Protobuf utils ([javadoc](https://google.github.io/mug/apidocs/com/google/mu/protobuf/util/package-summary.html)):
```
com.google.mug
mug-protobuf
9.7
```
##### Gradle
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'
```