CommonUtils
"Right around Christmas time," Earl B writes, "I inherited a lovely Java project that contained a library class named CommonUtils. Wandering inside, I found something quite strange in the middle of quite a few other weird things."

public static Integer getIntegerValueOf(int value) {
        Integer result;
        if ( value == 0 ) {
            result = DomainConstants.INTEGER_0;
        } else if ( value == 1 ) {
            result = DomainConstants.INTEGER_1;
        } else {
            result = new Integer(value);
        }
        return result; 
    }

"DomainConstants is an Interface with a list of static Objects," added Earl, "I'll let you guess what DomainConstants.INTEGER_0 and DomainConstants.INTEGER_1 are."

 

The Inadequate java.lang.*
"After recently joining a new application team," Justin M wrote, "I've come to realize that original developers (some of whom still work on the project) aren't the biggest fan of the classes in java.lang.*"

"Now don't get me wrong, they obviously use them, but primarily to develop their own, 'better' versions. Take, for example, IntegerType, their version of the Integer.

package com.initrodeGlobal;

public class IntegerType {
    Integer i;

    public IntegerType(int value)
    { i = new Integer(value); }
    public IntegerType(String s)
    { i = new Integer(s); }

    public static Integer decode(String nm) throws NumberFormatException
    { return Integer.decode(nm); }
    public static Integer getInteger(String nm)
    { return Integer.getInteger(nm); }
    public static Integer getInteger(String nm, int val)
    { return Integer.getInteger(nm, val); }
    public static Integer getInteger(String nm, Integer val)
    { return Integer.getInteger(nm, val); }
    public static int parseInt(String s) throws NumberFormatException
    { return Integer.parseInt(s); }
    public static int parseInt(String s, int radix) throws NumberFormatException
    { return Integer.parseInt(s, radix); }
    public static String toBinaryString(int i)
    { return Integer.toBinaryString(i); }
    public static String toHexString(int i)
    { return Integer.toHexString(i); }
    public static String toOctalString(int i)
    { return Integer.toOctalString(i); }
    public static String toString(int i)
    { return Integer.toString(i); }
    public static String toString(int i, int radix)
    { return Integer.toString(i, radix); }
    public static Integer valueOf(String s) throws NumberFormatException
    { return Integer.valueOf(s); }
    public static Integer valueOf(String s, int radix) throws NumberFormatException
    { return Integer.valueOf(s, radix); }

    public int compareTo(Object o)
    { return i.compareTo((Integer)o); }
    public int compareTo(Integer anotherInteger)
    { return i.compareTo(anotherInteger); }

    public byte byteValue()
    { return i.byteValue(); }
    public double doubleValue()
    { return i.doubleValue(); }
    public float floatValue()
    { return i.floatValue(); }
    public int intValue()
    { return i.intValue(); }
    public long longValue()
    { return i.longValue(); }
    public short shortValue()
    { return i.shortValue(); }

    public boolean equals(Object obj)
    { return i.equals(obj); }
    public int hashCode()
    { return i.hashCode(); }
    public String toString()
    { return i.toString(); }
}
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!