Results 1 to 6 of 6
Thread: Returning flags from enums
- 05-16-2010, 05:49 PM #1
Member
- Join Date
- Apr 2010
- Location
- london UK
- Posts
- 53
- Rep Power
- 0
Returning flags from enums
I hope this is possible ( i guess it is but i don't know how)
I hava an enumerated class mirrorflags
And a enumerated class rotationsJava Code:*/ public enum mirrorflags { DIAMIRROR, VERTMIRROR, HORMIRROR }
Java Code:*/ public enum Rotations { NOTURN, HALFTURN, HORTURN, VERTURN, RDIATURN, LDIATURN, RIGHTTURN, LEFTURN }
now i want a function Rotation.<name of rotation>.mirrors
that returns the mirrors(can be more than one) related to that Rotation
I know i will need to hardcode this in the program but i have no idea where to start.
More complications.
i need a function that is the opposite of rotation.ordinal()
is there a build in function for this or do i need to write something for myself?
something like
Java Code:public rotation Rotation(int ordinal) { for(Rotation i : Rotation) {if (i.ordinal() == ordinal) return i;} }
- 05-16-2010, 06:25 PM #2
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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 property of rotations). You'll have to create this as well.
Sounds like you're having fun with symmetry. Good luck! :)
- 05-16-2010, 07:29 PM #3
Member
- Join Date
- Apr 2010
- Location
- london UK
- Posts
- 53
- Rep Power
- 0
But Rotation are Enums. Can they have instance fields? or static fields?
I thought enums could not have fields at all :eek:
:D Enums are very new to me
- 05-16-2010, 07:52 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,605
- Blog Entries
- 7
- Rep Power
- 17
- 05-16-2010, 08:08 PM #5
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
The names Rotation, rotation and Rotations are all different. Make sure you stay consistent when you actually write your code. It's probably better to call the enum Rotation instead of Rotations, and then the method should be Rotation rotation(int ordinal). Other than that, what you have should work, but I can't help wondering whether you don't want a simple String[] instead.
-Gary-
- 05-26-2010, 07:37 AM #6
Member
- Join Date
- May 2010
- Posts
- 5
- Rep Power
- 0
Thanks gerry i really appreciate your well described post. The names Rotation, rotation and Rotations are all different. Make sure you stay consistent when you actually write your code. It's probably better to call the enum Rotation instead of Rotations, and then the method should be Rotation rotation(int ordinal). Other than that, what you have should work, but I can't help wondering whether you don't want a simple String[] instead.
Similar Threads
-
declaring problems with enums
By jackrulesok in forum New To JavaReplies: 10Last Post: 04-30-2010, 10:16 AM -
why we are using enums in Java?
By manish.anchan in forum New To JavaReplies: 7Last Post: 01-08-2010, 04:41 PM -
Keeps returning null
By ribbs2521 in forum New To JavaReplies: 7Last Post: 02-23-2009, 02:25 AM -
Why is my list returning nothing?
By xcallmejudasx in forum New To JavaReplies: 2Last Post: 11-05-2008, 03:51 PM -
stopping thread...using flags
By rstepler in forum New To JavaReplies: 1Last Post: 07-31-2008, 09:36 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks