Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6345565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:50:49+00:00 2026-05-24T20:50:49+00:00

Never was good at these things. We are using Checkstyle (for Java) to enforce

  • 0

Never was good at these things. We are using Checkstyle (for Java) to enforce good coding practices. One new check we would like to add is to identify when a certain API is used (potentially) incorrectly through the use of a regex check.

Incorrect usage examples:

BigDecimal.valueOf(someDouble).setScale(3);
someBigDecimalObject.setScale(6);

Correct usage examples:

BigDecimal.valueOf(someDouble).setScale(3, RoundingMode.HALF_UP);
someBigDecimalObject.setScale(1, RoundingMode.HALF_DOWN);

So,the regular expression I’m looking for is when “.setScale(” appears in the code that “RoundingMode.” appears somewhere after it. Or to add more clarity, the regular expression should be true when “.setScale(” appears but “RoundingMode.” doesn’t.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:50:50+00:00Added an answer on May 24, 2026 at 8:50 pm

    Off the top of my head:

    (?x: \.setScale \s* \(  (?: (?! \bRoundingMode\b ) [^)] ) * \) )
    

    What you want is to see .setScale(...) where ... doesn’t contain RoundingMode. To explain further (assuming the Regex is being processed by Java):

    (?x: – introduce “whitespace” mode so that you can pad the regex with spaces for readability
    \.setScale \s* \( – look for .setScale with arbitrary spaces then (
    Now the fun really begins: At every position until we encounter the trailing ) check whether the word RoundingMode appears:
    (?: – start a group containing…
    (?! \bRoundingMode\b ) – …a negative look-ahead assertion for the word RoundingMode, that is, the regex will fail to match if “RoundingMode” is detected; and then
    [^)] – match a non ) character
    ) * – repeat the above as often as required until
    \) – the closing “)” is detected.
    ) – Finally, close the (?x: construct.

    Of course, this won’t work if there are nested (...) expressions in the method call but you can’t solve that with a Java Pattern, you’ll need a dodgy Perl regex instead

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've had it of those dozens of editors which never provides simple things like:
A problem I ran into a while back I never found a good solution
I've always been intrigued by Map Routing, but I've never found any good introductory
What's the deal with iPhone's GPS? I never get a good reading when i'm
I've never been able to find a good script or plugin for sql server
Never used a cache like this before. The problem is that I want to
Never sure where to place functions like: String PrettyPhone( String phoneNumber ) // return
I have a large collection of my personal scripts that I would like to
so far I've never dealed with serious DB programming in native languages (I'm using
I've seen a lot of example code written using something like (please forgive how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.