One of my popular ways to make my code more readable is to make use of an ENUM.
If you have some “if” or “switch” statement:
char myChar = 'D'; if (myChar=='H') { //SOME CODE } else if (myChar=='V') { //SOME OTHER CODE }
it does not say much about the functionality thats why I use enums
public enum myType { HORIZONTAL("H"), VERTICAL("V"); private char directionToken; public static myType fromChar(char searchchar) { for (myType st : myType.values()) { if (st.directionToken == searchchar) { return st; } } return null; } private myType(String transToken) { this.directionToken = transToken.charAt(0); } public char directionToken() { return directionToken; } } ..... myType currRecordType = myType.fromChar(linechar[43]); switch (currRecordType) { case HORIZONTAL:{ ... break; } case VERTICAL:{ ... break; } }