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

  • SEARCH
  • Home
  • 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 6383311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:38:02+00:00 2026-05-25T02:38:02+00:00

This is a question more about best practices/design patterns than regexps. In short I

  • 0

This is a question more about best practices/design patterns than regexps.

In short I have 3 values: from, to and the value I want to change. From has to match one of several patterns:

XX.X
>XX.X
>=XX.X
<XX.X
<=XX.X
XX.X-XX.X

Whereas To has to be a decimal number. Depending on what value is given in From I have to check whether a value I want to change satisfies the From condition. For example the user inputs “From: >100.00 To: 150.00” means that every value greater than 100.00 should be changed.

The regexp itself isn’t a problem. The thing is if I match the whole From against one regexp and it passes I still need to check which option was inputted – this will generate at least 5 IFs in my code and every time I want to add another option I will need to add another IF – not cool. Same thing if I were to create 5 Patterns.

Now I have a HashMap which holds a pattern as the key and a ValueMatcher as the value. When a user inputs a From value then I match it in a loop against every key in that map and if it matches then I use the corresponding ValueMatcher to actually check if the value that I want to change satisfies the “From” value.

This aproach on the other hand requires me to have a HashMap with all the possibilities, a ValueMatcher interface and 5 implementations each with only 1 short “matches” methode. I think it sure is better than the IFs, but still looks like an exaggerated solution.

Is there any other way to do it? Or is this how I actually should do it? I really regret that we can’t hold methods in a HashMap/pass them as arguments because then I’d only have 1 class with all the matching methodes and store them in a HashMap.

  • 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-25T02:38:02+00:00Added an answer on May 25, 2026 at 2:38 am

    How about a chain of responsibility.

    Each ValueMatcher object exactly one From/To rule and a reference to the next ValueMatcher in the chain. Each ValueMatcher has a method which examines a candidate and either transaforms it or passes it on to the next in the chain.

    This way adding a new rule is a trivial extension and the controlling code just passes the candidate to the first member of the chain.

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

Sidebar

Related Questions

This is more a question about best practices. I have a view with many
This question is more aimed at good design practices rather than exceptions and stacks.
Colleagues, Preamble. My question is more about best practices. I know one workaround. This
This is more of a best practices question rater than something technical. I'm working
This is kind of a question about best practices. I have a PL/SQL block
EDIT: This question is more about language engineering than C++ itself. I used C++
More than about LINQ to [insert your favorite provider here], this question is about
This question is more UI/Design-ish than hard-core programming is. Background: I've been coding in
This question more falls into the category of best practices, and clean/safe code for
I have a question about best practices regarding how one should approach storing complex

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.