Questions tagged [enumeration]

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

Use for enumeration types.

1894 questions
13
votes
4 answers

Strange "Collection was modified after the enumerator was instantiated" exception

Perhaps someone can point me in the correct direction, because I'm completely stumped on this. I have a function that simply prints out a LinkedList of classes: LinkedList components = new LinkedList(); ... private…
cyberconte
  • 2,371
  • 4
  • 21
  • 27
13
votes
3 answers

Java Enum property best practice

I've seen two approaches to handling enums with properties. Is one better than the other? As a property: public enum SEARCH_ENGINE { GOOGLE("http://www.google.com"), BING("http://www.bing.com"); private final String url; private…
JustinKSU
  • 4,875
  • 2
  • 29
  • 51
13
votes
7 answers

Collection was modified; enumeration operation may not execute - why?

I'm enumerating over a collection that implements IList, and during the enumeration I am modifying the collection. I get the error, "Collection was modified; enumeration operation may not execute." I want to know why this error occurs when…
contactmatt
  • 18,116
  • 40
  • 128
  • 186
13
votes
4 answers

Force Initialization of an enumerated type in Java

I am attempting to find a way to force Java to load/initialize an enumerated type (which is nested within a class that contains a static Map). This is important to me because the enumerated type has a constructor that populates said map, and without…
Ryan Delucchi
  • 7,718
  • 13
  • 48
  • 60
13
votes
3 answers

How to enumerate CFProperyList / CFDictionary keys

I would like to iterate through a CFDictionary (CFPropertyList) and get all values on a specific level. This would be my dictionary / property-list: root A foo 0 bar 0 B foo 10 bar 100 C foo 20 …
Till
  • 27,559
  • 13
  • 88
  • 122
13
votes
7 answers

Delphi 2010 RTTI : Explore Enumerations

Considering such an enumeration : type TTypeOfData = ( [XmlName('ABC')] todABC, [XmlName('DEF')] todDEF, [XmlName('GHI')] todGHI ); Where XmlName is a custom attribute used to define the serialization string for members of this…
ZeDalaye
  • 689
  • 7
  • 17
13
votes
4 answers

How to get the int for enum value in Enumeration

If I had the value : "dog" and the enumeration: public enum Animals { dog = 0 , cat = 1 , rat = 2 } how could I get 0 for the value "dog" from Animals ? EDIT: I am wondering if there is index like acces. More commonn : how can I get the…
mathinvalidnik
  • 1,566
  • 10
  • 35
  • 57
13
votes
1 answer

Mock all instances of a class

I know this is typically a bad practice but in my case it is necessary. I have a case where an Enum holds a class to gain some information. So that Enum creates an instance of that calss in its Constructor. public enum MyEnum { CONSTANT(new…
Zarathustra
  • 2,853
  • 4
  • 33
  • 62
13
votes
3 answers

When and how should I use enumeration classes rather than enums?

A developer at work recently started using a class pattern instead of enums in places where enums would usually fit. Instead, he uses something similar to that below: internal class Suit { public static readonly Suit Hearts = new Suit(); …
13
votes
4 answers

working pattern of yield return

When i have a code block static void Main() { foreach (int i in YieldDemo.SupplyIntegers()) { Console.WriteLine("{0} is consumed by foreach iteration", i); } } class YieldDemo { public static IEnumerable SupplyIntegers() …
user193276
  • 3,931
  • 3
  • 19
  • 14
13
votes
4 answers

WPF How to bind an enum with Description to a ComboBox

How can I bind an enum with Description (DescriptionAttribute) to a ComboBox? I got an enum: public enum ReportTemplate { [Description("Top view")] TopView, [Description("Section view")] SectionView } I tried…
dg90
  • 1,243
  • 3
  • 17
  • 30
13
votes
1 answer

ruby's "any?" and "all?" methods behaviour on Empty Arrays and Hashes

First of all I found two useful articles in documentations about these methods: http://www.ruby-doc.org/core-1.9.3/Enumerable.html http://www.globalnerdy.com/2008/01/29/enumerating-rubys-enumerable-module-part-1-all-and-any/ all?: Passes each…
y4roslav
  • 347
  • 1
  • 3
  • 10
12
votes
6 answers

How do I write a generic Java enum rotator?

How do I make a generic enum rotator? It would be a generic version of next() in this example. public class TestEnum { enum Temperature { hot, cold }; public static void main(String[] args) { Temperature…
H2ONaCl
  • 10,644
  • 14
  • 70
  • 114
12
votes
2 answers

How to extend existing enumerations objects in Scala?

I'm wondering if you can extend already existing enumerations in Scala. For example: object BasicAnimal extends Enumeration{ type BasicAnimal = Value val Cat, Dog = Value } Can this be extended something like this: object…
Henry
  • 175
  • 1
  • 5
12
votes
1 answer

I get ClassCast exception when I enumerate vector with String type parameter, but no exception is there with Integer as type parameter

I was trying my hands on vectors and wrote a simple code to access its elements through enumeration. Vector v = new Vector(); v.add("Some String"); v.add(10); Enumeration e = v.elements(); while(e.hasMoreElements())…