Results 1 to 6 of 6
  1. #1
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default 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
    Java Code:
     */
    public enum mirrorflags {
        DIAMIRROR,
        VERTMIRROR,
        HORMIRROR
    }
    And a enumerated class rotations
    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;}
    }

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    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! :)

  3. #3
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default

    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

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by willemien View Post
    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
    An enum is just a class (although a bit special and you can't extend enums) and it can have fields and methods and the whole shebang.

    kind regards,

    Jos

  5. #5
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    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-

  6. #6
    shaycorl is offline Member
    Join Date
    May 2010
    Posts
    5
    Rep Power
    0

    Default

    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

  1. declaring problems with enums
    By jackrulesok in forum New To Java
    Replies: 10
    Last Post: 04-30-2010, 10:16 AM
  2. why we are using enums in Java?
    By manish.anchan in forum New To Java
    Replies: 7
    Last Post: 01-08-2010, 04:41 PM
  3. Keeps returning null
    By ribbs2521 in forum New To Java
    Replies: 7
    Last Post: 02-23-2009, 02:25 AM
  4. Why is my list returning nothing?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-05-2008, 03:51 PM
  5. stopping thread...using flags
    By rstepler in forum New To Java
    Replies: 1
    Last Post: 07-31-2008, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •