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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:21:20+00:00 2026-06-08T21:21:20+00:00

For now, I have a class with fields. @Entity public class Fuel { @Id

  • 0

For now, I have a class with fields.

@Entity
public class Fuel {

    @Id @GeneratedValue
    private Long id;

    private boolean diesel;
    private boolean gasoline;
    private boolean etanhol;
    private boolean cng;
    private boolean electric;

    public Fuel() {
        // this form used by Hibernate
    }

    public List<String> getDeclaredFields() {
        List<String> fieldList = new ArrayList<String>();

        for(Field field : Fuel.class.getDeclaredFields()){
            if(!field.getName().contains("_") && !field.getName().equals("id") && !field.getName().equals("serialVersionUID") ) {
                fieldList.add(field.getName());

            }
            Collections.sort(fieldList);
        }
        return fieldList;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public boolean isDiesel() {
        return diesel;
    }

    public void setDiesel(boolean diesel) {
        this.diesel = diesel;
    }

    public boolean isGasoline() {
        return gasoline;
    }

    public void setGasoline(boolean gasoline) {
        this.gasoline = gasoline;
    }

    public boolean isEtanhol() {
        return etanhol;
    }

    public void setEtanhol(boolean etanhol) {
        this.etanhol = etanhol;
    }

    public boolean isCng() {
        return cng;
    }

    public void setCng(boolean cng) {
        this.cng = cng;
    }

    public boolean isElectric() {
        return electric;
    }

    public void setElectric(boolean electric) {
        this.electric = electric;
    }   

}

I think it makes sense, but when I asked another question (maybe a stupid example since there can only be either automatic or manual gearbox) https://stackoverflow.com/questions/11747644/selectonemenu-from-declared-fields-list-in-pojo , a user recommend me to use enums instead. Like this way:

public enum Fuel {
    DIESEL("diesel"),
    GASOLINE("gasoline"),
    ETANHOL("etanhol"),
    CNG("cng"),
    ELECTRIC("electric");

    private String label;

    private Fuel(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

}

However, since there exists hybrids on the market (like Toyota Prius) the parent class would implement the boolean class at this way:

private Fuel fuel = new Fuel();

and if using enumerated list at this way:

private List<Fuel> fuelList = new ArrayList<Fuel>();

What is the best practice? Keep in mind that I might have 100 different fuels (just for example =). Do not forget that it is an entity and hence persisted in a database.

Thanks in advance =)

  • 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-08T21:21:21+00:00Added an answer on June 8, 2026 at 9:21 pm

    It sounds to me like you want an EnumSet, yes, definitely over a bunch of bool’s.

    This reminds me a lot of the design patterns for flags and I recently posted an SO question on exactly that: Proper design pattern for passing flags to an object

    This supports having 100 different fuel types easily. However it doesn’t support a car using 100 different fuel types simultaneously easily. But that to me sounds perfectly fine – it would be very hard to build such a car and this is perfectly reflected in the programmatic complexity of coding this 🙂 (Unless of course it really was just supporting all corn-based fuels – in which you might prefer a polymorphic pattern.)

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

Sidebar

Related Questions

I have an entity like this: @Entity @XmlRootElement public class Article { @Id @GeneratedValue(strategy
To start I have two entities. User.java @Entity public class User { @Id private
I have mapped class in JPA. : @Entity @Inheritance(strategy = InheritanceType.JOINED) public class User
I have a simple class Role: @Entity @Table (name = ROLE) public class Role
Assume we have following JPA Entities: class Parent { @Id private Long id; }
I have a similar situation like this one @Entity @Indexed public class Place {
If i have the following entity: public class PocoWithDates { public string PocoName {
I have class Fruit with data and logic. Now I need a lot of
I have a class called Trial which has_many results. Now What I want to
I have a class that creates a file. I am now doing integration tests

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.