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 7521219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:11:59+00:00 2026-05-30T02:11:59+00:00

When I try to use enum to store: =, >, <, etc, I have:

  • 0

When I try to use enum to store: “=”, “>”, “<“, etc, I have:

    public static enum DataValueModifier {
    EQUAL("="),
    GREATER_THAN(">"),
    GREATER_EUQAL(">="),
    LESS_THAN("<"),
    LESS_EQUAL("<="),
    APPRROXIMATE("~"),
    NOT_DETERMINED("ND");
    private String value;
    private DataValueModifier(String value) {
        this.value = value;
    }
    public String getValue() {
        return value;
    }
}

How do I use it when I try to compare a string to see if it contains a “=” sign, should I do:

if (dataValue.contains(DataValueModifier.EQUAL.getValue())) {
...
}

I understand using enum is the better practice here, but this just looks silly…
Thanks,

David

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

    First of all, I’d move the “contains” method (or the equivalent of it) to the enum itself by defining an isModifier method.

    public static enum DataValueModifier {
    
        ...
    
        public boolean isModifier( String modifierString ) 
        {
           return modifierString != null && value.equals(modifierString);
        }
    }
    

    Then, your code looks like this instead:

    if (DataValueModifier.EQUAL.isModifier(dataValue)) 
    {
      //...
    }
    

    But, more importantly, why are you using dataValue instead of the enum in the first place? If you are getting command line input or something or parsing a string equation and then need to figure out the expression I guess I understand. But if you have control of the code then you should just start with the enum and you’ll be able to say

    if ( dataValueEnum == DataValueModifier.EQUAL ) {
    {
      //...
    }
    

    I’d also consider adding a static method to the enum that converts a given string to the correct enum value. It’s not quite as efficient, perhaps, but unless you really care about efficiency it will make your code much cleaner. So add this method to your enum:

    public static DataValueModifier toDataValueModifier( String dataValue ) {
        if( EQUAL.isModifier( dataValue ) {
           return EQUAL;
        } else if( GREATER_THAN.isModifier( dataValue ) {
           return GREATER_THAN;
        } else if...
           // Do this for all possible values
        } else {
           return UNKNOWN;
           // Also, add an UNKNOWN to your list of enum values.
        }
    }
    

    The isModifier and the toDataValueModifier methods might add a bit of ugly code to your DataValueModifier enum, but all your other code will look great. You can now do something like this:

    DataValueModifier dataValueEnum = DataValueModifier.toDataValueModifier(dataValue);
    if (dataValueEnum == DataValueModifier.EQUAL) {
       ...
    }
    

    or even

    switch( DataValueModifier.toDataValueModifier(dataValue) ) {
        case EQUAL:
            // ...
            break;
        case GREATER_THAN:
            // ...
            break;
        case GREATER_EQUAL:
            // ...
            break;
        // ... define all the cases you want
        case UNKNOWN:
        default:
             // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to use PHPMailer to send registration, activation. etc mail to users: require(class.phpmailer.php);
I have one class that declares an enumeration type as: public enum HOME_LOAN_TERMS {FIFTEEN_YEAR,
I try to use enum type as a dependency property in my custom control,
I try to use templatetags in django but I have trouble. I defined enumhelper.py
I have a C# file A which defined some public enum and public struct.
I have defined a C# enum as public enum ORDER { ... unknown, partial01,
I have a class Cell: public class Cell { public enum cellState { WATER,
I try to use this code for toggling text on the link: var showText=<span>Open</span>
I try to use the domainpeople.com API and to do I need to use
I try to use doctest from example from http://docs.python.org/library/doctest.html But when I run python

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.