James sent in today's snippet with virtually no introduction; just six, measly words: "the grass is definitely not greener." Normally, that'd be a bit frustrating, since it's always nice to know a little history or background about the code. But like those six word stories, James told the classic tale of the young and burgeoning software developer who’s always looking to expand his professional purview by seeking out new opportunities to learn and sharpen his skills, only to find his efforts frustrated by a “seemed good on paper” job that leads to nowhere – or worse – towards destitute and despair.
Well, either that, or this code really speaks for itself. Maybe it's the generic Util class which acts as a dump for random methods. Perhaps it's the alphabet array with an extra Z. Or it could be that method for turning letters into numbers.
/** * The utilize methods. */ public final class Util { /** * The ARRALPHALET chars . */ private static final String[] ARRALPHALET = new String[] { "Z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; /** * the count ARRALPHALET chars. */ private static final int VALUE = 26; ...snip... /** * @param decimal * @return */ public static String dec2Alpha(final int decimal) { final ArrayList<String> arrResult = new ArrayList<String>(); int a = decimal; int b = decimal; do { b = a / VALUE; final int c = a % VALUE; if (c == 0 && b == 0) { arrResult.add(0, "0"); } else if (c == 0 && b != 0) { b = b - 1; arrResult.add(0, ARRALPHALET[c]); } else { arrResult.add(0, ARRALPHALET[c]); } a = b; } while (a > VALUE); if (a != 0) { arrResult.add(0, ARRALPHALET[a]); } return StringUtils.join(arrResult.toArray()); } }