Daily WTF?

V práci jsem našel po jednom bývalém spolupracovníkovi kus velice příjemného kódu. Prostě se o něj musím podělit.

Někdo by řekl, že stačí nahradit poslední dvě číslice, případně kontrolovat přetečení přes desítku.

/**
 * Parses ticketing number and returns array with ticket numbers.
 * @param number Source ticket number.
 * @return String array of length 2. The first item is starting ticket number, the seconond item is the last ticket number.
 */
private static
String[] parseTicketNumber(String number) {
    String[] no = new String[2];
    String[] s = number.split("-");
    no[0] = s[0];
    if (s.length == 1) {
        no[1] = s[0];
    } else if (s.length == 2) {
        long i = Long.valueOf(s[0]).longValue();
        while (!Long.toString(i).endsWith(s[1])) {
            i++;
        }
        no[1] = Long.toString(i);
    } else {
        return null;
    }
    return no;
}
 

Přidat komentář

0 Komentáře.

Přidat komentář


Upozornění - Můžete použít tytoHTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*