Example usage for java.lang Integer valueOf

List of usage examples for java.lang Integer valueOf

Introduction

In this page you can find the example usage for java.lang Integer valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Integer valueOf(int i) 

Source Link

Document

Returns an Integer instance representing the specified int value.

Usage

From source file:Main.java

public static int getTagIntData(String xmlStr, String xmlRoot) {
    String tags[] = getTagDataArray(xmlStr, xmlRoot);
    if (tags.length > 0) {
        String intStr = tags[0];//from  w ww . j a  va2 s  .c  o m
        return (Integer.valueOf(intStr)).intValue();
    }
    return 0;
}

From source file:Main.java

public static Bitmap createIdenticon(byte[] hash, int background) {
    Bitmap identicon = Bitmap.createBitmap(5, 5, Bitmap.Config.ARGB_8888);

    float[] hsv = { Integer.valueOf(hash[3] + 128).floatValue() * 360.0f / 255.0f, 0.8f, 0.8f };
    int foreground = Color.HSVToColor(hsv);

    for (int x = 0; x < 5; x++) {
        //Enforce horizontal symmetry
        int i = x < 3 ? x : 4 - x;
        for (int y = 0; y < 5; y++) {
            int pixelColor;
            //toggle pixels based on bit being on/off
            if ((hash[i] >> y & 1) == 1)
                pixelColor = foreground;
            else//w  w w. j  ava  2 s.  co  m
                pixelColor = background;
            identicon.setPixel(x, y, pixelColor);
        }
    }

    Bitmap bmpWithBorder = Bitmap.createBitmap(48, 48, identicon.getConfig());
    Canvas canvas = new Canvas(bmpWithBorder);
    canvas.drawColor(background);
    identicon = Bitmap.createScaledBitmap(identicon, 46, 46, false);
    canvas.drawBitmap(identicon, 1, 1, null);

    return bmpWithBorder;
}

From source file:Main.java

/**
 * convert a string to integer.//w  w  w . java2  s. c om
 * <p>
 * null => defaultValue<br/> "abc" => defaultValue<br/> "123" => 123<br/> "
 * 123 " => 123<br/> "1,234,567" => 1234567<br/>
 * </p>
 * 
 * @param str
 * @param defaultValue
 * @return a int value or <code>defaultValue</code> if cant convert.
 */
public static Integer convertStrToInteger(Object str, Integer defaultValue) {
    if (null == str) {
        return defaultValue;
    }
    try {
        String s = str.toString().replace(",", "");
        return Integer.valueOf(s.trim());
    } catch (Exception e) {
        return defaultValue;
    }
}

From source file:com.github.tomakehurst.wiremock.admin.Conversions.java

public static Integer toInt(QueryParameter parameter) {
    return parameter.isPresent() ? Integer.valueOf(parameter.firstValue()) : null;
}

From source file:PrimitiveUtils.java

public static Object read(String value, Class type) {
    Object ret = value;//from   w w w  .  ja  v  a 2s . c om
    if (Integer.TYPE.equals(type)) {
        ret = Integer.valueOf(value);
    }
    if (Byte.TYPE.equals(type)) {
        ret = Byte.valueOf(value);
    }
    if (Short.TYPE.equals(type)) {
        ret = Short.valueOf(value);
    }
    if (Long.TYPE.equals(type)) {
        ret = Long.valueOf(value);
    }
    if (Float.TYPE.equals(type)) {
        ret = Float.valueOf(value);
    }
    if (Double.TYPE.equals(type)) {
        ret = Double.valueOf(value);
    }
    if (Boolean.TYPE.equals(type)) {
        ret = Boolean.valueOf(value);
    }
    if (Character.TYPE.equals(type)) {
        ret = value.charAt(0);
    }
    // TODO others.
    return ret;
}

From source file:nl.ctrlaltdev.harbinger.testutil.TestUtil.java

public static final void resetMockHttpSessionId() {
    try {/*from ww  w.ja  v a2s. co m*/
        Field nextId = MockHttpSession.class.getDeclaredField("nextId");
        nextId.setAccessible(true);
        nextId.set(null, Integer.valueOf(1));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static int getEmulatorPort(String serial) {
    if (serial == null) {
        return 0;
    }/*from   w w w . j  a v a2 s  .  c  o  m*/

    int stringSize = serial.length();
    String lastFourNumbers = serial.substring(stringSize - 4, stringSize);

    int port = 0;

    try {
        port = Integer.valueOf(lastFourNumbers);
    } catch (NumberFormatException e) {
        // do nothing (this should not happen)
    }
    return port;
}

From source file:Main.java

public static int bcdToInt(byte[] input, int offset, int len, boolean padLeft) {
    String intStr = bcd2str(input, offset, len, padLeft);
    return Integer.valueOf(intStr);
}

From source file:Main.java

/**
 * Extracts a list of integer values from the specified attribute.
 * @param element        the element to fetch the integer list from
 * @param attributeName  the name of the attribute containing the integer list
 * @return a list of integer values from the specified attribute
 *//*  www.  j  a  v  a  2s.  c o  m*/
public static List<Integer> getIntegerListAttribute(Element element, String attributeName) {
    String intListString = element.getAttribute(attributeName);
    if (intListString == null || intListString.length() == 0) {
        return Collections.emptyList();
    }

    String[] intStrings = intListString.split(" "); //$NON-NLS-1$

    List<Integer> intValues = new ArrayList<Integer>(intStrings.length);
    for (String intString : intStrings) {
        Integer intValue = Integer.valueOf(intString);
        intValues.add(intValue);
    }
    return intValues;
}

From source file:Main.java

/**
 * Activities on Android are invoked with a Uri string.  This method captures and returns the last bit of this Uri
 * which it assumes to be a numeric ID of the current article/announcements etc.
 * @return/*from   w  w w .  ja  v a  2s  . c  om*/
 */
public static int filterIdFromUri(Uri uri) {
    String id = uri.getLastPathSegment();

    return Integer.valueOf(id);
}