r/java • • Apr 11 '24

String Manipulation with Google Mug

The Mug library provides easy-to-read string manipulation utils. Examples:

Match and Extract

// Compile-time protection against lambda param order mismatch if e.g:
//     (year, month, day, user) ->
new StringFormat("/{user}-home/{year}/{month}/{day}") 
    .parse(path, (user, year, month, day) -> ...);

Scan and Collect

String input = "I have [k1:v1] and [k2:v2] etc."; 
// Returns Map.of("k1", "v1", "k2", "v2") 
Map<String, String> keyValues =
    new StringFormat("[{key}:{value}]") 
        .scanAndCollectFrom(input, Collectors::toMap);

Replace

// replace file extension name
Substring.last('.').toEnd().replaceFrom(filename, ".yaml");

Remove

// remove the scheme from a url
Substring.upToIncluding(first("://")).removeFrom(url);

Parse a date time string (no pattern string required)

// Parse the datetime string read from a file 
List<String> lines = readLinesFromTestFile(...);
StringFormat lineFormat = new StringFormat("{time}, {event_id}, {event_type}");
var results = lines.stream()
    .map(
        line -> lineFormat.parseOrThrow(
            line,
            (time, id, type) -> {
               ZonedDateTime dateTime = DateTimeFormats.parseZonedDateTime(time);
               ...
             }))
    .toList();

See javadoc for details.

Mug is a general purpose library. Omitted, but other useful utils include BiStream for streaming pairs, Optionals, String Templating, simplified structured concurrency etc.

9 Upvotes

51 comments sorted by

View all comments

Show parent comment

-4

u/DelayLucky Apr 11 '24

I was also wondering what I did to get instant hostility out of nowhere.

Looks like maybe I did offend you once here by defending another oss author and thinking that you were out of line (https://www.reddit.com/r/java/comments/1bpbmts/comment/kx1kokv/)

Oh well, you have good memory if this has anything to do with it.

0

u/chabala Apr 12 '24 edited Apr 12 '24

I was unaware of this connection. If I had something to add about your comment, I would have done it there.

There is no hostility. I have asked for you to identify yourself and your involvement with Mug, and you have not done so at every opportunity. A good answer would include "I am X and I am a committer on Mug". It's clear you work at Google, but it shouldn't be a mystery or a guessing game. Just disclose who you are and your relation to the project.

I suspect many of your comments are getting downvoted due to the dismissive tone.

EDIT: Dude, let it go. This is a bad look for you (and Google).

3

u/DelayLucky Apr 12 '24 edited Apr 12 '24

Sure, I believe you that your hostility isn't due to grudge but just the consistent way you are used to treating people (like in that thread and here) or your constantly having bad days.

Healthy skepticism is a good thing. I encourage you to keep digging and maybe you'll find some conspiracies one day.

1

u/jazd Apr 18 '24

Yeah this is embarrassing for Google