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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:41:26+00:00 2026-06-01T14:41:26+00:00

I am writing a flat file parser that reads token/value pairs using a Scanner.

  • 0

I am writing a flat file parser that reads token/value pairs using a Scanner. The files being read contain the token “class”. The token is later used in a switch statement, and uses the (pre Java 7) valueOf(token) Java idiom to produce an enum value. (I am using Java6 for compatibility with GWT.) As a workaround, I am using uppercase values in the enum, and valueOf(token.toUpperCase()).

public enum ParseTags {
    CODE, CLASS, INSTRUCTOR, HOURS;
}

// . . . 

token = scanner.next();
value = scanner.next();

switch (ParseTags.valueOf(token.toUpperCase())) {
case CODE:
    entry.setCode(value);
    break;
case CLASS:
    entry.setClass(value);
    break;

Because this is being compiled into javascript, I want to avoid the extra “toUpperCase()” operation on each iteration; not sure what performance will be on target platform. Is there a more graceful way to represent reserved words in an enumeration? This would be handled well by Java7’s switch on String, but again, I am confined to Java6sdk.

  • 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-01T14:41:28+00:00Added an answer on June 1, 2026 at 2:41 pm

    What you’re doing right now is the preferred way to do it. I would be extraordinarily shocked if the toUpperCase were a bottleneck.

    That said, I might consider something like

    enum ParseTags {
      CODE {
        public void set(Entry entry, String value) { 
          entry.setCode(value);
        }
      },
      ...;
      public abstract void set(Entry entry, String value);
    }
    

    so you can do

    ParseTags.valueOf(token.toUpperCase()).set(entry, value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The higher-ups in my company were told by good friends that flat files are
When writing my own flat file databases I try and keep the file sizes
I a writing a DSL to generate parsers for bioinformatics flat files. I would
I've been writing output from perl scripts to files for some time using code
Informed options needed about the merits of flat file database. I'm considering using a
I support a legacy Java application that uses flat files (plain text) for persistence.
I am writing a Ruby script that will generate a large flat HTML menu
I am trying to read in a file that only have one column, and
I'm writing an application that creates a Catalog of files, which can be attributed
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the

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.