Questions tagged [enum]

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

Filter by
Sorted by
Tagged with
5 votes
4 answers
887 views

Naming a method that gets the next enum value or starts from the beginning if the given value is the last

I'm struggling to find a proper name for a specific method (in code named NameOfExtension), and would also like some feedback about its implementation. I am ...
user avatar
  • 153
-1 votes
2 answers
74 views

Using default implementations to superpower flags enums with C# [closed]

I would like to share this post with the community since at first glance it is very promising. Storing flags in the database is something that I have been interested in doing for a while since it ...
user avatar
  • 199
0 votes
1 answer
25 views

JavaScript Class with a Fixed Set of Instances

I am looking to write a JavaScript class BasicType with five fixed instances INT, FLOAT, <...
user avatar
  • 765
0 votes
0 answers
23 views

Use switch on an enum to navigate to another screen

Basically I have an enum to store my screens to which I can navigate in my Flutter app. ...
user avatar
  • 101
3 votes
2 answers
172 views

Resolving teeth numbering from 3 columns

For a project, I'm using 3 columns to define teeth positions in a database. For these positions, I want to generate numbers according to this link. Currently, I'm using a ...
user avatar
  • 719
1 vote
1 answer
47 views

PartialOrd of Rust Enums based on encapsulated data

I have an Enum the encapsulates numeric primitives (u8, i8, u16, i16, u32, i32, u64, i64, f32, f64) into a common type called "Number". I want to implement a PartialOrd train for the enum ...
user avatar
  • 111
14 votes
4 answers
2k views

Using Python enums to define physical units

I'm using Python's Enum to define the physical units in which a value is expressed. Eventually, I want to add them as an attribute to my ...
user avatar
  • 261
7 votes
1 answer
356 views

Enabling bitset-like behavior for enum classes (C++20)

I want to enable bitmask-like behavior (ie. overloaded operator|, operator& and operator^...
user avatar
4 votes
3 answers
322 views

A method for managing enumerations in VBA

I have for some time been frustrated by the limitations around enumerations in VBA. Googling didn't find anything really simple and comprehensive. So after a bit of head scratching I came up with ...
user avatar
  • 625
1 vote
1 answer
99 views

Generate and Control JMenu Radio Buttons Using An Enum

Put together a RadioMenu class that can use a Enum to generate a Single-Selection Radio Button Menu. My main question is about whether there's a way to remove the ...
user avatar
4 votes
0 answers
136 views

Enum Class in Fortran

I tried to implement something like a C++ enum class in Fortran. That means it should be typesafe and scope bound. (No comparison between integers and enum values ...
user avatar
  • 842
7 votes
2 answers
1k views

Enum union in Python

This is a snippet of code written in Python 3.9 to implement the concept of "enum unions": an enum made up of several sub-enums whose set of members is the union of the sub-enums' members. ...
user avatar
  • 625
6 votes
3 answers
128 views

Efficient implementation of comparison operators for cards in a poker simulation

Just as a learning exercise, I am implementing a poker game simulator. I am purposefully not searching for ready made tutorials showing how to do this, relying mostly on the python docs - that way I ...
user avatar
  • 187
2 votes
1 answer
77 views

Defining a finite set of instances of a class to check against [closed]

I have a Type class that will have many instances. I get the instances from a web service. The Type class has a ...
user avatar
3 votes
0 answers
52 views

I want to clean up this console app calculator (VB.net)

Getting started in VB.net I've written this console calculator based heavily off Nicholas Dingle youtube channel (in case it looks familiar). What I want to do is have a separate sub called ...
user avatar
1 vote
0 answers
64 views

Self Running iterable state machine with Enums in Java

During development I needed to design a state machine with decision which runs to completion and performs state transition without the need to wait for events. So i come up with the following ...
user avatar
2 votes
1 answer
800 views

Fast API path parameters from Enum Class

from enum import Enum from fastapi import FastAPI app = FastAPI() Hi Defined a route and a Enum Class for the same but the Enum Class looks ugly. ...
user avatar
  • 229
5 votes
1 answer
2k views

Compare List to Enum Where Contains Any

I have a List that I want to compare to an Enum. If a.Value is found in the Enum we return <...
user avatar
2 votes
2 answers
105 views

Use case of nesting an enum into a struct

At our office there is this piece of code (the original author isn't employed anymore, so I can't ask him). Does anybody have an idea, what he did there? Is there any advantage of using this struct <...
user avatar
4 votes
1 answer
237 views

Code for sorting items in recyclerView

I'm have recyclerView which is needed for displayed for show list of my audio records. I added the ability to sort my audio records. Please take a look at the code that I use for sorting and tell me ...
user avatar
  • 407
2 votes
1 answer
617 views

C++17 enum macro with to_string operator

I created a simple enum macro that creates a to_string method for the enum. This has been done before, but my version is designed to compile quickly. From what I ...
user avatar
1 vote
1 answer
38 views

Would my implementation of this enum pass?

I have a feature with feature flagging enabled, basis the condition I want to load different pages in my screen, to achieve this I have the following enum: ...
user avatar
  • 261
2 votes
2 answers
104 views

List Filtering Code

I am developing applications for android. In my application, the user can add information about his weight and watch the progress of weight change. I decided to add filtering of the elements according ...
user avatar
  • 407
6 votes
2 answers
340 views

LazyEnum with validation

Motivation In the standard Python library enum, a subclass of Enum would create all its members upon class creation. This can ...
user avatar
3 votes
1 answer
70 views

Use Python Enum to implement residue ring and multiplicative residue group

I have implemented the integer residue ring \$ \mathbb{Z}/m\mathbb{Z} \$ and the integer multiplicative residue group \$ (\mathbb{Z}/m\mathbb{Z})^* \$. Functionalities include: In \$ \mathbb{Z}/m\...
user avatar
2 votes
1 answer
80 views

Enum conversion to Enumeration class with small Business Logic inside

I had old enum, I converted it to Enumeration class and added one method inside (isValid). I am not sure if it is good approach ...
user avatar
  • 121
3 votes
1 answer
154 views

Enum in PowerShell Class

I am playing with learning PowerShell classes, and I have a validation situation that kind of lends itself to Enums, as shown in the first example. With Enum ...
user avatar
1 vote
1 answer
3k views

Macro to generate an enum and an array of strings

Often when I find myself working with magic number enum values and I want to know what they represent, so I create an array of strings in order to print out their label. This macro automates that ...
user avatar
6 votes
2 answers
244 views

Coloring weekdays with enums

My aim is to assign a color to each workday in a week. So if a user enters a day as a str, then I can know which color it should have. Because colors and workdays ...
user avatar
  • 251
4 votes
2 answers
207 views

Better approach on handling unexpected string upon converting it to the enum value

I have Grade enum and there is a static method to convert a string value to the particular enum value. ...
user avatar
  • 143
6 votes
2 answers
212 views

Create a 2 way mapping to allow you to stringify enums or map one enum to another

I've created a class that creates key->value pairs but also value->key pairs - i.e. a reversible hash-map. This is because I want to be able to switch between corresponding members of 2 enums ...
user avatar
  • 1,998
2 votes
1 answer
390 views

Octave classdef enumeration workaround

AFAIK Octave still does not support enumerations, so I've done my best to write a workaround. The question is if there is something missing in code below, or maybe something can be improved? The ...
user avatar
6 votes
2 answers
172 views

Opposite access to enums

Consider I have many enums (Java) that looks somewhat like this: ...
user avatar
  • 63
2 votes
1 answer
90 views

Cookie value to enum

Users can have a Cookie called lang that contains either the value "default=1" (English) or "default=2" (French). This cookie is used to determine their preferred ...
user avatar
4 votes
1 answer
208 views

Java enum-based factory to calculate entry parameters

I want to create a factory to return all Source instances that match given entry parameters- that is, I want to iterate through some Collection of objects and for each entry check boolean method. I ...
user avatar
  • 43
2 votes
1 answer
41 views

Ranges of enum members that dwim

Inspired by this blogpost I decided to try and make it possible to have ranges of enum members that dwim, aka. that contain the actual members and not a stringified ...
user avatar
  • 221
5 votes
0 answers
312 views

Reference enum values in Angular template without aliasing the enum type

Is there a way to improve this code? I'd like to use the enum type PaymentMethoddirectly in the angular template without renaming it to ...
user avatar
2 votes
1 answer
74 views

The most elegant way to locate two enums

I have situation where user has got options to select, and after selected any option will appear next options. For example : 1 - Add car 2 - Add motorcycle. 3 - Print cars 4 - Print motorcycles And ...
user avatar
4 votes
1 answer
4k views

overload c++ enum class operators and enable check value set

I use c++ 11 enum class usually instead of the old enums because many enums can contain the same value but as known they don't have the bitwise operators out of the box so we should define them ...
user avatar
  • 293
6 votes
1 answer
86 views

Distinguish between different types of log items in a dictionary by their key

My logging adapter is using a dictionary for storing data that is passed from middleware to middleware. It is a one-liner: ...
user avatar
  • 43.8k
10 votes
2 answers
1k views

Bouncing map back into its bounds, after user dragged it out

Users like exploring maps, seeing all that is around. However they tend to go too far. To prevent the map from getting lost to the user it bounces back into the set bounds, as defined by a rectangle. ...
user avatar
  • 289
3 votes
0 answers
126 views

Emulating a C++ enum class C++ in C

I am trying to emulate a C++ enum class in C and the code works as I expect. I used this code as indicated on Stack Overflow. ...
user avatar
1 vote
1 answer
74 views

Using enum for singleton implementations to choose way of doing something

I have this service that reads emails from a mailbox as they come and I want to extract its contents in a map structure. For now I am interested only in the actual email (no images or attachments). I ...
user avatar
2 votes
1 answer
60 views

Two ways to implement DND type abilities

I am creating a game in Java that uses the DND model for a lot of its components. I've hit a roadblock when it comes to creating and implementing abilities. I have ...
user avatar
  • 9,466
2 votes
0 answers
39 views

Client wrapper for sending data to a downstream process

I am building a Python client for an alert process engine. The users can use this client to publish and clear the alerts. The client exposes two methods publish and clear to the users. These methods ...
user avatar
10 votes
3 answers
858 views

General purpose replacement for enum with FlagsAttribute

Enums with the FlagsAttribute have the disadvantage that you need to be careful when assigning their values. They are also inconvenient when you would like to allow ...
user avatar
  • 43.8k
5 votes
1 answer
537 views

Enum for handling network request errors in Swift

I'm working on a new API written in Swift 5 and I wanted to play with the new Result. I wanted to know what you guys think about this syntax: ...
user avatar
3 votes
1 answer
79 views

API for multiple printer attributes [closed]

I have network printers which have different attributes (e.g. supported network protocols, languages, status, print modes). ...
user avatar
  • 173
3 votes
1 answer
942 views

Swift function to find a specific set of combinations of 3 digits within a larger integer array

I asked this question on Stack Overflow and was directed here. I'm working on a function that will help me quickly find all the upper structure triads (3-note chord) that I can add to a 4-note 7th ...
user avatar
2 votes
2 answers
1k 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. ...
user avatar
  • 21

1
2 3 4 5