Piet Souris

Saloon Keeper
+ Follow
since Mar 08, 2009
Forum Moderator
Piet Souris currently moderates these forums:
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piet Souris

You could give the Country class a method 'public City getCapital()' that would simplify the code a little.
1 hour ago
Your BiConsumers are the same (did Campbell mention this already?)
So you can do here:
2 hours ago
Note thar you can reduce the typing a little by using the var keyword, and by importing static Collectors.*.
The expression

is a Consumer<Person>, and so, it requires just one parameter. That the action it performs consists of executing a two-parameter BiConsumer doesn't matter.

And you can use andThen like this:

and then do:

Note that the List of hobbies is an Arrays.asList, meaning that you cannot add or remove other hobbies.
4 hours ago
Congrats, it does the job! It is a bit complicated, though. This is what I came up with:

This 'lineSeperator' is a bit problematic for what I have, since it consists of two characters on my Windows machine. But a replace could fix that.
2 days ago
Wow, did I propose a nonsense solution... don't know what I was thinking.
Anyway, a simple loop did the job, no fancy streams, no escapes, no splitting.
2 days ago
hi Dmitry,

welcome to the Ranch and enjoy the stay!

One way is to make a regex of the string "24 apr.(saturday) - " and call it s. Then you can split the whole expression with "expression.split(s.repeat(N))". That repeat method is from java 16, I think
3 days ago
How about creating Durations (see the API of the Duration class) from the input times? You can then simply add them to get total time.
1 week ago
Thanks, guys.

Never heard of that BOM. Learned a thing or two here. And cows to Ron and Carey, who made the thing very clear.
1 week ago
Also possible is to have a running total and a delta that gets added to total in each step. Afte every three steps change the sign of delta.

But hey: this is a periodic function, so the very first thing that comes to mind is a Fourier series.      
1 week ago
But hey: where's the loop?
1 week ago
Coordinate need not be generic at all. For instance: class Coordinate extends Pair<Double, Double>
1 week ago
A Number has the method: doubleValue()
1 week ago
Do you expect things like Coordinate<Float, BigInteger>?  Do you need two generic types?
1 week ago
I like David's switch, if only because it is certainly not the first thing that comes up! I was thinking of using java 11 String.repeat, but the way to get a different string for every repeat is a bit ugly.
2 weeks ago