Java Number Value Of valueOf(boolean b)

Here you can find the source of valueOf(boolean b)

Description

value Of

License

Open Source License

Declaration

public static Boolean valueOf(boolean b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final Byte[] byteCache = new Byte[-(-128) + 127 + 1];
    private static final Character[] charCache = new Character[127 + 1];
    private static final Integer[] intCache = new Integer[-(-128) + 127 + 1];
    private static final Short[] shortCache = new Short[-(-128) + 127 + 1];
    private static final Long[] longCache = new Long[-(-128) + 127 + 1];

    public static Byte valueOf(byte b) {
        final int offset = 128;
        return byteCache[(int) b + offset];
    }//from  ww w .j a v  a  2  s .  co  m

    public static Boolean valueOf(boolean b) {
        return (b ? Boolean.TRUE : Boolean.FALSE);
    }

    public static Character valueOf(char c) {
        if (c <= 127) {
            return charCache[(int) c];
        }
        return new Character(c);
    }

    public static Integer valueOf(int i) {
        final int offset = 128;
        if (i >= -128 && i <= 127) {
            return intCache[i + offset];
        }
        return new Integer(i);
    }

    public static Short valueOf(short s) {
        final int offset = 128;
        int sAsInt = s;
        if (sAsInt >= -128 && sAsInt <= 127) {
            return shortCache[sAsInt + offset];
        }
        return new Short(s);
    }

    public static Long valueOf(long l) {
        final int offset = 128;
        if (l >= -128 && l <= 127) {
            return longCache[(int) l + offset];
        }
        return new Long(l);
    }

    public static Float valueOf(float f) {
        return new Float(f);
    }

    public static Double valueOf(double d) {
        return new Double(d);
    }
}

Related

  1. valueOf(boolean b)
  2. valueOf(Boolean b)
  3. valueOf(Boolean bool)
  4. valueOf(boolean flag)
  5. valueOf(boolean tmp)
  6. valueOf(Boolean value)