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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:38:52+00:00 2026-05-21T12:38:52+00:00

How can I improve this? The relationship is one to one and continuous on

  • 0

How can I improve this?

The relationship is one to one and continuous on [-1,5] so i was thinking of using enum, but I’m not sure how to compare a string value to an enum value.

If there is any better way to do this, please suggest.

Thanks!

private int evaluateWord(String sval) {
    if (sval.equals("program"))
        return 1;
    else if (sval.equals("begin"))
        return 2;
    else if (sval.equals("end"))
        return 3;
    else if (sval.equals("int"))
        return 4;
    else if (sval.equals("if"))
        return 5;
    else
        System.exit(0);
  • 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-21T12:38:52+00:00Added an answer on May 21, 2026 at 12:38 pm

    Have you considered stuffing the mapping into a HashMap once, and then just querying the map?

    For example, something like this:

     private static final Map<String,Integer> m_map = new HashMap<String,Integer>();
     static {
         m_map.put( "program", 1 );
         m_map.put( "begin", 2 );
         m_map.put( "end", 3 );
         m_map.put( "int", 4 );
         m_map.put( "if", 5 );
     }
    
     private int evaluateWord(String sval) {
         Integer value = m_map.get( sval );
         if ( null != value ) {
            return value;
         }
         else {
            System.exit(0);
         }
     }
    

    By the way, it looks as if you’re writing a parser. It can be reasonable to write a parser by hand. Another option to consider, unless you have a good reason to write it by hand, is a parser generator like ANTLR.

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

Sidebar

Related Questions

I have data in a DB that have hierarchical relationship (could be represented as
I would like to write an algorithm that compares one memory block with another
I've created a program that parses data from a file and imports it into
I am trying to create a class with various methods that will need to
I have created a Custom preference which has the following constructor public CoordinatesPreference(Context context,
Are C++ Templates just Macros in disguise? I was reading the above topic, and
I am a beginner in Java and am doing an exercise from a book.
I am trying to have a dialog fly-in from a side of my screen,
Consider the next example: public List<Allergy> GetAllergies(int? ingredientId = null) { var allergies =
We have several latency-sensitive pipeline-style programs that have a measurable performance degredation when run

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.