Results 1 to 3 of 3

Thread: Verbose Java

  1. #1
    JeanNoel 53 is offline Member
    Join Date
    Dec 2010
    Posts
    5
    Rep Power
    0

    Smile Verbose Java

    I have lot of enum in my program end i have some case where I have numeric value to adress them.
    however i coded trancode method to solve this problem.
    But this seem very verbose, in C++ it's direct. for example I give an enum, a tracode and a direct implementation that is not working.
    Java Code:
    public enum enPOS 
       {
         POS_NONE,				//	Undefined                   0
         POS_PREP,				//	Preposition                 1
         POS_ART,				//	Article                     2
         POS_ADJ,				//	Adjective                   3
         POS_NOUN,				//	Noun                        4
         POS_NB,				//	Number                      5
         POS_MARK,				//	Mark                        6
         POS_SENT,				//	Sentence point              7
         POS_STOPMARK,		                //	Mark of end of sentence     8
         POS_COMMA,			        //	Comma                       9
         POS_CONJ,				//	Conjunction                 10
         POS_PRONOUN,		                //	Pronoun                     11
         POS_VERB,				//	Verb                        12
         POS_AUX,				//	Auxiliary                   13
         POS_ADV,				//	Adverb                      14
         POS_PAST_PARTICIPLE,	                //	Participle                  15
         POS_PRESENT_PARTICIPLE,               //      Participe présent           16
         POS_BLANK,			        //	Blank                       17
         POS_ABREV,                            //      Abreviations                18
         POS_NAMED_ENTITY,                     //      Noms propre et Entitée nomée19
         POS_DECLENCHEUR,                      //      mots servant à repèrer les préconditions 20
         POS_DECLENCHEUR_MOT,                  //      noms déclanchant            21
         POS_PIVOT,                            //      mot continuant un syntagme  22
         POS_OTHER,			        //	Other POS                   23
         NUMBER_OF_POS,
       };
    the transcode function is as folloowing:
    Java Code:
    public int transtypePOSToInt( enPOS pTemp)
        {
           int iPos = 0;
           switch (pTemp) {
                            case POS_NONE:
                                iPos = 0;
                                break;
                            case POS_PREP:
                                iPos = 1;
                                break;
                            case POS_ART:
                                iPos = 2;
                                break;
                            case POS_ADJ:
                                iPos = 3;
                                break;
                            case POS_NOUN:
                                iPos = 4;
                                break;
                            case POS_NB:
                                iPos = 5;
                                break;
                            case POS_MARK:
                                iPos = 6;
                                break;
                            case POS_SENT:
                                iPos = 7;
                                break;
                            case POS_STOPMARK:
                                iPos = 8;
                                break;
                            case POS_COMMA:
                                iPos = 9;
                                break;
                            case POS_CONJ:
                                iPos = 10;
                                break;
                            case POS_PRONOUN:
                                iPos = 11;
                                break;
                            case POS_VERB:
                                iPos = 12;
                                break;
                            case POS_AUX:
                                iPos = 13;
                                break;
                            case POS_ADV:
                                iPos = 14;
                                break;
                            case POS_PAST_PARTICIPLE:
                                iPos = 15;
                                break;
                            case POS_PRESENT_PARTICIPLE:
                                iPos = 16;
                                break;
                            case POS_BLANK:
                                iPos = 17;
                                break;
                            case POS_ABREV:
                                iPos = 18;
                                break;
                            case POS_NAMED_ENTITY:
                                iPos = 19;
                                break;
                            case POS_DECLENCHEUR:
                                iPos = 20;
                                break;
                            case POS_DECLENCHEUR_MOT:
                                iPos = 21;
                                break;
                            case POS_PIVOT:
                                iPos = 22;
                                break;
                            case POS_OTHER:
                                iPos = 23;
                        }
            return( iPos);
        }
    this code is verbose!:D
    and a direct implementation that will be my wish
    Java Code:
    int ipos;
    enPOS POS;
     ipos = (enPOS) POS;

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default

    Quote Originally Posted by JeanNoel 53 View Post
    this code is verbose!:D
    and a direct implementation that will be my wish
    Java Code:
    int ipos;
    enPOS POS;
     ipos = (enPOS) POS;
    You didn't actually ask a question, and I'm not really sure what that code is supposed to be doing. Why are you casting your variable to the enum type that it's already been declared as?

    But if my magic crystal ball is working correctly, I gather that you might want to look into storing the int value inside the enum type.

    Like so:

    Java Code:
    public class EnumTest {
    
    	public static enum TestEnum{
    		
    		EN_ONE(1), EN_TWO(2), EN_THREE(3);
    		
    		private int i;
    		
    		private TestEnum(int i){
    			this.i = i;
    		}
    		
    		public int getI(){
    			return i;
    		}
    	}
    	
    	public static void main(String[] args) {
    		int i;
    		TestEnum t = TestEnum.EN_ONE;
    		i = t.getI();
    		System.out.println(i);
    	}
    }
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default

    Also have a look at the ordinal() method; e.g.

    Java Code:
    enum E { A, B, C }
    
    public class T {
    
    	public static void main (String[] args) {
    		
    		System.out.println(E.A+": "+E.A.ordinal());
        }
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

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