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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:45:03+00:00 2026-06-15T17:45:03+00:00

I am validating the status of a record retrieved from the DB by defining

  • 0

I am validating the status of a record retrieved from the DB by defining an ENUM as below

public enum RecordStatusEnum {
    CREATED("CREATED"),
    INSERTED("INSERTED"),   
    FAILED("FAILED");

private String recordStatusValue;

    RecordStatusEnum (String status) {
        recordStatusValue= status;
    }

    public boolean isSuccess() {
        return (this.equals(CREATED) || this.equals(INSERTED));
    }

}

The method isSuccess() is being used to check the status of the retrieved record ( column status from employee)

if (!(employee.getStatus().isSuccess())) {
            // return error
        }

As per the new requirement, there are a set of conditions introduced say A,B and C; and for them there is a column in the Employee table ‘condition’.

So I need to retrieve the status as well as the condition and see if it belongs to a set which has the combination of both.

For eg : isSuccess() should check if in the following:

CREATED and A 
CREATED and B
INSERTED and C

This must be achieved such that it is easy for me to add a new combination say ‘INSERTED and B’ into the list easily.

What is the best approach for the above problem?

Note : in the actual business scenario there are a whole lot more statuses and checks (eg isFailed() canBeModified() etc) with many different combinations

And any method can be suggested even if it doesn’t use ENUMS. I mentioned ENUMS, because I dont want to deviate much from the existing implementation

  • 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-06-15T17:45:04+00:00Added an answer on June 15, 2026 at 5:45 pm

    There are many possibilities, but you could do like this (I removed the String status, which doesn’t add any value since it’s equal to the name of the enum):

    public enum RecordStatusEnum {
        CREATED(Condition.A, Condition.B),
        INSERTED(Condition.C),   
        FAILED();
    
        private Set<Condition> successConditions;
    
        RecordStatusEnum(Condition... successConditions) {
            this.successConditions = EnumSet.copyOf(Arrays.asList(successConditions));
        }
    
        public boolean isSuccess(Condition c) {
            return successConditions.contains(c);
        }
    }
    

    EDIT:

    Example with two sets of conditions:

    public enum RecordStatusEnum {
        CREATED(EnumSet.of(Condition.A, Condition.B),
                EnumSet.of(Condition.C)),
        INSERTED(EnumSet.of(Condition.C),
                 EnumSet.of(Condition.B),
        FAILED(EnumSet.noneOf(Condition.class),
               EnumSet.noneOf(Condition.class));
    
        private Set<Condition> successConditions;
        private Set<Condition> modificationConditions;
    
        RecordStatusEnum(Set<Condition> successConditions,
                         Set<Condition> modificationConditions) {
            this.successConditions = successConditions;
            this.modificationConditions = modificationConditions;
        }
    
        public boolean isSuccess(Condition c) {
            return successConditions.contains(c);
        }
    
        public boolean canBeModified(Condition c) {
            return modificationConditions.contains(c);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm validating and posting form data via ajax with code below. The problem is,
Validating Primitive Arguments and Complex Data Validating Arguments When writing a method, arguments should
When validating user inputs in an application that is to be run across multiple
When validating a document in the ItemAdding event there are many ways to display
While validating my CSS on http://jigsaw.w3.org/css-validator/ I am getting following errors: 1.Property zoom doesn't
I am validating XML documents against a schema. Some more complex documents/schemas always fail
I'm validating my form, just checking if in the fields where a number should
I am validating a form and when there is any error in the textfield
I am validating value entered in textbox against database and wanted to show right
I'm validating a form using the Validator interface with Spring MVC 3.0.2 using SimpleFormController

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.