Skip to main content

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
3 votes
3 answers
133 views

Avoiding numbness with Python Enum

First, the context: I'm working with a student to build a web frontend for a star cluster simulation package called starlab. Typical starlab usage involves ...
tachycline's user avatar
-2 votes
1 answer
402 views

Enum Singleton implementation in Java

I just wanted to implement the enum singleton in java. Here is my implementation where I have tried to create a singleton DataSource instance: ...
Rahul's user avatar
  • 11
8 votes
1 answer
206 views

A global Enum for comparison operators

This approach was born out of wanting to pass a logical expression (E.G. ">=10000") as a parameter to a function. So, I built an Enum and a function to use it to evaluate logical expressions. Is ...
Kaz's user avatar
  • 8,800
9 votes
4 answers
1k views

Flags on steroids

What is so bad about [Flags] enum? It does not support IEnumerable<T> anyhow, so to get one we need to use syntax like (...
Dmitry Nogin's user avatar
  • 6,121
2 votes
1 answer
69 views

Comparing a selected attribute of a color with a given value

I need to call different functions depending on which enum value is used as parameter. it's working as it should do, but I wanted to ask if there's a proper way to do this without lacking a good ...
user avatar
6 votes
2 answers
249 views

Efficiently return a ChatColor

I am working on a plugin for a Minecraft server. In it, I have a function that returns a ChatColor depending on what permission level you are. Whenever I need ...
Spotlight's user avatar
  • 175
15 votes
2 answers
16k views

Extension method to list enum values

I have the following enum extension method: ...
Pete's user avatar
  • 641
5 votes
2 answers
2k views

Enums for the four directions

I have walls that I can spawn. They wll move in one of four directions, up, down, right or left. Now I can set, wether the wall is thin, wide, long or short, but the problem is: Nearly everything I ...
zebleckDAMM's user avatar
4 votes
2 answers
23k views

Parsing from one enum to another

I face a problem I think I am not approaching appropiately. I have two independent enumerators that both will contain the same members, the only difference being the values given. I have to be able ...
Oscar Guillamon's user avatar
0 votes
1 answer
8k views

Remove elements existing in a list built from an enum

The objective of this code is to make the difference inbetween two lists of items, that is knowing which items are missing in the second list in regards to the first one. The first list is built from ...
Oscar Guillamon's user avatar
5 votes
1 answer
1k views

Generic method for obtaining enum items in an ushort object

The idea is to perform a bit-wise scan of an ushort provided to find any and all matches within an enum collection. The code I ...
Oscar Guillamon's user avatar
3 votes
2 answers
250 views

C++-safe way to use using inside headers

I have this C++ 14 code in a project of mine. Enhedron/Util/Enum.h: ...
Simon Bourne's user avatar
8 votes
2 answers
10k views

Yet another lightweight Enum for Python 2.7

I'm trying to develop a lightweight enum for Python 2.7. This question is downstream of the SO question here; for context, a streamlined version of the bulleted addendum to that question is ...
hBy2Py's user avatar
  • 247
8 votes
2 answers
245 views

Checking DnD Traits in an enum

Overall, I'm working on a simulator for a modified DnD 3.5 system. Right now, I'm trying to write an enum class that handles the Classes/Professions, and am ...
BrainFRZ's user avatar
  • 841
6 votes
1 answer
46 views

Module for isotopic masses and abundances

I have written a small module for accessing data on isotope masses and relative abundances. My long term aim is to build tools in Haskell for working with mass spectrometry data. Any comments on how ...
Michael T's user avatar
  • 163
0 votes
2 answers
95 views

Transforming CSS into an encoded representation

I have a java code that is supposed to format the content of a .css file so that I could use the result to make a enum class. ...
Daria M's user avatar
  • 451
7 votes
1 answer
4k views

The Yahtzee Game

I am designing two methods to be used in a Java implementation of Yahtzee. For those not familiar with the game: Players take turns rolling dice and acquire points based on the face up values ...
Robert Blatner's user avatar
4 votes
1 answer
258 views

"EnumSpace" - enum inheritance attempt using namespace macro

EnumSpace This file enables the use of a utility I like to call "EnumSpace". This utility is enums and ...
user2962533's user avatar
1 vote
1 answer
3k views

Bitmask type to perform binary operations

Without any specific implementation details, how would you create a bitmask type that wraps binary arithmetic into something easy to read? Ideally, this would be used with an ...
christo8989's user avatar
4 votes
2 answers
276 views

Handling Enum flags for a copy operation

I've just set up a bit of code to try and make things neater, but all I've really done, is add a whole bunch of nested if statements: ...
Trent's user avatar
  • 261
5 votes
1 answer
246 views

Enumerations for a game character's statistics

I would like to improve my functions and work properly on enums without all of those IFs as well as make it more consistent (for example ...
Gabbek's user avatar
  • 85
8 votes
2 answers
221 views

Efficiently checking if a large enumeration has a consistent order

The scenario is as follows: We have a streamed enumeration that we have to check if it's ordered or not before processing it (about 75-80% of the time it is ordered). We are talking about pretty big ...
InBetween's user avatar
  • 659
10 votes
1 answer
1k views

Attempt at type-safe enums in JavaScript

I wrote this tiny library yesterday. The goal was to implement enums in JavaScript with type-safety. I modeled the implementation similar to enums in Java, since that is what I am most familiar with. ...
Vivin Paliath's user avatar
8 votes
2 answers
6k views

Function to toggle between two values of an enum

I have this code, but it looks a bit verbose: enum MonitoringMode { Seek, Destroy } ...
heltonbiker's user avatar
4 votes
1 answer
150 views

Class for modifying stats of units

I am specifically looking for input on naming ModifierCalculator and Modifiers. I would also appreciate input on whether ...
Aeailmuawe's user avatar
2 votes
1 answer
940 views

Sort files by the type of file

I need to sort files by the type of the File. To accomplish the task I first wrote the code below: ...
mak's user avatar
  • 111
23 votes
3 answers
5k views

C++ FlagSet: typesafe usage of enumeration as bitset/bitmask

Below is my attempt at providing a type-safe way to combine enumeration and bitset together. The resulting class is intended to be use as a set of flags, where each flag is a member of the "user-...
Xaqq's user avatar
  • 333
19 votes
1 answer
520 views

Suggesting "safe enum" class for ISO C

There are quite some questions and answers about how to make enum really type-safe and I didn't find a solution that ensures both type safety and valid values. So I ...
Felix Palmen's user avatar
6 votes
2 answers
5k views

EF lookups and enums

I have a lookup table "RequestTypes" that has the following data: ...
Nean Der Thal's user avatar
4 votes
3 answers
556 views

Page Enum with overridden methods for the first and last members

I am managing the changing of views in an Android app using this enum and associated methods. I am particularly interested in the Page enum's use of overriding <...
Derek's user avatar
  • 225
16 votes
2 answers
4k views

Localizing an enum in Java

I am currently using an enum in my Android application to display time periods: Weekly Bi-Weekly Monthly Quarterly Yearly I created the enum like this, because I wanted to know the description, and (...
AdamMc331's user avatar
  • 383
2 votes
1 answer
105 views

Populate the list based on which datacenter code is running on

This is a follow on to : Efficiently detect datacenter based on server hostname and return the full path. I have a library which is running in different datacenters in production. I have three ...
david's user avatar
  • 1,947
5 votes
1 answer
126 views

Efficiently detect datacenter based on server hostname and return the full path

I have a library which is running in different datacenters in production. I have three datacenters in production: DHP, SLP, LTR Depending on which datacenter ...
david's user avatar
  • 1,947
6 votes
3 answers
573 views

Enum Constants for Convert Units

I have a few constants in a game that I'm doing for hobby. I need to store constants for the total size of the a Physical World and the size of the Screen. I can position the world's objects to the ...
alexpfx's user avatar
  • 524
3 votes
3 answers
100 views

Device-dependent image descriptor fields

In a Java class that belongs in a library, I have a field size that indicates size of image. It must be int, but some values are ...
hasanghaforian's user avatar
1 vote
1 answer
1k views

Implementing a date validator using enum

First and second post on the same subject. This is such a great way to learn. Once again I'm open to suggestions. I have implemented almost all of the suggestions from before, which have resulted in ...
Nilzone-'s user avatar
  • 1,426
9 votes
4 answers
3k views

Enumerated rank comparator utility class

A common task I often face is ordering a collection of items according to some predefined model, typically expressed as an ordered list of ranks. For example, credit agencies might rate financial ...
janos's user avatar
  • 112k
4 votes
1 answer
2k views

Enums for measurement units, with possible circular dependency

I have some enums that define measurement information, such as volume, mass, distance etc... They are defined as such: ...
Brandon's user avatar
  • 244
5 votes
2 answers
16k views

Map enum values

I want to map values of a enum to some other values. For instance, here I map Color to Group: ...
Mikhail's user avatar
  • 153
0 votes
3 answers
822 views

Mixing business logic and presentation layer in enum type

Let's assume I have an enum type with currency: ...
radekEm's user avatar
  • 934
6 votes
1 answer
180 views

Classes to manage perks to be added and removed

I am looking for code correctness and design usage as I think I might be over doing it in the class department. There are two things I'm mostly concerned with. The possible redundancy of classes ...
steve's user avatar
  • 169
9 votes
3 answers
11k views

Using enum descriptions to string/text binding

In my WP8 application I need to show a couple of radio buttons to let the user select a value out of an enum. I don't want to hardcode either the value or the text (...
Adarsha's user avatar
  • 298
5 votes
2 answers
4k views

Mapping enum keys to instance values

I am working on a pathfinding program / algorithm, and I have the following class: ...
Raven Dreamer's user avatar
2 votes
2 answers
1k views

Extracting name and value from the enum

I wrote the below enum from which I need to extract the name and its value: ...
david's user avatar
  • 1,947
20 votes
2 answers
3k views

Enum, constants, or other to represent chess pieces

I'm learning C# and I decided to write a chess program to help me practice the concepts I'm learning in my book. I started the Board class tonight, which is going to handle 1) the board state and 2) ...
RedDragonWebDesign's user avatar
3 votes
2 answers
4k views

Enum vs lookup table for temporary and permanent teeth

I'm implementing a solution in Java using Ebean and I'm having some issues choosing between using enums or simply look up tables. I have a table "Tooth". A tooth ...
KirdApe's user avatar
  • 95
14 votes
2 answers
5k views

Let's play some Swift Poker

Before you can do any sort of card game, you must first write some code to define your deck of cards. One thing I've noticed in looking at some of Apple's Swift interfaces is that they very much so ...
nhgrif's user avatar
  • 25.3k
2 votes
1 answer
3k views

Enum list to STL container

Can someone improve upon this function of mine? EnumToSTLContainer is supposed to make a copy of any STL container whose elements are from a specified ...
prestokeys's user avatar
  • 1,391
6 votes
1 answer
176 views

Supporting Enum in EF 5 with .Net 4.0

I'm currently working through Getting Started with EF5 using MVC 4 in Visual Studio 2010 (.NET 4.0) to learn about how to use ASP.NET and Entity Framework. During the beginning of the tutorial I ran ...
John Odom's user avatar
  • 267
10 votes
2 answers
6k views

Too much fun with EnumMap-related features and lambdas?

I have an utility class to handle EnumMap-related features, such as creating/converting between Object -> Enum and ...
h.j.k.'s user avatar
  • 19.2k