Search Results

Search found 414 results on 17 pages for 'enums'.

Page 7/17 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • How thread-safe is enum in java?

    - by portoalet
    Hi, How thread-safe is enum in java? I am implementing a Singleton using enum (as per Bloch's Effective Java), should I worry at all about thread safety for my singleton enum? Is there a way to prove or disprove that it is thread safe? // Enum singleton - the preferred approach public enum Elvis { INSTANCE; public void leaveTheBuilding() { ... } } Thanks

    Read the article

  • Using NHibernate to map a nChar column to an enumerated type

    - by Morrislgn
    Hello Folks, I am trying to map a table frp, a SQL Server 2005 DB to a class which contains an enum: public class MyClass{ private YesNoOptional addressSetting; public YesNoOptional AddressSetting{ {get; set;} } } public enum YesNoOptional { Yes, No, Optional } This will dictate that one of three values is inserted into the corresponding column - 'Y', 'N', 'O'. This column is of type nchar(1). My mapping file is like so (addressSetting is the property which is causing the problem): <class name="IncidentDefinition" table="IR_INCIDENT_DEF" lazy="false" > <id name="Guid" column="INT_GUID" > <generator class="guid"></generator> </id> <property name="Reference" column="INT_REF" ></property> <property name="Description" column="INT_DESCRIPTION" ></property> <property name="AddressSetting" column="INT_ADDRESS_REQ" ></property> <property name="Active" column="INT_ACTIVE" type="YesNo"></property> <property name="PinDocId" column="INT_PIN_DOC_ID"></property> </class> Using the config above I get the following error: NHibernate.ADOException: could not initialize a collection: System.FormatException: Input string was not in a correct format.. If I try to map the enum using a custom type like so: <property name="AddressSetting" column="INT_ADDRESS_REQ" type="ML.Types.YesNoOptional, ML.Types" ></property> Error: System.FormatException: Input string was not in a correct format. Next, if I try using a specific type like so: <property name="AddressSetting" column="INT_ADDRESS_REQ" type="String" ></property> This error is generated: NHibernate.PropertyAccessException: The type System.String can not be assigned to a property of type System.ArgumentException: Object of type 'System.String' cannot be converted to type 'ML.Types.YesNoOptional'.. As a last resort I tried to specify the type as a char like so: <property name="AddressSetting" column="INT_ADDRESS_REQ" type="Char" ></property> This works a bit better, as it in it doesnt throw an error, however instead of returning the character from the table and mapping it to the enumerated type the ASCII value of the character is returned instead - so Y is represented by 89! I am hoping someone can explain what I am doing wrong and\or how why this is happening please? Thanks Morris

    Read the article

  • how to add enum value to list

    - by netmajor
    I have enum: public enum SymbolWejsciowy { K1 , K2 , K3 , K4 , K5 , K6 , K7 , K8 } and I want to create list of this enum public List<SymbolWejsciowy> symbol; but in my way to add enum to List: 1. SymbolWejsciowy symbol ; symbol.Add(symbol = SymbolWejsciowy.K1); 2. symbol.Add(SymbolWejsciowy.K1); I always get Exception Object reference not set to an instance of an object. What i do wrong :/ Please help :)

    Read the article

  • Spring - How do you set Enum keys in a Map with annotations

    - by al nik
    Hi all, I've an Enum class public enum MyEnum{ ABC; } than my 'Mick' class has this property private Map<MyEnum, OtherObj> myMap; I've this spring xml configuration. <util:map id="myMap"> <entry key="ABC" value-ref="myObj" /> </util:map> <bean id="mick" class="com.x.Mick"> <property name="myMap" ref="myMap" /> </bean> and this is fine. I'd like to replace this xml configuration with Spring annotations. Do you have any idea on how to autowire the map? The problem here is that if I switch from xml config to the @Autowired annotation (on the myMap attribute of the Mick class) Spring is throwing this exception nested exception is org.springframework.beans.FatalBeanException: Key type [class com.MyEnum] of map [java.util.Map] must be assignable to [java.lang.String] Spring is no more able to recognize the string ABC as a MyEnum.ABC object. Any idea? Thanks

    Read the article

  • Most common C# bitwise operations

    - by steffenj
    For the life of me, I can't remember how to set, delete, toggle or test a bit in a bitfield. Either I'm unsure or I mix them up because I rarely need these. So a "bit-cheat-sheet" would be nice to have. For example: flags = flags | FlagsEnum.Bit4; // Set bit 4. or if ((flags == FlagsEnum.Bit4)) == FlagsEnum.Bit4) // Is there a less verbose way? Can you give examples of all the other common operations, preferably in C# syntax using a [Flags] enum?

    Read the article

  • Hibernate - how to map an EnumSet

    - by al nik
    Hi all, I've a Color Enum public enum color { GREEN, WHITE, RED } and I have MyEntity that contains it. public class MyEntity { private Set<Color> colors; ... Do you know how to map this in the relative Hibernate hbm.xml? Do I need a UserType or there's an easiest way? Thanks

    Read the article

  • Enum type constraints in C#

    - by Taylor L
    What is the reason behind C# not allowing type constraints on Enum's? I'm sure there is a method behind the madness, but I'd like to understand why it's not possible. Below is what I would like to be able to do (in theory). public static T GetEnum<T>(this string description) where T : Enum { ... }

    Read the article

  • Choosing the default value of an Enum type without having to change values

    - by frou
    In C#, is it possible to decorate an Enum type with an attribute or do something else to specify what the default value should be, without having the change the values? The numbers required might be set in stone for whatever reason, and it'd be handy to still have control over the default. enum Orientation { None = -1, North = 0, East = 1, South = 2, West = 3 } Orientation o; // Is 'North' by default.

    Read the article

  • Why C# calls different overloaded method for different values of same type?

    - by Fabio Veronez
    Hello all, I have one doubt concerning c# method overloading call resolution. Let's suppose I have the following C# code: enum MyEnum { Value1, Value2 } public void test() { method(0); // this calls method(MyEnum) method(1); // this calls method(object) } public void method(object o) { } public void method(MyEnum e) { } Note that I know how to make it work but I would like to know why for one value of int (0) it calls one method and for another (1) it calls another. It sounds awkward since both values have the same type (int) but they are "linked" for different methods. Ps.: This is my first question here, i'm sorry if I made something wrong. =P

    Read the article

  • Is it a good idea to keep all the enums in one place?

    - by kzen
    When I'm building a class library I usually create a file Enums.cs to hold all the enums used in the assembly. Here is an example: namespace MyNamespace { public enum Colors { Red, Green, Blue } public enum Shapes { Circle, Square, Triangle } } This makes all my enums easy to find, well organized and easy to access in code. I'm wondering if there is any reason why this would not be such a good idea?

    Read the article

  • In Rails, how should I implement a Status field for a Tasks app - integer or enum?

    - by Doug
    For a Rails 3.0 Todo app, I have a Tasks model with a Status field. What's the best way to store the Status field data (field type) and still display a human-readable version in a view (HTML table)? Status can be: 0 = Normal 1 = Active 2 = Completed Right now I have this: Rails Schema Here: create_table "tasks", :force = true do |t| t.integer "status", :limit = 1, :default = 0, :null = false Rails Model Here: class Task < ActiveRecord::Base validates_inclusion_of :status, :in => 0..2, :message => "{{value}} must be 0, 1, or 2" Rails View Here: <h1>Listing tasks</h1> <table> <tr> <th>Status</th> <th>Name</th> <th></th> <th></th> <th></th> </tr> <% @tasks.each do |task| %> <tr> <td><%= task.status %></td> <td><%= task.name %></td> <td><%= link_to 'Show', task %></td> <td><%= link_to 'Edit', edit_task_path(task) %></td> <td><%= link_to 'Delete', task, :confirm => 'Are you sure?', :method => :delete %></td> </tr> <% end %> </table> Requirements Store a Task's status in the db such that the values are easily localizable, i.e. I'm not sure I want to store "normal", "active", "completed" as a string field. Solution must work with Rails 3.0. Questions: Should I store the field as an integer (see above)? If so, how do I display the correct human readable status in an HTML table in my Rails view, e.g. show "Active" instead of "1" in the HTML table. Should I use an enum? If so, is this easy to localize later? Should I use straight strings, e.g. "Normal", "Active", "Completed" Can you provide a quick code sample of the view helper, controller or view code to make this work?

    Read the article

  • Obj-C Error: Expected expression before ...... (why?)

    - by Horatiu Paraschiv
    Hi I have an enum declared like this: typedef enum { Top, Bottom, Center } UIItemAlignment; In my code I try to use it like this: item.alignment = UIItemAlignment.Top; I get an error like this: " Expected expression before 'UIItemAlignment' " If I use only: item.alignment = Top; everything works fine but why do I get this error if I try to use it the other way? _alignment is an NSInteger and it has a property declared like this @property (readwrite) NSInteger alignment; and I synthesized it in my implementation file. So my question is, why do I get this error?

    Read the article

  • Source Insight: Show me Enum Values

    - by JXG
    I'm programming in C and using Source Insight. I have an enum type with a lot of constants (like 100). I have debug prints that print out variable values, but they (of course) print out as integers. What I'd like to do is click on the name of an enum constant, and see its numeric value displayed somewhere. (I've seen this done in a Visual Studio plugin, so it must be possible.) That is, assume I have enum colors { ORANGE, PURPLE, PINK }; I want to click on (or select, or something) PURPLE and see the value 1 somewhere visible (ideally, the symbol window or context window, but I'm not particular). Is there an easy way to do this in Source Insight? Is there a difficult way, at least (such as writing a macro)?

    Read the article

  • Is there a way to make ToEnum generic

    - by maxfridbe
    I would like to do this but it does not work. bool TryGetEnum<TEnum, TValue>(TValue value, out TEnum myEnum) { if (Enum.IsDefined(typeof(TEnum), value)) { myEnum = (TEnum)value; return true; } return false; } Example usage: MyEnum mye; bool success = this.TryGetEnum<MyEnum,char>('c',out mye);

    Read the article

  • org.hibernate.HibernateException: Error while accessing enum.values(): class com.mksoft.fbautomate.d

    - by Misha Koshelev
    This error is driving me nuts!!! Caused by: java.lang.NoSuchMethodException: com.mksoft.fbautomate.domain.Account$Type.values() The same exact class works fine in a separate Groovy file. Any ideas/help much appreciated. Most confusing... http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html has no values() method! Here is my class: @Entity class Account { @Id @GeneratedValue(strategy=GenerationType.AUTO) public Long id enum Type {MYVALUE} @Enumerated(EnumType.STRING) public Type type public String email // @org.hibernate.annotations.Type(type="encryptedString") public String pass public String fullName String toString() { "type:\""+type+"\",email:\""+email+"\""+",fullName=\""+fullName+"\"" } } Thank you! Misha

    Read the article

  • C++ enumerations and compiler dependency

    - by dougie
    I currently have code with an enum where one value is set and the rest are left to be set by the compiler using the previous value +1, or so I hope. Is this functionality within an enumerated type compiler dependant, an example is below to clarify. enum FUNC_ERROR_CODE { FUNC_SUCCESS, FUNC_ERROR_1 = 24, FUNC_ERROR_2, FUNC_ERROR_3 } Is it safe to assume that FUNC_ERROR_2 will have the value 25 and FUNC_ERROR_3 will have the value 26, regardless of compliler used. I'm coding this so as a function can return an integer value, 0 is always success and any other value can signify failure.

    Read the article

  • Is there a way to make `enum` type to be unsigned?

    - by Kirill V. Lyadvinsky
    Is there a way to make enum type to be unsigned? The following code gives me a warning about signed/unsigned comparison. enum EEE { X1 = 1 }; int main() { size_t x = 2; EEE t = X1; if ( t < x ) std::cout << "ok" << std::endl; return 0; } I've tried to force compiler to use unsigned underlying type for enum with the following: enum EEE { X1 = 1, XN = 18446744073709551615LL }; But that still gives the warning.

    Read the article

  • Most elegant way to morph this sequence

    - by Ed Woodcock
    Hi folks: I've got the Day of the week stored in a database table (that I do not control), and I need to use it in my code. Problem is, I want to use the System.DayOfWeek enum for representation for this, and the sequences are not the same. In the database, it's as follows: 1 2 3 4 5 6 7 S M T W T F S I need it as follows: 0 1 2 3 4 5 6 M T W T F S S What's the most elegant way to do this? for example, I could do: i = dayOfWeek; i = i - 2; if (i < 0) { i = 6; } but that's a bit inelegant. Any suggestions?

    Read the article

  • Convert integer enum to string

    - by user216205
    Hi Guys, considering the following enum: public enum LeadStatus { Cold = 1, Warm = 2, Hot = 3, Quote = 5, Convert = 6 } How can I convert the integer value back to string when I pull the value from a database. I've tried: DomainModel.LeadStatus status = (DomainModel.LeadStatus)Model.Status; but all I seem to get is "status = 0"

    Read the article

  • How would I set up this enum to return the image I want?

    - by Justen
    I'm trying to set up this enum so that it has the ability to return the correct image, though I'm struggling with a way to incorporate the context since it is in a separate class. public enum CubeType { GREEN { public Drawable getImage() { return Context.getResources().getDrawable( R.drawable.cube_green ); } }; abstract public Drawable getImage(); } The error I'm getting is: Cannot make a static reference to the non-static method getResources() from the type Context

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >