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 String getMaxId(List<String> ids) {
    String oozieId = ids.get(0);//from  ww w  . ja  v a  2  s  .co m
    int maxInt = Integer.valueOf(oozieId.split("-")[0]);
    for (int i = 1; i < ids.size(); i++) {
        String currentId = ids.get(i);
        int currInt = Integer.valueOf(currentId.split("-")[0]);
        if (currInt > maxInt) {
            oozieId = currentId;
        }
    }
    return oozieId;
}

From source file:Main.java

public static boolean getBoundaryLevel(Point bound) {
    if (mLevelSet == null)
        mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET,
                null);//from  ww  w .  j ava 2s  .  c o m
    if (mLevelSet != null) {
        ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet));
        Collections.sort(array, mComparator);
        bound.x = Integer.valueOf(array.get(0));
        bound.y = Integer.valueOf(array.get(array.size() - 1));
        return true;
    }
    return false;
}

From source file:Main.java

/**
 * This one is tricky, You first obtain a String cursor of the Iterator of
 * Users, then you check if It have current, while true we invoke another
 * function called "getCurrentName" which returns the name of the user, then
 * I call advance function for the cursor to move forward, and invoke
 * haveCurrent again and assign it to the same boolean I entered the while
 * with (In order to get out of it!)/*from  w w w.ja  va 2  s.  c  o m*/
 *
 */
public static List<String> getListOfUsers() throws RuntimeException {
    try {
        List<String> allUsers = new ArrayList<String>();

        String cursor = (String) connection.invoke(defaultAuthenticator, "listUsers",
                new Object[] { "*", Integer.valueOf(9999) },
                new String[] { "java.lang.String", "java.lang.Integer" });

        boolean haveCurrent = ((Boolean) connection.invoke(defaultAuthenticator, "haveCurrent",
                new Object[] { cursor }, new String[] { "java.lang.String" })).booleanValue();

        while (haveCurrent) {
            String currentName = (String) connection.invoke(defaultAuthenticator, "getCurrentName",
                    new Object[] { cursor }, new String[] { "java.lang.String" });

            allUsers.add(currentName);
            connection.invoke(defaultAuthenticator, "advance", new Object[] { cursor },
                    new String[] { "java.lang.String" });

            haveCurrent = ((Boolean) connection.invoke(defaultAuthenticator, "haveCurrent",
                    new Object[] { cursor }, new String[] { "java.lang.String" })).booleanValue();
        }

        return allUsers;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

/**
 * Method for parsing raw IP Address string.
 * @param fullIpAddress Raw IP Address./* w  w  w  .j a  va2s  . co  m*/
 * @return Correct IP Address.
 */
public static String getProperIpAddress(String fullIpAddress) {
    /* IP address is stored in format: xxx.xxx.xxx.xxx for correct sorting. */
    String[] ipAddressArray = fullIpAddress.split("\\.");
    String part1 = String.valueOf(Integer.valueOf(ipAddressArray[0]));
    String part2 = String.valueOf(Integer.valueOf(ipAddressArray[1]));
    String part3 = String.valueOf(Integer.valueOf(ipAddressArray[2]));
    String part4 = String.valueOf(Integer.valueOf(ipAddressArray[3]));
    return part1 + "." + part2 + "." + part3 + "." + part4;
}

From source file:ImageUtil.java

/**
 * returns a dimension where width and height are inside the bounds of the
 * maxWidth and maxHeight parameters<br>
 * and the aspect ratio is the same as sourceWidth and sourceHeight.
 * /*from  w  ww.j a  v a 2  s  .  c o  m*/
 * @param maxWidth
 *            the maximum width of the target dimension
 * @param maxHeight
 *            the maximum height of the target dimension
 * @param sourceWidth
 *            the widht of the source image
 * @param sourceHeight
 *            the height of the source image
 * @return the target dimension that will be the greatest dimension that
 *         <ul>
 *         <li>will keep the ratio of the source images dimension</li>
 *         <li>fits in the bounds of the maximum dimension given</li>
 *         </ul>
 */
public static Dimension scaleDimensions(int maxWidth, int maxHeight, int sourceWidth, int sourceHeight) {
    float vidH, vidW, maxH, maxW;
    vidW = Integer.valueOf(sourceWidth).floatValue();
    vidH = Integer.valueOf(sourceHeight).floatValue();
    maxW = Integer.valueOf(maxWidth).floatValue();
    maxH = Integer.valueOf(maxHeight).floatValue();

    //        System.out.println("initial height / width ratio: " + vidH / vidW);
    //        System.out.println();
    //        System.out.println("vidW "+vidW+", vidH "+vidH);
    //        System.out.println("maxW "+maxW+", maxH "+maxH);
    //        System.out.println();

    float finalW, finalH;
    finalH = vidH / vidW * maxW;
    finalW = maxW;

    if (finalH > maxH) {
        float factor = maxH / finalH;
        finalH = maxH;
        finalW = finalW * factor;
    }

    int w = Float.valueOf(finalW).intValue();
    int h = Float.valueOf(finalH).intValue();

    Dimension d = new Dimension(w, h);

    //        System.out.println();
    //        System.out.println("finalW "+finalW+", finalH "+finalH);
    //        System.out.println("final height / width ratio: " + finalH / finalW);
    //        System.out.println();
    //        System.out.println(d);

    return d;
}

From source file:Main.java

/**
 * Get the value of the specified attribute as an integer. If the element has no attribute by the specified name, 0
 * is returned./* www  . j a  v  a2  s  .  co m*/
 * 
 * @param root The element.
 * @param attrName The attribute name.
 * @return The value of the attribute, if it exists, 0 otherwise.
 */
public static int getAttrInt(Element root, String attrName) {
    if (root.hasAttribute(attrName))
        return Integer.valueOf(root.getAttribute(attrName)).intValue();
    return 0;
}

From source file:com.hp.autonomy.iod.client.RestAdapterFactory.java

public static RestAdapter getRestAdapter(final boolean withInterceptor, final Endpoint endpoint) {
    final HttpClientBuilder builder = HttpClientBuilder.create();

    final String proxyHost = System.getProperty("hp.iod.https.proxyHost");

    if (proxyHost != null) {
        final Integer proxyPort = Integer.valueOf(System.getProperty("hp.iod.https.proxyPort", "8080"));
        builder.setProxy(new HttpHost(proxyHost, proxyPort));
    }/*  w  w  w  .  ja v a 2  s.  c o  m*/

    final RestAdapter.Builder restAdapterBuilder = new RestAdapter.Builder().setEndpoint(endpoint.getUrl())
            .setClient(new ApacheClient(builder.build())).setConverter(new IodConverter())
            .setErrorHandler(new IodErrorHandler());

    if (withInterceptor) {
        restAdapterBuilder.setRequestInterceptor(new ApiKeyRequestInterceptor(endpoint.getApiKey()));
    }

    return restAdapterBuilder.build();
}

From source file:Main.java

/**
 * Converts an array of ints to array of Integers
 *//*from www. ja  v  a  2 s  .c  o m*/
public static Integer[] toIntegerArray(int array[]) {
    Integer newArray[] = new Integer[array.length];
    for (int i = 0; i < array.length; i++)
        newArray[i] = Integer.valueOf(array[i]);
    return newArray;
}

From source file:Main.java

/**
 * //from   w w  w  .  j a va  2s  .  c o  m
 * @param version1
 * @param version2
 * @return 0 if equals, 1 if version1 > version2, -1 if version1 < version2
 */
public static int compareVersion(String version1, String version2) {
    if (version1 == null || version1.length() == 0 || version1.equals("null") || version1.contains("string")
            || version2 == null || version2.length() == 0 || version2.equals("null")
            || version2.contains("string")) {
        // invalid version, can not compare
        return 0;
    }
    if (version1.equals(version2)) {
        // version equals
        return 0;
    } else {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        int l = v1.length;
        if (v2.length < l) {
            l = v2.length;
        }
        if (l > 0) {
            for (int i = 0; i < l; i++) {
                try {
                    int int1 = Integer.valueOf(v1[i]);
                    int int2 = Integer.valueOf(v2[i]);
                    if (int1 > int2) {
                        return 1;
                    } else if (int1 < int2) {
                        return -1;
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                    if (v1[i].compareToIgnoreCase(v2[i]) < 0) {
                        return -1;
                    } else if (v1[i].compareToIgnoreCase(v2[i]) > 0) {
                        return 1;
                    }
                }
            }
            return 0;
        } else {
            // invalid version, can not compare
            return 0;
        }
    }
}

From source file:Main.java

public static Integer getIntegerValue(Element integerElement) throws NumberFormatException {
    String elementValue = getTextContent(integerElement);
    return Integer.valueOf(elementValue);
}