Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Justin Musgrove

Greenhorn
+ Follow
since Jun 16, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Justin Musgrove

If you are using java 8 or guava here are a few code snippets to check if a number is within a range:

Guava


Java 8
7 years ago
"you can spend a week figuring out the perfect regex, but then a month later you " - been there done that Freed! BreakIterator deals with text boundaries, here is a solution to your use case:



Output:
Start at position 179 of the string (or at the end if it isn't that long) and work backwards until you hit the end of a word or a period. Chop that segment off and throw it into
your pot, then repeat until there's nothing left. Note that the end of a word can be followed by a space, or by a non-period punctuation mark like a comma, or by the end of the
string. Be careful not to go past the end of the string in the latter case.
7 years ago
I have found guava splitter is much more flexible and easier to read than regular expression. For your use case it would look like this:



Check out more guava splitter examples

Google splitter home page
7 years ago
Hey Jason,

We have a front end development team that started to use dust.js which is a js templating engine for prototypes and demos. It fits right into the fe dev stack/tools, close to logic less, and meshes with json well. A new project was started using java and wanted to reuse the templates that already have been developed so we needed to find a way to render those templates on the server. Writing a light piece of code we converted our java objects to json and then render the dust template in rhino.

I wrote up how you could do it using nashorn which feels like a lot of work but not all that bad.
http://www.leveluplunch.com/blog/2014/06/09/compile-load-render-dustjs-template-java-nashorn/

Hope this helps.
7 years ago