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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:34:34+00:00 2026-05-13T05:34:34+00:00

I tend to use enums to create mini data tables all over my code.

  • 0

I tend to use enums to create mini data tables all over my code. I use this pattern often. Often enough that I thought I’d ask for others opinion. I’m just curious if I’m taking enums too far, or if I should be doing something else instead.

A common example is an enum I’ll use to drive the TableFormat(from glazed lists) in a JXTable(from swingx). But you could do the same with a TableModel and JTable. Here there is an enum value for each column in the table.

public enum Column {
  INDEX("Order",false, Integer.class, 30) ,
  ENVIRONMENTS("Environments", false, String.class, 50) ,
  LOGICALS("Logicals", false, String.class, 100),
  URL("Url", false, String.class, 200),
  SQL("Text", false, String.class, 200),
  SOURCE("Source", false, String.class, 50) ,
  TYPE("Type", false, String.class, 40) ,
  FORMATED("Formated", false, Boolean.class, 30) ,
  ACTIVE("Active", true, Boolean.class, 30);

  private String headerName;
  private boolean isEditable;
  private Class<? extends Object> viewClass;
  private int defaultWidth;

  PlanTableColumn (String headerName, boolean isEditable, Class<? extends Object> viewClass, int defaultWidth) {
    this.headerName = headerName;
    this.isEditable = isEditable;
    this.viewClass = viewClass;
    this.defaultWidth = defaultWidth;
  }

  public String getHeaderName() {
    return headerName;
  }
  public boolean isEditable() {
    return isEditable;
  }
  public Class<? extends Object> getViewClass() {
    return viewClass;
  }
  public int getDefaultWidth() {
    return defaultWidth;
  }
  public static Column fromOrdinal(int position){
    return Column.values()[position];
  }
}

With this enum defined, writing the TableModel or TableFormat is rudimenatary, and in some cases re-usable between unrelated tables. Especially if each enum value provides its own implementation of a getColumnValue(rowData).

This is a small example, as other tables use Column enums that also contain properties for things like; isVisibleByDefault, sortable, maxWidth, draggable, selectable. And I’ll use these enums for far more things just just table column specifications as well.

Here is a larger example from some code that handles objects in an oracle database.

public enum ObjectType {
    //          Display     Oracle          Gets    | Permissions     |
    // Enum     Name        Name            Synonym Execute Select DML  Compiled
    TABLE(      "Table",    "TABLE",        true,   false, true,  true,  false),
    VIEW(       "View",     "VIEW",         true,   false, true,  false, true),
    MATERIALIZED_VIEW("Materialized View", "MATERIALIZED VIEW",
                                        true,   false, true,  false, true),
    PROCEDURE(  "Procedure","PROCEDURE",    true,   true,  false, false, true),
    PACKAGE(    "Package",  "PACKAGE",      false,  false, false, false, true),
    FUNCTION(   "Function", "FUNCTION",     true,   true,  false, false, true),
    TRIGGER(    "Trigger",  "TRIGGER",      false,  false, false, false, true),
    SYNONYM(    "Synonym",  "SYNONYM",      true,   false, true,  true,  false),
    INDEX(      "Index",    "INDEX",        false,  false, false, false, false),
    CONSTRAINT( "Constraint","CONSTRAINT",  false,  false, false, false, false),
    SEQUENCE(   "Sequence", "SEQUENCE",     true,   false, true,  false, false),
    TABLE_PARTITION( "Table Partition", "TABLE PARTITION", false, false, false, false, false);

    private String name;
    private String nameLC;
    private boolean synonym;
    private boolean grantExecute;
    private boolean grantSelect;
    private boolean grantDML;
    private boolean compiled;
    // "oracleName" is what is used in oracle *_objects tables to identify the object type.
    private String oracleName;

    ObjectType(String name, String oracleName, boolean synonym, boolean execute, boolean select, boolean dml, boolean compiled) {
        this.name = name;
        this.oracleName = oracleName;
        this.nameLC = name.toLowerCase();
        this.synonym = synonym;
        this.grantExecute = execute;
        this.grantSelect = select;
        this.grantDML = dml;
        this.compiled = compiled;
    }

    public String getOracleName() {
        return oracleName;
    }
    public String getName() {
        return name;
    }
    public boolean getsSynonym() {
        return synonym;
    }
    public boolean isGrantExecute() {
        return grantExecute;
    }
    public boolean isGrantSelect() {
        return grantSelect;
    }
    public boolean isGrantDML() {
        return grantDML;
    }
    public boolean isCompiled() {
        return compiled;
    }

    public static ObjectType fromName(String string) throws UnknownObjectTypeException {
        String stringLC = string.toLowerCase();

        for ( ObjectType type : ObjectType.values() ) {
            if ( type.nameLC.equals(stringLC) ) {
                return type;
            }
        }

        throw new UnknownObjectTypeException("found no object type with name " + string);
    }

    public static ObjectType fromOracleName(String string) throws UnknownObjectTypeException {
        for ( ObjectType type : ObjectType.values() ) {
            if ( type.getOracleName().equals(string) ) {
                return type;
            }
        }
        throw new UnknownObjectTypeException("found no object type with oracle name " + string);
    }
}

So what do you think? Am I going overboard with the enum properties?

  • 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-13T05:34:34+00:00Added an answer on May 13, 2026 at 5:34 am

    If your code refers to the enum values (by name) you have a good case for using them … and exposing them. The same applies if you need to implement a Column lookup(String) method. Otherwise, they might be a bit heavy-weight.

    But if these things are not exposed in public APIs, it probably doesn’t matter which approach you take.

    (In case you are interested, I take the view that it is OK to leave out the getter and setter method for a private inner class, especially if the fields are declared as final. You could apply that here … if the enum is declared as private inner … to cut out some of the verbiage.)

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

Sidebar

Related Questions

Inside the Rails code, people tend to use the Enumerable#inject method to create hashes,
In new C++ code, I tend to use the C++ iostream library instead of
When debugging web sites that I'm working on, I tend to use Attach to
I was curious about how other people use the this keyword. I tend to
Is there any particular reason to use one over the other? I personally tend
I tend to take the academic approach all too often and adhere to strict
I tend to use the words define, declare and assign interchangeably but this seems
I tend to use If Not IsDBNull(dr(data)) Then myData = dr(data) End If to
I'm on an optimization kick, at the moment. I tend to use multiple tables,
In c++ primer, pg 95 the author says that c++ programmers tend to use

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.