Results 1 to 3 of 3
Thread: Verbose Java
- 01-04-2011, 04:02 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 5
- Rep Power
- 0
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.
the transcode function is as folloowing: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, };
this code is verbose!:DJava 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); }
and a direct implementation that will be my wish
Java Code:int ipos; enPOS POS; ipos = (enPOS) POS;
- 01-04-2011, 04:17 PM #2
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!
- 01-04-2011, 04:46 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks