enum 3 « enum « Java Data Type Q&A

1. Returning flags from enums    java-forums.org

Perhaps your Rotation enum could hold an ArrayList of MirrorFlags as an instance field, and each Rotation could create list in its constructor. Then it can have a method that returns this list. Regarding your second question, no there is no internal method for this (it should be obvious since this isn't an intrinsic property of enum but rather an intrinsic ...

2. Struggling with enum!    java-forums.org

3. Enum confusion    java-forums.org

import java.util.Map; import java.util.TreeMap; public enum Day2 { //Day2 enums use the Day2 constructor for String types. DAY1STRING1("Open"), DAY1STRING2("Closed"), DAY1STRING3("Cancelled"), DAY1STRING4("Reversed"), DAY2DOUBLE1(2.2), DAY2DOUBLE2(5.0); public static Map dayMap = new TreeMap(); private String value; private Double num; public int samba = 1000; static{ dayMap().put("Open", DAY1STRING1); dayMap().put("Closed",DAY1STRING2); dayMap().put("Cancelled",DAY1STRING3); dayMap().put("Reversed", DAY1STRING4); dayMap().put("Reversal",DAY2DOUBLE1); dayMap().put("Expired", DAY2DOUBLE2); } private Day2(String value){ this.value = value; } ...

4. Enums taking in enums?    java-forums.org

5. Learning enum    java-forums.org

Java Code: C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:5: error: illegal start of type FATHER {56}, ^ C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:5: error: ';' expected FATHER {56}, ^ C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:5: error: illegal start of type FATHER {56}, ^ C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:6: error: ';' expected MOTHER {52}, ^ C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:6: error: not a statement MOTHER {52}, ^ C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:6: error: ';' expected MOTHER {52}, ^ C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:6: error: illegal start of type MOTHER {52}, ^ C:\Program\Java\jdk1.7.0\jre\classes\pjjava\nbie\Family.java:6: error: ';' ...

6. Copy construtor with enums -    java-forums.org

7. Enum Question    forums.oracle.com

9. About enums    forums.oracle.com

I got the ans.. Static means one per class. means it is related to class member so nested classes are member of inclosing class so it is allowed, thas why it is not allowed for non-inner classes if it is right please reply me other wise i am having wrong concept in my mind.

10. Abstract enums.    forums.oracle.com

Hi All, I was trying to create an abstract enum within a java class using Eclipse IDE, but as soon as I specify abstract keyword before enum declaration, the compiler complains saying that 'Only public, private, protected, static & abstract are allowed.' If abstract is allowed, why is this error coming up then? Any code snippet of abstract enum if you ...

11. enum validation    forums.oracle.com

Well, if you type in "PC", then input is not "Wii", so that goes as "true" and hence you enter the while. Your logic is faulty. Try AND, not OR - it's supposed to be neither of those values. Or just negate the unnegated ORs combined. I don't see any enum there by the way.

13. Enum question    forums.oracle.com

The assignment is to write a tokenizer. It will read in word by word and then an integer value is assigned to each respective word/letter based on what kinda it is. Reserved words are given integer values 1-10; Special symbols are given the value 11-29; Integers (no matter the value) are given the value 30 and Identifiers are given the value ...

14. Using enum to validate tokens in a string    forums.oracle.com

Hi, My java expereince is limited, however I want to make use of enums when tokenising. e.g. enum Tokens { LeftBracket("("), RightBracket(")"), Open("Open"), Close("Close"), End("."), More("/"), Quote("\""); private String token Token (String s) this.token = s; } What I want to do is add a method where I present a String e.g. "End", my Token is scanned and the token variable ...

15. Enums    forums.oracle.com

import java.util.*; enum OperatingSystems { windows, unix, linux, macintosh } public class NewClass { public static void main(String args[]) { OperatingSystems os; os = OperatingSystems.windows; switch(os) { case windows: System.out.println("You chose Windows!"); break; case unix: System.out.println("You chose Unix!"); break; case linux: System.out.println("You chose Linux!"); break; case macintosh: System.out.println("You chose Macintosh!"); break; default: System.out.println("I don't know your OS."); break; } } } ...

16. Enum multiple choice question    forums.oracle.com

17. trying to understan how to use enums    forums.oracle.com

18. Implement enum in java    forums.oracle.com

19. enums in public enum    forums.oracle.com

20. Enums - Deck/Display Deck    forums.oracle.com

21. Trying to use Enum    forums.oracle.com

For my java class I need to create an enumeration called TaxBracket. Using Eclipse and JDK 6 I try and create a file by right clicking on the project name in Eclipse and selecting NEW --> ENUM. When I try to give it a name it says "Project HW4 is not a JDK 5.0 compliant project". I have JDK 6 why ...

22. Quick enum question    forums.oracle.com

23. enum and restrictions    forums.oracle.com

Hi, Could anybody tell me what are the underlying reasons of not letting clone enums (and what has got in common with special handling of serialization I believe ...) ? I know that it would break the singleton design pattern, but why is it so important ? What would the risk be ? Any examples ? Thanks, Adrian

24. enum and modifiers    forums.oracle.com

25. am I explaining this enum right?    forums.oracle.com

27. enum in JDK 1.5.07    forums.oracle.com

else { NUM_INFO ni = Enum.valueOf( NUM_INFO.class, argv[0].toUpperCase()); System.out.println( "Char : " + ni.getNumChar() + "\n" + "Value: " + ni.getNumValue() ); System.out.println("Name of the Num Info : " + ni.name()); } } } enum NUM_INFO { ONE ('1', 1.0/6.0), TWO ('2', -2.0/6.0), THREE ('3', 3.0/6.0), FOUR ('4', -4.0/6.0), FIVE ('5', 5.0/6.0), SIX ('6', -6.0/6.0);

28. What is enum used for?    forums.oracle.com

Hi folks, Happy new year one and all. I'm teaching my self Java out of a book at the moment, and the author has dropped enum out of nowhere with no explanation as to what it is and how it's used. From what I gather, it seems to be some sort of collection of some sort, to store a bunch of ...

29. A small doubt regarding Enums....    forums.oracle.com

30. cant get enum to work for java 6 - what am i doing stupid    forums.oracle.com

trying to define an enum inside a class as this public class Keyboard { enum SpecialCharacters {EoF} ... however the eclipse editor on java 6 come back with "enum could not be resolved to a type". if i save the enum def in its own java file that doesnt work either. must be doing something stupid - can any one put ...

31. semicolon exptected while use enum    forums.oracle.com

It iwas weird, after i used BlueJ and chose the same VM, the code can run as usuall. Anyone can give me clue why in my cygwin and command line cannot running this code. I have the same problem while i try to use the Collection-Based for Loop Hope someone can help me

32. A default enum    forums.oracle.com

33. import enum    forums.oracle.com

You can't import anything from the default package (and you don't need to) so both of your (outer) classes have to be in a package if you want to import them. If you use different pacakages the class and the enum have to have public access.. kind regards, Jos edit: and make that A.Proof instead of just Proof in your other ...

34. using enums    forums.oracle.com

35. enum code    forums.oracle.com

it turns out that the reason i had a problem is because the book explained how to put two classes in code with creator so the code was not expected to run with out putting in the second class (enum) as i had not done that before i could not execute the program until i had read the next chapter. unfortunately ...

36. I can't import enums for some reason    forums.oracle.com

In a class I made, I can't seem to import an enum. Eclipse tells me "The import de.game.ground.Constants.Board cannot be resolved." Board is the name of my enum sitting in the class Constants. What's so weird is that other classes have imported the enum and are using it just fine. But for some reason this one class won't. These classes are ...

37. Getting my head around enum    forums.oracle.com

I'm trying to understand all of the features available using java's enum. I understand everything about enums as long as they are simple enumerated lists. However when constructors, methods, and instance variables are thrown into the mix, I loss the ability to make sense of what an enum really is and what it does. I'm reading the following article, but I ...

38. Enum Style Question    forums.oracle.com

I tried googling this but haven't found the answer. In my application, a game, I've set up a couple of enums. The first is for the menu EASY, MEDIUM, HARD. Mulitple classes use it for animation speed etc. I like it much better than passing an int or char because makes the code very readable.

39. ENUMS    forums.oracle.com

I have a few quick questions about using ENUMs - and why they are so good? After having read the documentation on them on sun.com, and my own textbook notes, I'm still not entirely clear about using them. I know you should use them when you have a fixed set of constants (such as days of the week, status' for something). ...

40. Enum Question    forums.oracle.com

41. Enums    forums.oracle.com

An enum basically defines a class with a fixed number of instances that can be accessed statically. Enums are NOT represented in any way as ints, nor are they indexed in any retrievable way. However, as enums can have fields, methods and constructors just like regular classes, it's easy enough to define a method that returns whatever int you want. BTW, ...

42. Enum question    forums.oracle.com

No, I agree, but the bad design I think lies in how I'm passing the Enum now. I don't know, I guess what I'm asking is it possible to pass just an Enum as a whole to an entirely different object without creating a needless instance of it? Like what I really want is to call doSomething like this: doSomething(UserStatus); Obviously, ...

43. Enum Question    forums.oracle.com

It's almost always better to keep information in as specific a type as you can. So for a whole number of inches, use an int rather than a string. For two such numbers, you can use two ints, or - in this specific case - you know the max is one less than the min of the next, you could iterate ...

44. cannot use enums    forums.oracle.com

public String toString() { if (value > 1 && value < 11) return String.valueOf(value); else if (value == 1) return "Ace"; else if (value == 11) return "Jack"; else if (value == 12) return "Queen"; else if (value == 13) return "King"; else return "error"; } public int value() { return value % 13 + 1; } }

45. Enum to return Enum    forums.oracle.com

It is possible, but IMO, a bad design. Enums are good for discrete states. However, if you find yourself maintaining things like graphs or trees or associations, you probably would be better off modelling these at an abstract level (e.g., Domain, Action, etc. in your examples) and moving the associations (which actions allowed for a domain) to external configuration such as ...

46. enum - core java II example    forums.oracle.com

47. Enum misuse when used to implement interpreted language procedures?    forums.oracle.com

I don't consider it a misuse at all. An enum is simply a class with a known, fixed, named set of instances that exist as long as the class exists. Enums were specifically designed to allow this kind of functionality. If there's any abuse going on, you could say it's enum's design encouraging such different behaviors by instance rather than by ...

48. enum lookup by multiple strings    forums.oracle.com

49. How to replace my enum implementation with something more efficient!    forums.oracle.com

To reduce the footprint, take advantage of I/O streams. Don't read everything into a collection. Read in one record at a time, transform or permute it or store it or transmit it or whatever you are doing, and then read the next one. If you need to summarize the records, only store the summary information (e.g., count, sum, standard deviation, whatever). ...

50. Enum    forums.oracle.com

51. Using ENUM with FLAGS in java    forums.oracle.com

52. Enum    forums.oracle.com

They are basically double values of a more complicated Object and belong to a class. I have 10 instances of a class like: Currency class, Region class, and these double refer to some value in this class; where I have to display these values in one row in a report so I used an Array to keep all these values ...

53. getting an Enum[]?    forums.oracle.com

54. enum can be local?    forums.oracle.com

Thankyou prometheuzz for your kind reply. But I am little confused. Implicitly static means In what sense? Is that implicitly static to some other class or it is a static declaration? If we say that we can't declare a static class or variable means we must use the KeyWord "static" right? but I am just declaring simply as enum. Did I ...

55. Quick enum question    forums.oracle.com

Just one possible "style" issue... same as putting "normal" constants in interfaces... All classes which implement that interface inheret the constants. If that makes to you in your circumstances then go-for-it... If it really doesn't then consider removing the constants to a dedicated class. There is no correct answer, both approachs have there adds and disadds.

56. Enums - a good way to hold configuration data    forums.oracle.com

57. enums    forums.oracle.com

58. Difference between java.lang.Enum && enum    forums.oracle.com

59. Design Question enums etc    forums.oracle.com

Ok. So I have a class that represents a symbol. A symbol can have many values associated with it e.g name, description, type etc I have a BaseSymbol which contains a map, which I'm intending to use to store the values associated with a symbol ( as above ) rather than having explicit fields associated with the symbol. So BaseSymbol implements ...

60. Embedding a displayable form in enums?    forums.oracle.com

Alternatively you can override toString(), either globally or in individual values. In general you should use name() to get the format name, toString() for the human readable form. Overriding toString is convenient when, for example, you use the enum as the basis of a JComboBox or the like where toString() is called implicitly.

61. enum    forums.oracle.com

62. enum not recognized...    forums.oracle.com

63. enums programs are not executing....?    forums.oracle.com

64. How to create and use enum    forums.oracle.com

public enum enumRequest { REQUEST1 (1), REQUEST2 (2), REQUEST3 (3); private final int state; enumRequest (Integer state) {this.state=state);} public GetState() { return this.state;} }; // Constructor RequestHandler() { enumRequest request; } } i am getting an error: "enumRequest cannot be resolved to a type" i am using java 1.5 compiler, can anyone help? 10x.

65. Enum not initialized    forums.oracle.com

66. enums    forums.oracle.com

public Card next() { return get(card++); } public Card dealCard() { // Deals one card from the deck and returns it. if (card == 52) shuffle(); cardsUsed++; return deck[cardsUsed - 1]; } public String toString() { String t = ""; for (int i = 0; i < 52; i++) if ( (i + 1) % 5 == 0) t = t ...

67. can i work on enums with java 1.6?    forums.oracle.com

enum ShirtSize {SMALL,MEDIUM,LARGE} class Shir { ShirtSize shirt; } public class TestShirt { public static void main(String[] a) { Shir s=new Shir(); s.size=Shir.ShirtSize.small; System.out.println(s.size); } } while compilation i got as class or interface expected. i tried in other way also in which enum can be placed inside the class Shir then i got error as ';' expected.........

68. Enums    forums.oracle.com

69. Enum help    forums.oracle.com

70. enum in JDK1.5 vs JDK1.4    forums.oracle.com

71. why enum??    forums.oracle.com

72. Help: a question about the Enum......    forums.oracle.com

73. can i implement enum    forums.oracle.com

i have a class where i defined a class which have an enum and i want other application to use that enum. But that application wants to have more enums than i defined. can anyone please give me a suggestion on how to resolve this issue. i want to implement in sucah a way that othet applciaiton can extend or implement ...

74. Working with enums    forums.oracle.com

Also, now let's say I save this enum to the database but I save it by it's ID, not it's string value. Then later when I read from the database I want to instantiate the right enum type for the IDs I read, how do I do that? Same thing as above, iterate though all of them and compare the next ...

75. ExceptionInInitializerError in Initializing enum    forums.oracle.com

return null; } } ================================ Although this is not a pressing issue as the workaround achieves the same result, I would be interested to know if this is a bug or if there are some restriction on the use of Class.forName that I am not aware of. Thanks in advance for your help with this. Reg

76. Sort by using enums    forums.oracle.com

A lot her depends on how all of your data is structured, and in fact, I think that this is the key. There are probably 100 ways to do something like this, but one way I can think of off the top of my head is: 1) I'd have a Genre enum that lists the various possible genres (i.e., ACTION, COMEDY, ...

77. Dynamically create an enum    forums.oracle.com

I was trying to read in a list of values from a config file and then use these values in an if statement. The idea being that if the values are changed in the config file I wont have to change my code.. That's all very well, but how do you intend to establish the connection between the values, and the ...

78. Defining Enums    forums.oracle.com

Hi all, In my code I have couple of places where i am using static int codes. Now I want to use Enums there. The question I am facing is to define each in their seperate file or define them as public inside the class which is using it. For example I have a class SQLUtil.java which has: public static final ...

79. Java 6 doesn't enum    forums.oracle.com

80. Java 6 doesn't accept enum any more?    forums.oracle.com

81. Is there any way to supress Enum in jdk 1.5    forums.oracle.com

Our application needs to upgrade from jdk.14 to jdk.15. The appl. doesn't automatically compile in jdk1.5 as enum has become a keyword now, whereas we have been using enum as a variable , package name extensively in our application. Is there any way to suppress enum in jd1.5, like the way assert can be suppressed in jdk1.4

82. Enum in Java    forums.oracle.com

83. public enums Java 5    forums.oracle.com

Enums are translated to regular classes so CoffeeSize can't be public in the same file as another public class for the same reason that you can't have two public classes in the same file. Nowhere in that comment does it say that it can be public, only that it can't be private or protected. Message was edited by: dwg

84. Beef with Enums    forums.oracle.com

The issue here is not whether or not I've found the best possible solution to my problem, it's whether or not enumerated types are compatible with interfaces in a meaningful way. If people have found meaningful ways of using interfaces in conjunction with enumerated types, I would like to hear about them, as all the solutions I've found feel ugly.

85. Question Enum    forums.oracle.com

86. Regarding Enum    forums.oracle.com

87. What's the purpose of an Enum?    forums.oracle.com

Too slow. Though I'll add: enum is basically a language feature implementing the "typesafe enum" pattern. (Or, arguably, it's more of an idiom than a pattern, but whatever.) The book Effective Java by Joshua Bloch describes the typesafe enum pattern and why you'd want to use it, in pretty good detail. The book is a bit out of date now (because, ...

88. Java Enums    forums.oracle.com

Some things you want a variable to represent just naturally take a limited set of options best represented by names. Day of week, Compass direction (North, South, East or West) or the like. You could use an integer and define a small set of values, but the enum provides a cleaner and more type-safe approach.

89. Stupid enum question    forums.oracle.com

/** * Returns an array containing the constants of this enum * type, in the order they're declared. This method may be * used to iterate over the constants as follows: * * for(E c : E.values()) * System.out.println(c); * * @return an array containing the constants of this enum * type, in the order they're declared */ public static E[] ...

90. enums    forums.oracle.com

91. Enum in java 1.4    forums.oracle.com

Hai friends We have enum functionality in Java1.5. we don't have it in 1.4. If you want one, here is the code.(Enum in java 1.4) import javax.print.attribute.*; class Bach extends EnumSyntax { public Bach(int x) { super(x); } public static final Bach JOHANN_SEBASTIAN = new Bach(0); public static final Bach WILHELM_FRIEDEMANN = new Bach(1); public static final Bach CARL_PHILIP_EMMANUEL = new ...

92. enum    forums.oracle.com

93. Enums    forums.oracle.com

94. Uncessary enum qualification    forums.oracle.com

OK, I can see why the compiler does what it does, but I can't see why the compiler can't [...] Well, firstly it would make the grammar for the parser much harder to write and much less efficient, and secondly it's generally considered better to have a single unambiguous syntax for these things. The sort of thing you're describing is often ...

95. Enum?    forums.oracle.com

96. Extendable Enums    forums.oracle.com

97. Enums    forums.oracle.com

I know there's no harm in that. It's just to make the code more clear and avoid unnecessary instantiations. mleiria I'd actually like to see what other people think about this. theoretically, yes, it's a good idea, but my take is that anyone using the code will see it's just full of constants, and not worth instantiating anyway, and experience tells ...

99. Self-referencing enum    forums.oracle.com

} The code above creates an entry in the enum called "son" that contains a reference to "dad" and "mom" that are both elements in the same enum. Code that uses this enum will find that both "father" and "mother" are null for "son". Is that right? Is there a better way or prefered way to do this?

100. doubt with an enum program    forums.oracle.com