enums

How to inject a Jakarta enums in a Spring application context ?

I have a class which constructor takes a Jakarta enums. I'm trying to find how I can easily inject it via an Spring XML aplicationContext. For example : The enum : public class MyEnum extends org.apache.commons.lang.enums.Enum { public static final MyEnum MY_FIRST_VALUE = new MyEnum("MyFirstValue"); public static final MyEnum ...

Extending enum

public enum myEnum { VAL1(10), VAL2(20), VAL3("hai") { public Object getValue() { return this.strVal; } public String showMsg() { return "This is your msg!"; } }; String strVal; Integer intVal; public Object getValue() { return this.intVal; } private myEnum(int i) { th...

Generate random enum in C# 2.0.

Could someone please point me toward a cleaner method to generate a random enum member. This works but seems ugly. Thanks! public T RandomEnum<T>() { string[] items = Enum.GetNames(typeof( T )); Random r = new Random(); string e = items[r.Next(0, items.Length - 1)]; return (T)Enum.Parse(typeof (T), e, true); } ...

Enum C++ Get by Index

Hi, I was wondering in C++ if I have an enum can I access the value at the second index? For example I have enum Test{hi, bye}; if I want 'hi', can I do something like Test[0], thanks. ...

synch enumeration with static data from a database

Hi I have an enumeration of delivery status codes. And when I save delivery data to the database they are stored with a foreign key to a table containing the same data (i.e. the same delivery codes) What is the best strategy for keeping an enumeration in synch with data in a database? Do you just remember to add to the enumeration wh...

Enum struct? A Value object that behaves like a Enum

Hi, I am wondering how you would approach this problem I have two Taxrates that can apply to my products. I specifically want to avoid persisting the Taxrates into the database while still being able to change them in a central place (like Taxrate from 20% to 19% etc). so I decided it would be great to have them just compiled into my ...

Why do I have to cast enums to int in C#?

This is my code: internal enum WindowsMessagesFlags { WM_EXITSIZEMOVE = 0x00000232, WM_DISPLAYCHANGE = 0x0000007e, WM_MOVING = 0x00000216, } protected override void WndProc(ref Message m) { switch(m.Msg) { case (int)WindowsMessagesFlags.WM_DISPLAYCHANGE: FixWindowSnapping(); break; ...

Do you use enum types in your WCF web services?

I've heard some people saying that enums are evil and shouldn't be used in web services because of the mismatches that could occur between the server and the client if some values are assigned, or if the enum is marked with the Flags attribute. They also said that web services exposing enums are harder to maintain but couldn't really giv...

How can you two-way bind a checkbox to an individual bit of a flags enumeration?

For those who like a good WPF binding challenge: I have a nearly functional example of two-way binding a checkbox to an individual bit of a flags enumeration (thanks Ian Oakes, original MSDN post). The problem though is that the binding behaves as if it is one way (UI to DataContext, not vice versa). So effectively the check box does ...

Check if an enum has a field that equals a string

I have an enum public enum FileExtentions { mp3, mpeg } And I have a FileInfo of which I want to check if the extension is in the previous enum. I was hoping I could do a FileExtensions.Any(e=>e.ToString().Equals(file.Extension)); But that would have been too awesome. Any ideas? ...

Enums in AS3 / Flash / Flex?

One thing I really like about AS3 over AS2 is how much more compile-time type-checking it adds. However, it seems to be somewhat lacking in that there is no type-checked enumeration structure available. What's a good (best / accepted) way to do custom enumerated types in AS3? ...

Which database systems support an ENUM data type, which don't?

Following up this question: "Database enums - pros and cons", I'd like to know which database systems support enumeration data types, and a bit of detail on how they do it (e.g. what is stored internally, what are the limits, query syntax implications, indexing implications, ...). Discussion of use cases or the pros and cons should take...

What's the best way to handle coexistence of the "int enum" pattern with java enums as an API evolves?

Suppose you're maintaining an API that was originally released years ago (before java gained enum support) and it defines a class with enumeration values as ints: public class VitaminType { public static final int RETINOL = 0; public static final int THIAMIN = 1; public static final int RIBOFLAVIN = 2; } Over the years the API has ...

How to get all Enum values in XMLBeans?

Hello Apache XMLBeans can be used to generate Java classes and interfaces from XML Schema Definition files (XSD). It also generates Enums based on StringEnumAbstractBase and StringEnumAbstractBase.Table to represent domain values. They are handy for entering only valid values. However, I want to get all those values to generate a JCombo...

Should enums have uninitialized values . .

We were having a debate if enums should have uninitialized values. For example. We have public enum TimeOfDayType { Morning Afternoon Evening } or public enum TimeOfDayType { None Morning Afternoon Evening } I think that there shouldn't be any none but then you have to default to some valid value on initi...

Are enums only named integers, types or neither of both?

Fun with enums in C#. Take one generic list that is created to store some Enum that you had defined previously and add few items in it. Iterate with foreach or GetEnumerator<T>() but specify some other enum then the original and see what happens. I was expecting InvalidCastException or something like that but it perfectly works :). ...

How to use enums with JPA

I have an existing database of a film rental system. Each film has a has a rating attribute. In SQL they used a constraint to limit the allowed values of this attribute. CONSTRAINT film_rating_check CHECK ((((((((rating)::text = ''::text) OR ((rating)::text = 'G'::text)) OR ((rating)::text = 'PG'::text)) OR ...

Passing an enum value as command parameter from xaml

Hi, I want to pass an enum value as command parameter in WPF, something like this - <Button x:Name="uxSearchButton" Command="{Binding Path=SearchMembersCommand}" CommandParameter="SearchPageType.First" Content="Search"></Button> SearchPageType is an enum and this is to know from which button search command is invoked. Is th...

What's the best way to handle "type" tables with LINQ to SQL?

I have some tables that represent various types. They usually just consist of an ID (int), and a name. Ideally I would have this in an enum. Is there a way to map a table like this onto an enum? EDIT: How would I handle it if there were extra fields other than an ID and Name? ...

What is the size of an enum in C?

I'm creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read somewhere that (at least in GCC) the compiler can make the enum any width they need to be to hold their values. So, is it possible to have an enum that is 64 bits wide...