Questions tagged [enumeration]

The process of enumerating values, for example from some collection.

Use for enumeration types.

1894 questions
23
votes
15 answers

How can I eliminate duplicated Enum code?

I have a large number of Enums that implement this interface: /** * Interface for an enumeration, each element of which can be uniquely identified by its code */ public interface CodableEnum { /** * Get the element with a particular…
Dónal
  • 185,044
  • 174
  • 569
  • 824
23
votes
11 answers

How to cast a value from one enum to another in Java?

How can I cast a value from Enum1 to Enum 2 in Java? Here is an example of what I'm trying to do : public enum Enum1 { ONE, TWO, THREE; } public enum Enum2 { FOUR, FIVE, SIX; } So I want to do something like this: Enum2 en2 =…
Android-Droid
  • 14,365
  • 41
  • 114
  • 185
23
votes
1 answer

Get every n-elements of array

How to select every n-elements (e.g. six) of an array using Ruby 1.9+? Example: a = [0, 1, 2, 3, 4, ... , 33] # solution # => [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11], ... ]
akrisanov
  • 3,212
  • 6
  • 33
  • 56
23
votes
3 answers

why does comma(,) not cause to compilation error?

I am writing a code that and suddenly see that "," doesn't cause any compilation error. Why ? What I mean public enum A { B, C, ; // no compilation error } but int a, b, ; // compilation error
user467871
23
votes
3 answers

Why am I getting "Collection was modified; enumeration operation may not execute" when not modifying the enumerated collection?

I have two collections of strings: CollectionA is a StringCollection property of an object stored in the system, while CollectionB is a List generated at runtime. CollectionA needs to be updated to match CollectionB if there are any differences. So…
Grace Note
  • 3,205
  • 4
  • 35
  • 55
22
votes
7 answers

How to enumerate returned rows in SQL?

I was wondering if it would be possible to enumerate returned rows. Not according to any column content but just yielding a sequential integer index. E.g. select ?, count(*) as usercount from users group by age would return something along the…
SilentGhost
  • 307,395
  • 66
  • 306
  • 293
22
votes
5 answers

Possibility of mapping enum values to string type instead of integer

Enum attributes are great and I want to use them. But mapping enum values to integer would make it hard to maintain both code and database. Also my database would be highly coupled with my code which I think I should consider that a bad thing. I…
Eren CAY
  • 686
  • 1
  • 7
  • 17
22
votes
3 answers

How to define enum in as3?

Is there a way to define an enum in AS3 in a way we do it in other languages? I can define constants with defined values like that: private const CONST_1:int = 0; private const CONST_2:int = 1; private const CONST_3:int = 2; and so on. If I want to…
Nava Carmon
  • 4,523
  • 3
  • 40
  • 74
22
votes
3 answers

Get an Enumeration (for the Keys) of a Map (HashMap) in Java?

As far as I understand this, it seems that there is not a direct way of getting an Enumeration directly for the Keys of a HashMap. I can only get a keySet(). From that Set, I can get an Iterator but an Iterator seems to be something different than…
tim
  • 1,119
  • 4
  • 10
  • 13
21
votes
4 answers

C - forward declaration of enums?

Forward declaration of enums in C does not work for me. I searched the internet and Stack Overflow but all of the questions regarding forward declarations of enumerators refer to C++. What do you do for declaring enumerators in C? Put them at the…
loop
  • 3,460
  • 5
  • 34
  • 57
21
votes
6 answers

How to use std::foreach with parameters/modification

I've found myself writing for(int i=0;iDoWhatever(param); a lot, and I'd like to compress this into a foreach statement, but I'm not sure how to get param in there without going super-verbose. I've also got things…
Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
21
votes
5 answers

Is the order in which handles are returned by EnumWindows meaningful?

From a couple of preliminary tests it seems that EnumWindows always returns windows in reverse instantiation order, i.e. most recently instantiated window first. Is that a valid observation? If so, is it true across all versions of Windows? And is…
Oliver Giesen
  • 9,129
  • 6
  • 46
  • 82
21
votes
6 answers

How to convert string result of enum with overridden toString() back to enum?

Given the following java enum: public enum AgeRange { A18TO23 { public String toString() { return "18 - 23"; } }, A24TO29 { public String toString() { return "24 - 29"; …
Kevin
  • 956
  • 3
  • 11
  • 24
21
votes
8 answers

How to write a 'using' statement for enum classes?

In a rock, paper, scissors program that I am writing, I am enumerating the three different moves and declaring them as a class. However, when I try to write a using statement so that I have to avoid using the scope operator, it doesn't seem to work.…
Victor Odouard
  • 1,345
  • 3
  • 15
  • 28
20
votes
1 answer

Is it possible to convert enums to text in PostgreSQL

Is is possible to convert an enum declared in a postgresql schema to text so that I could use like clause for the enum column?
Blip
  • 3,061
  • 5
  • 22
  • 50