Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [enum]

A data type consisting of a set of named values called elements, members or enumerators of the type.

0
votes
0answers
26 views

I've got enums on top of enums, and then some more traits for those enums… it's getting unwieldy [on hold]

So I have an enum wrapping an enum, but I have another enum talking about what that enum is. Which makes for a confusing English sentence, so here's an example. I got one enum: ...
0
votes
0answers
17 views

Single chars mapped to enums in Rust

I'm writing a simple program to parse lines read from a file. As I'm new to Rust, I wonder if I'm creating too much boilerplate. A sample line in the file looks like this: ...
2
votes
2answers
60 views

Java Swing Exercise: BMI Calculator

This is my first question here and this is my working Body Mass Index Swing Calculator. Any improvement or recommendation is welcome. ...
5
votes
1answer
243 views

Get elementary values from a flagged enum

I created a little function that returns the elementary values from a flagged enum. By "elementary" I mean the values that are powers of 2, excluding any combined enum values. I was a bit surprised I ...
4
votes
1answer
51 views

Enum class for weight units

I have some enum classes for units, like Weight units (KG and LB). I am translating the code to Qt C++ from Java, and I'm wondering what the best way to do this is as enums cannot have constructors in ...
0
votes
1answer
130 views

Enhanced C# Enumeration / `enum`

I am developing my own kind of Enumeration like SmartEnum but trying to prevent the user to provide a recursive-ish type definition like below: ...
1
vote
1answer
35 views

Playing card class, written using enums

I wrote a card class a while back in this post here: Previous Question I know it has been a long time but I recently came back to the project and wrote it using an enum as suggested in the answer to ...
-1
votes
1answer
51 views

C++ API design - Should I pass enums as method parameters

I have two methods which are GetMinimumSize() and GetMaximumSize(). They return the maximum size of the window, and they take ...
3
votes
3answers
65 views

Simple boolean gate with two TriState inputs

As part of a code review I came across this isDummy(a,b)-Method and the question, whether it is more readable as a conjunction, or a disjunction: Original snippet: ...
2
votes
1answer
76 views

Image pixel-editing class with an enum for colors

I'm creating an image class that can be used by other classes to create visualizations of data. The class doesn't need to be complicated as the classes will be editing the images pixel by pixel. The ...
1
vote
1answer
39 views

Avoiding the use of ordinal() in an already-deployed enum

While reviewing a PR, I found an enum being used like this: ...
-1
votes
1answer
50 views

Adding additional attributes to an Enum object

I have used Enum objects before in PHP as shown here. However, I often find it's a requirement to have further attributes or metadata available on the instances. I came up with the example solution ...
2
votes
1answer
75 views

C++ class for a flag register in a Chip8 emulator

In order to learn C++ I decided to code a Chip8 emulator following a tutorial. When I came across the idea of a flag register and decided it would be fun to implement in order to get familiar with ...
1
vote
1answer
57 views

Using Enum in java to store a fixed set of mutable objects

I already posted this on Stack Overflow, but someone suggested to post it to Code Review instead. I am creating an Android app that draws to the canvas. For this, ...
0
votes
2answers
104 views

Factory method to create two kinds of cars based on an enum

I am implementing the factory method approach. My intention is to know if my approach is correct for factory method. Any modifications to be done to align with the approach? First I am creating an ...
2
votes
1answer
115 views

Manage Game Level with enum

Basically What I have is basket ball App. In which I have Added some levels and difficulties. logic is simply use tupple in enum and I have some methods to update / get current level with new values ...
0
votes
2answers
111 views

Creating an Enum with a Custom Type in Swift 4.x

I was in a code review today and someone said, "Why don't you do an enum on that?" I had started to, but conforming to a bunch of protocols seemed like a gigantic ...
4
votes
1answer
130 views

PHP class that behaves like enums

I'm relatively new to PHP and one of the things I miss from other languages are enums. After looking around for some samples on how can I have somewhat similar to them, I came up with this ...
9
votes
2answers
2k views

Int to Enum Extension Method

As you know, converting an int to an enum is straightforward. Doing it generically with type/range checking isn't. I looked for a reusable example since this seems like a common situation but did not ...
7
votes
3answers
282 views

Viable Flags (Enum) ValueObject

I was answering a question that led down a rabbit hole of creating an EnumValueObject with [Flags] capabilities. I started with ...
3
votes
1answer
207 views

I created a “enum string” container in c++

The reason I created this is because I wanted my string values to be type safe and I wanted to decrease the amount of bad data that has crept into my system due to hard coded values in the past. ...
5
votes
4answers
660 views

Python Constant Class, Different Enum Implementation

So I saw a need for and came up with a class implementation to group constants, which I'm calling a Constant Class. I wondered if there existed other similar implementations or if there is a flaw in ...
2
votes
2answers
327 views

Game Character class with many skills

Im creating a class that has all of my data in and can see it would quickly become messy. I feel that there must be a way of making it neater rather than making a new method each time For example. I ...
5
votes
2answers
416 views

Custom enumeration classes

Lately I've been using a lot of enums in my project and the lack of generic Enum constraint seems to be quite problematic. This combined with few other headaches ...
12
votes
1answer
153 views

Generic framework to handle parameterized commands

I asked this question a while ago, and this was one of the comments: There (mostly) seems to be a one-to-one mapping of a lot of your functions to IRC command verbs. For example, ...
1
vote
2answers
68 views

Advanced nuclides library

[Context] : I'm currently developing a program in nuclear physics and i would like to have a simple access to all nuclides. Technical specifications are : Since informations are static, I want them ...
1
vote
1answer
65 views

Nuclides enum library

I'm currently developing a program in nuclear physics and i would like to have a simple access to all nuclides. Technical specifications are : Since informations are static, I want them to be hard ...
1
vote
2answers
286 views

Simple barista application to calculate the price of a drink based on different ingredients

The scenario is that a customer orders a coffee from a vending machine by selecting a choice from several categories, such as size, flavor, and creamer type. Given their choices, we then have to ...
1
vote
1answer
142 views

Pre Java 8 a lot of Comparators implementation

Looking for critiques on my implementation of a list of countries that offers many ways to sort it in a useful and easy way for a client. The main concern is about the design of the enum that holds ...
2
votes
1answer
441 views

Using enums in a card/deck class [closed]

I recognize that this is a common question area with lots of answers: Here and here for example. Specifically I'm trying to better understand how to use Enums in Python. Suits in a deck of cards ...
2
votes
2answers
196 views

Mixing arbitrary integers and enum values

I'm writing a text adventure editor that identifies various StoryEntity instances by name, among other means, but the name is the primary way for the user or player ...
1
vote
0answers
114 views

Utility for setting Excel column heads

In my workplace, our web application used to show the data in LIST. It also allows their users to download that list's data in Excel format (we are using Apache POI for Excel). Now everytime we need ...
1
vote
0answers
48 views

Map between multiple data sets and magic numbers

Intro I've recently come across a problem when getting metadata from files in explorer. Meta Data can be read off a file using the GetDetailsOf function, which ...
5
votes
0answers
597 views

Implementing an enum field for peewee.Model

I implemented an enum field class EnumField inheriting from peewee.CharField. The reason that I use a character-based field is ...
11
votes
2answers
3k views

Reimplementing Python's enum.auto() for compatibility

In Python >= 3.6 there is an enum.auto() function. The auto() function can be used like this: ...
2
votes
1answer
754 views

Enum synced with Database

Our database has several tables that have a value that can be one of 4 things, so we made these columns instead have an id column with a foreign key to an enum table with an id and a value column to ...
3
votes
1answer
50 views

Class to classify and compare alphanumeric symbols

I need a class to handle sequences of the following Symbols: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. Digits, lowercase and uppercase symbols will be handled differently. I will ...
0
votes
4answers
5k views

Enumeration for days of the week

I want to be able to represent days of the week as Strings and numerical values so I can print out the days of the week and sort them properly (sun-sat instead of sorting them alphabetically). This is ...
3
votes
1answer
464 views

Including ResourceBundle in enum in order to display enum constant name in different languages [closed]

I'm working on spring web application which has to be accessible both in polish and english. So generally, it's all about internationalization. Of course, internationalization is based on getting ...
2
votes
2answers
3k views

Enum with associated value as stored property in Swift extension

I have a service which connects to server using socket and stays connected, I used this enum to manage connection state: ...
2
votes
1answer
2k views

Int-Enum to String and vice a versa in Swift

I have a situation in my client-server app where I have to send my network strength to server and also receive other clients' strength from server. So I created enum as: ...
2
votes
2answers
378 views

Nested switch to return configuration for combination of 3 database types and 4 domains

I am currently doing a code review for a coworker. I have encountered something like this: ...
7
votes
2answers
114 views

Picking weighed enumerable values at random

I have a number of enumerables, and I want to randomly pick one value from one of the enumerables so that each value has a certain weight in the randomisation process. This is simplification of my ...
8
votes
4answers
3k views

Instantiating a C++ class based on an enum value

I have a bit of code duplication and trying to figure a better way to reduce it. I'm looking for any suggestions. If this was in Java I could easily use reflection. The code posted is a basic ...
2
votes
2answers
2k views

Iterate over an Enum subgroup

I'm looking for a way to get a subset of a given enum to avoid repetition and use same enum type while comparing. I found this question Enum subset or subgroup in C# and like the idea of using static ...
6
votes
3answers
3k views

Kotlin: Comparing enums

I am currently converting a project from Java to kotlin and re-writing the code in the process to make the most out of kotlin's capabilities. The project contains a Battle System which uses elements ...
1
vote
0answers
187 views

Input data integrity checking

I am trying to perform integrity checks on input data before the core of my algorithm gets to work by making sure inputs are neither NAN or out of a reasonable set of bounds. I have defined the ...
4
votes
2answers
2k views

Enum usage to restrict class attribute values

I am using enums in python3 for the first time but unsure if I am using them correctly. I want to restrict the 'allowed values' for a class attribute ...
3
votes
1answer
649 views

Change the background color of the console with the help of enum

I've recently learned the concept of enum and method calling with the enum. From what I learned I've done this simple snippet ...
1
vote
2answers
81 views

Performant functional evaluation for enum value

I have a Java enum which represents the side of an order (enum Side {ASK, BID}) and I'm constantly writing code with which I'd like to use the ternary operator, e.g....