Code example for WeakHashMap

Methods: put

0
            System.arraycopy(le.entries,0,entries,1,le.entries.length);
        } 
    } 
     
    static { 
        CLASS_DISTANCES = new WeakHashMap();
        initialPopulate(); 
    } 
     
    private static void initialPopulate() { 
        // int, double, byte, float, BigInteger, BigDecimal, long, short 
        // GString, char 
         
         
        LinearEntry object = new LinearEntry();
        object.entries = new Class[]{Object.class};
        CLASS_DISTANCES.put(Object.class,object);
         
        LinearEntry number = new LinearEntry();
        number.concat(new Class[]{Number.class,Serializable.class},object);
        CLASS_DISTANCES.put(Number.class,number);
 
        LinearEntry compareableNumber = new LinearEntry();
        compareableNumber.concat(Comparable.class,number);
         
        LinearEntry binteger = new LinearEntry();
        binteger.concat(new Class[]{BigInteger.class, BigDecimal.class}, compareableNumber);
        CLASS_DISTANCES.put(BigInteger.class,object);
         
        LinearEntry bdec = new LinearEntry();
        binteger.concat(new Class[]{BigDecimal.class, BigInteger.class}, compareableNumber);
        CLASS_DISTANCES.put(BigDecimal.class,object);
         
         
         
        // byte: 
        LinearEntry start = new LinearEntry();
        start.entries =  new Class[]{
                byte.class, Byte.class, short.class, Short.class,
                int.class, Integer.class, long.class, Long.class,
                BigInteger.class,
                float.class, Float.class,  double.class, Double.class, 
                BigDecimal.class,
                Number.class,Object.class};
        CLASS_DISTANCES.put(byte.class,start);
         
        // short: 
        start = new LinearEntry();
        start.entries =  new Class[]{
                short.class, Short.class,
                int.class, Integer.class, long.class, Long.class,
                BigInteger.class,
                float.class, Float.class,  double.class, Double.class, 
                BigDecimal.class,
                Number.class,Object.class};
        CLASS_DISTANCES.put(short.class,start);
         
        // int: 
        start = new LinearEntry();
        start.entries =  new Class[]{
                int.class, Integer.class, long.class, Long.class,
                BigInteger.class,
                float.class, Float.class,  double.class, Double.class, 
                BigDecimal.class,
                Number.class,Object.class};
        CLASS_DISTANCES.put(int.class,start);
         
        // long: 
        start = new LinearEntry();
        start.entries =  new Class[]{
                long.class, Long.class,
                BigInteger.class,
                float.class, Float.class,  double.class, Double.class, 
                BigDecimal.class,
                Number.class,Object.class};
        CLASS_DISTANCES.put(long.class,start);
         
        // Biginteger: 
        start = new LinearEntry();
        start.entries =  new Class[]{
                BigInteger.class,
                float.class, Float.class,  double.class, Double.class, 
                BigDecimal.class,
                Number.class,Object.class};
        CLASS_DISTANCES.put(long.class,start);
         
        // float: 
        start = new LinearEntry();
        start.entries =  new Class[]{ 
                byte.class, Byte.class, short.class, Short.class,
                int.class, Integer.class, long.class, Long.class,
                BigInteger.class,
                float.class, Float.class,  double.class, Double.class, 
                BigDecimal.class,
                Number.class,Object.class};
        CLASS_DISTANCES.put(float.class,start);
         
        // double: 
        start = new LinearEntry();
        start.entries =  new Class[]{ 
                double.class, 
                Double.class, BigDecimal.class,
                Number.class,Object.class};
        CLASS_DISTANCES.put(double.class,start);
 
    } 
     
    private static synchronized void popultate(Class clazz) {
        if (CLASS_DISTANCES.get(clazz) != null) return;