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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:57:53+00:00 2026-06-18T05:57:53+00:00

I have about 30 handler routines to dispatch when given a routine name, in

  • 0

I have about 30 handler routines to dispatch when given a routine name, in String form.
So in a factory method, a natural way to dispatch routine is using a series of if...else to compare the routine name to fit in the slot. it works, but no doubt it is clumsy and inefficient as the number of routines rises up.

I came up with a fashion using enum and EnumMap: whenever I add a routine, I add an enum instance, and register it in EnumMap(the routine name and the routine class as key and value).

As what I know, when the number of instances is less than 64(the long type length), the EnumMap implementation uses a long as a bit array and use bit offset to do put and get, so it is extremely fast, and I could gain a O(1) performance when I dispatch the routine as long as the number of routine is less than 64(it quite suits for my situation).

However, a limit of EnumMap is that its key type can only be a Enum, instead of String,
and I could not use the routine name(string) to do a quick lookup….

Is there any way to work around this ?
Or if only I could do a reverse lookup using a value for a key 🙂

  • 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-18T05:57:54+00:00Added an answer on June 18, 2026 at 5:57 am

    I would keep it simple and just use a HashMap<String, Handler> until you can prove that this is a serious bottleneck. I’m assuming here that there’s a common superclass or interface that all your handlers extend, so you can just do

    handlers.get(name).handle(...);
    

    EnumMap won’t be any faster if you’re starting from a String key as you first have to use valueOf to get the enum value corresponding to the string, and this is itself implemented as a lookup in a HashMap…

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

Sidebar

Related Questions

I have about 15 text boxes and instead of going to the event handler
I have a question about string in TCL: HANDLE_NAME /group1/team1/RON proc HANDLE_NAME {playerName} {
I have a form load sub routine here and the problem is that the
I have about 40 links which are all handled within jquery but when they
I have read nearly every single post about the activity not found to handle
I have about 50 arrays filled with numbers and I have to report out
I have about 20 grid views that I have to create. All of them
i have about 60 fragments ListFragment , now i use each Listfragment with another
I have about 8 entities that all have a one to one relationship with
i have about 20 possible exception messages that i want thrown when an error

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.