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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:23:21+00:00 2026-05-30T09:23:21+00:00

I’m trying to improve a Java project which uses a lot of large case

  • 0

I’m trying to improve a Java project which uses a lot of large case statements. In cases where the case statement is used, it is used to handle an event which has an attribute associated to it. For example:

public void jumpOverWall(int wallID) {
    switch (wallID) {
            case 0:
            case 1213:
            case 2123:
            case 3123:
            case 4123:
    }
}

The numbers are non sequential and all require a different action to be performed – for example saying “You cannot jump over this wall” or moving the character to a set position. There are very few cases in which the case response follows a set pattern. What I mean by this is that the switch statements do not follow a pattern that would allow for code similar to:

public void jumpOverWall(int wallID) {
    someArray[1213] = 10;
    someArray[3123] = 20;

    if (playerJumpingSkill > someArray[wallID]) {
            // Do something
    } else {
            sendPlayerMessage("You cannot do this!");
    }
}

Therefore, I am wondering the best possible way of handling these ‘events’. The whole idea of an ‘event handler’ style system is something that appeals to me but I am stuck as how to implement it (or a better solution to the problem). There are too many ‘events’ (in my opinion) to have a separate class for each one.

Is there a method / design for hooking events? Would this be applicable / work. I’d be looking to a method of easy hooking such as:

hookEvent(1213, new SomeInterface() {
    boolean eventOK() {
        // Do something
        return true;
    }
}

Then these ‘hooks’ would be checked for and called?

  • 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-30T09:23:22+00:00Added an answer on May 30, 2026 at 9:23 am

    Why not have a separate method for each case? That way, it makes your code more readable.

    public void jumpOverWall(int wallID)
    {
          switch (wallID) 
            {
            case 0:     methodA(wallID); break; // you could of course have a more descriptive name here.
            case 1213:  methodB(wallID); break; 
            case 2123:  methodC(wallID); break;
            case 3123:  methodD(wallID); break;
            case 4123:  methodE(wallID); break;
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.