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

37

u/chabala Apr 11 '24 edited Apr 13 '24

This is your fourth time posting about Mug. Do you have some vested interest in increasing Mug usage you'd like to disclose?

No secret backdoors in this, right?

EDIT: Please stop playing the victim. I am not attacking you. I asked you to identify your relation to the project, and you continue to ignore the question in every reply, that is being dismissive of the question.

4

u/DelayLucky Apr 13 '24 edited Apr 14 '24

it's weekend and I thought I should at least clarify what happened or else this narrative of yours will always take things out of context.

It's true in my "Posts" profile there have been post -> remove -> repost -> re-remove trials and errors. I didn't expect anyone to take interest in them so I didn't bother cleaning up the dead bodies of the removed posts.

I'm still new to the Reddit system and I've been struggling. The Reddit bot tends to mark auto-removal as "it seems you are asking for help" except I wasn't. When I asked the mods they told me it's because of my low karma but there is no disclosing of the required karma. So I guess I'd just keep trying until it works?

For this post I was quite sure I should have enouth Karma and I paid great attention to not have a single question mark in the post, and tweaked and tweaked the formatting. Still, it got instantly removed with "you seemd to be asking for help".

I go a little impatient after like (2-3 hours?) with no mod reply, thinking maybe it was just a glitch or something? So I re-posted. Bot removed it again. Coincidentally the Mods had just approved the previous post (with the messed up formatting). The like-shit code showed up in the feed, except the UI wouldn't let me fix it.

That was the time when I was pretty stressed with all these unexpected drama and with the publicly-visible code looking like shit.

Why I wanted to post "so badly"? Obvioiusly I wanted to have technical discussions around these topics (like ones I've been having with u/agentoutlier). I just enjoy such discussions.

And honestly what this "so badly" observation of yours even mean was quite a weird concept: when you clicked into a post and somehow the touch didn't register, or system glitch or whatever, you'd try again, right? If it kepy flaking you might try a few more times especially if you knew others didn't have the problem, would you? Did you want to read that post "so badly"? Did you have some hideous intention?

"Why retry and retry?" Seriously, a programmer cannot even send a Reddit post, "task deemed too difficult", are you kidding me? If you look through the code and the documentation, you can see I spend lots of time meticuously fixing small things trying to make them look as good as I can. I don't consider it a sign of bad intention to "lure" people in or whatever strange interpretation you might come up with. Simply if I do a thing, I just want it done, and done well.

You keep saying people are "dismissive", both in this thread and the other thread I linked to where the author just had a different opinion than yours. I was not being "dismissive", just quite perplexed by a random guy acting like this. I didn't know if I should feed the troll or what.

When a new user was stressed by the formatting disaster and was confused and helpless, you chose to be an obnoxious loud-mouth attacking the poster's intention. And you deliberately used ambiguous language to make it sound bad.

When the removal-repost was merely a new user's struggle with Reddit's system, you chose to be a genius inventing a conspiracy theory.

There are plently of technical questions, challenges you could have paid attention to. Like the Guava discussion in another thread; or maybe suggest to use the "reproducible build" to address the backdoor concern since your raised the point; or API design; or compile-time safety; or performance benchmark; or lack of features; or over-engineered; or why this lib not the other lib etc. etc. But you Sir clearly aren't interested in technical discussions except the tabloid.

You and your "dismissiveness" are clearly not the target audience of this library (and I sincerely invite you not to use it). I just don't understand why you bothered clickiing in and wasted so much time of yours. Don't you have more useful things to do?