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

/**
 * Converts a comma-separated string to a list of integers
 * //from   w w  w . j  a va 2s  .  c om
 * @param indexList the string
 * @return a list of integers
 */
public static List<Integer> parseIntList(final String indexList, final String separator) {
    final List<String> indicesAsString = Arrays.asList(indexList.split(separator));
    final List<Integer> indices = new ArrayList<Integer>();
    for (final String indexAsString : indicesAsString) {
        indices.add(Integer.valueOf(indexAsString));
    }
    return indices;
}

From source file:com.joken.common.utils.ConverterUtils.java

/**
 * ?//from   w  ww  . jav  a 2 s.c om
 * 
 * @param time
 *            :08:30:00
 * @param separator
 *            :
 * @return 
 */
public static Long string2TimeSeconds(String time, String separator) {
    Calendar cl = Calendar.getInstance();
    String[] times = time.split(separator);
    cl.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0]));
    cl.set(Calendar.MINUTE, Integer.valueOf(times[1]));
    cl.set(Calendar.SECOND, Integer.valueOf(times[2]));
    cl.set(Calendar.MILLISECOND, 0);
    return cl.getTimeInMillis() / 1000;
}

From source file:net.bican.wordpress.Main.java

/**
 * @param args execute with "-?" for an explanation of args
 * @throws ParseException When the command line options cannot be parsed
 *//*from  w  ww.  ja  va 2 s  .  c  om*/
public static void main(String[] args) throws ParseException {
    try {
        Options options = new Options();
        options.addOption("?", "help", false, "Print usage information");
        options.addOption("h", "url", true, "Specify the url to xmlrpc.php");
        options.addOption("u", "user", true, "User name");
        options.addOption("p", "pass", true, "Password");
        options.addOption("a", "authors", false, "Get author list");
        options.addOption("s", "slug", true, "Slug for categories");
        options.addOption("pi", "parentid", true, "Parent id for categories");
        options.addOption("oi", "postid", true, "Post id for pages and posts");
        options.addOption("c", "categories", false, "Get category list");
        options.addOption("cn", "newcategory", true, "New category (uses --slug and --parentid)");
        options.addOption("pg", "pages", false, "Get page list (full)");
        options.addOption("pl", "pagelist", false, "Get page list");
        options.addOption("ps", "page", true, "Get page");
        options.addOption("pn", "newpage", true, "New page from file <arg> (needs --publish)");
        options.addOption("pe", "editpage", true, "Edit page (needs --postid and --publish");
        options.addOption("pd", "deletepage", true, "Delete page (needs --publish)");
        options.addOption("l", "publish", true, "Publish status for \"new\" options");
        options.addOption("us", "userinfo", false, "Get user information");
        options.addOption("or", "recentposts", true, "Get recent posts");
        options.addOption("os", "getpost", true, "Get post");
        options.addOption("on", "newpost", true, "New post from file <arg> (needs --publish)");
        options.addOption("oe", "editpost", true, "Edit post (needs --postid and --publish");
        options.addOption("od", "deletepost", true, "Delete post (needs --publish)");
        options.addOption("sm", "supportedmethods", false, "List supported methods");
        options.addOption("st", "supportedfilters", false, "List supported text filters");
        options.addOption("mn", "newmedia", true, "New media file (uses --overwrite)");
        options.addOption("ov", "overwrite", false, "Allow overwrite in uploading new media");
        options.addOption("so", "supportedstatus", false, "Print supported page and post status values");
        options.addOption("cs", "commentstatus", false, "Print comment status names for the blog");
        options.addOption("cc", "commentcount", true, "Get comment count for a post (-1 for all posts)");
        options.addOption("ca", "newcomment", true, "New comment from file");
        options.addOption("cd", "deletecomment", true, "Delete comment");
        options.addOption("ce", "editcomment", true, "Edit comment from file");
        options.addOption("cg", "getcomment", true, "Get comment");
        options.addOption("ct", "getcomments", true, "Get comments for the post");
        options.addOption("cs", "commentstatus", true, "Comment status (for --getcomments)");
        options.addOption("co", "commentoffset", true, "Comment offset # (for --getcomments)");
        options.addOption("cm", "commentnumber", true, "Comment # (for --getcomments)");
        try {
            WpCliConfiguration config = new WpCliConfiguration(args, options, Main.class);
            if (config.hasOption("help")) {
                showHelp(options);
            } else if ((!config.hasOption("url")) || (!config.hasOption("user"))
                    || (!config.hasOption("pass"))) {
                System.err.println("Specify --user, --pass and --url");
            } else {
                try {
                    Wordpress wp = new Wordpress(config.getOptionValue("user"), config.getOptionValue("pass"),
                            config.getOptionValue("url"));
                    if (config.hasOption("authors")) {
                        printList(wp.getAuthors(), Author.class, true);
                    } else if (config.hasOption("categories")) {
                        printList(wp.getCategories(), Category.class, true);
                    } else if (config.hasOption("newcategory")) {
                        String slug = config.getOptionValue("slug");
                        Integer parentId = getInteger("parentid", config);
                        if (slug == null)
                            slug = "";
                        if (parentId == null)
                            parentId = 0;
                        System.out
                                .println(wp.newCategory(config.getOptionValue("newcategory"), slug, parentId));
                    } else if (config.hasOption("pages")) {
                        printList(wp.getPages(), Page.class, false);
                    } else if (config.hasOption("pagelist")) {
                        printList(wp.getPageList(), PageDefinition.class, false);
                    } else if (config.hasOption("page")) {
                        printItem(wp.getPage(getInteger("page", config)), Page.class);
                    } else if (config.hasOption("userinfo")) {
                        printItem(wp.getUserInfo(), User.class);
                    } else if (config.hasOption("recentposts")) {
                        printList(wp.getRecentPosts(getInteger("recentposts", config)), Page.class, false);
                    } else if (config.hasOption("getpost")) {
                        printItem(wp.getPost(getInteger("getpost", config)), Page.class);
                    } else if (config.hasOption("supportedmethods")) {
                        printList(wp.supportedMethods(), String.class, false);
                    } else if (config.hasOption("supportedfilters")) {
                        printList(wp.supportedTextFilters(), String.class, false);
                    } else if (config.hasOption("newpage")) {
                        if (!config.hasOption("publish")) {
                            showHelp(options);
                        } else {
                            System.out.println(
                                    wp.newPage(Page.fromFile(new File(config.getOptionValue("newpage"))),
                                            config.getOptionValue("publish")));
                        }
                    } else if (config.hasOption("editpage")) {
                        edit(options, config, wp, "editpage", true);
                    } else if (config.hasOption("editpost")) {
                        edit(options, config, wp, "editpost", false);
                    } else if (config.hasOption("deletepage")) {
                        delete(options, config, wp, "deletepage", true);
                    } else if (config.hasOption("deletepost")) {
                        delete(options, config, wp, "deletepost", false);
                    } else if (config.hasOption("newpost")) {
                        if (!config.hasOption("publish")) {
                            showHelp(options);
                        } else {
                            System.out.println(
                                    wp.newPost(Page.fromFile(new File(config.getOptionValue("newpost"))),
                                            Boolean.valueOf(config.getOptionValue("publish"))));
                        }
                    } else if (config.hasOption("newmedia")) {
                        String fileName = config.getOptionValue("newmedia");
                        File file = new File(fileName);
                        String mimeType = new MimetypesFileTypeMap().getContentType(file);
                        Boolean overwrite = Boolean.FALSE;
                        if (config.hasOption("overwrite"))
                            overwrite = Boolean.TRUE;
                        MediaObject result = wp.newMediaObject(mimeType, file, overwrite);
                        if (result != null) {
                            System.out.println(result);
                        }
                    } else if (config.hasOption("supportedstatus")) {
                        System.out.println("Recognized status values for posts:");
                        printList(wp.getPostStatusList(), PostAndPageStatus.class, true);
                        System.out.println("\nRecognized status values for pages:");
                        printList(wp.getPageStatusList(), PostAndPageStatus.class, true);
                    } else if (config.hasOption("commentstatus")) {
                        showCommentStatus(wp);
                    } else if (config.hasOption("commentcount")) {
                        showCommentCount(config, wp);
                    } else if (config.hasOption("newcomment")) {
                        editComment(wp, config.getOptionValue("newcomment"), "newcomment");
                    } else if (config.hasOption("editcomment")) {
                        editComment(wp, config.getOptionValue("editcomment"), "editcomment");
                    } else if (config.hasOption("deletecomment")) {
                        System.err.println(Integer.valueOf(config.getOptionValue("deletecomment")));
                        deleteComment(wp, Integer.valueOf(config.getOptionValue("deletecomment")));
                    } else if (config.hasOption("getcomment")) {
                        printComment(wp, Integer.valueOf(config.getOptionValue("getcomment")));
                    } else if (config.hasOption("getcomments")) {
                        Integer postID = Integer.valueOf(config.getOptionValue("getcomments"));
                        String commentStatus = config.getOptionValue("commentstatus");
                        Integer commentOffset;
                        try {
                            commentOffset = Integer.valueOf(config.getOptionValue("commentoffset"));
                        } catch (NumberFormatException e) {
                            commentOffset = null;
                        }
                        Integer commentNumber;
                        try {
                            commentNumber = Integer.valueOf(config.getOptionValue("commentnumber"));
                        } catch (Exception e) {
                            commentNumber = null;
                        }
                        printComments(wp, postID, commentStatus, commentOffset, commentNumber);
                    } else {
                        showHelp(options);
                    }
                } catch (MalformedURLException e) {
                    System.err.println("URL \"" + config.getOptionValue("url") + "\" is invalid, reason is: "
                            + e.getLocalizedMessage());
                } catch (IOException e) {
                    System.err.println("Can't read from file, reason is: " + e.getLocalizedMessage());
                } catch (InvalidPostFormatException e) {
                    System.err.println("Input format is invalid.");
                }
            }
        } catch (ParseException e) {
            System.err.println("Can't process command line arguments, reason is: " + e.getLocalizedMessage());
        }
    } catch (XmlRpcFault e) {
        String reason = e.getLocalizedMessage();
        System.err.println("Operation failed, reason is: " + reason);
    }
}

From source file:Main.java

/**
   Return the value of an attribute of a node as an integer number
   or <code>null</code> if the attribute is not present.
 *///from w  w w.ja va 2 s.co  m
static public Integer getIntegerAttribute(Node node, String att_name) {
    if (node == null)
        return null;
    String text = getText(node.getAttributes().getNamedItem(att_name));
    if (text == null)
        return null;
    return Integer.valueOf(text);
}

From source file:com.intuit.tank.harness.functions.MonetaryFunctions.java

/**
 * Process the numeric request//w w  w  .j  ava 2  s .c  o  m
 * 
 * @param values
 *            The command line
 * @return The requested value; "" if there was an error
 */
public static String executeFunction(String[] values) {
    try {
        if (values[2].equalsIgnoreCase("randompositive"))
            return MonetaryFunctions.randomPositiveMonetary(Integer.valueOf(values[3]));
        else if (values[2].equalsIgnoreCase("randomnegative"))
            return MonetaryFunctions.randomNegativeMonetary(Integer.valueOf(values[3]));
        return "";
    } catch (Exception ex) {
        return "";
    }
}

From source file:Main.java

/**
 * //from www  .  jav a2 s  .  c  om
 * @param value
 * @return int[]
 */
public static int[] toIntArray(final String value) {
    if (value == null) {
        return new int[] {};
    }

    final String strippedValue = value.replace(ARRAY_OPEN_TAG, EMPTY_STRING).replace(ARRAY_CLOSE_TAG,
            EMPTY_STRING);
    final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR);
    final Collection<Integer> intCollection = new ArrayList<>();

    while (tokenizer.hasMoreTokens()) {
        intCollection.add(Integer.valueOf(tokenizer.nextToken().trim()));
    }

    return toIntArray(intCollection);
}

From source file:com.common.server.AppLicenceUtil.java

public static int videoCount() throws Exception {

    Map map = getLicence();/*ww  w.j  a v a  2  s. c o  m*/
    String videoCount = (String) map.get("videoCount");
    if (videoCount != null) {

        int count = Integer.valueOf(videoCount).intValue();
        return count;

    } else
        return 0;
}

From source file:com.billing.ng.crypto.util.PasswordUtils.java

public static Integer getSaltLength() {
    if (saltLength == null) {
        String prop = System.getProperty("crypto.hash.salt_length", "256");
        saltLength = StringUtils.isNotBlank(prop) ? Integer.valueOf(prop) : 256;
    }/*w ww. ja va2 s.  co m*/
    return saltLength;
}

From source file:Main.java

/**
 * Decodes a String into an object of the specified type. If the object
 * type is not supported, null will be returned.
 *
 * @param type the type of the property.
 * @param value the encode String value to decode.
 * @return the String value decoded into the specified type.
 * @throws Exception If decoding failed due to an error.
 *//*from ww  w .  j  av  a2s.  c  o  m*/
private static Object decode(Class type, String value) throws Exception {
    if (type.getName().equals("java.lang.String")) {
        return value;
    }
    if (type.getName().equals("boolean")) {
        return Boolean.valueOf(value);
    }
    if (type.getName().equals("int")) {
        return Integer.valueOf(value);
    }
    if (type.getName().equals("long")) {
        return Long.valueOf(value);
    }
    if (type.getName().equals("float")) {
        return Float.valueOf(value);
    }
    if (type.getName().equals("double")) {
        return Double.valueOf(value);
    }
    if (type.getName().equals("java.lang.Class")) {
        return Class.forName(value);
    }
    return null;
}

From source file:Main.java

/**
 * Convert string format date data to whooing date format integer
 * @param   dateStr     Date data formatted string like "05/21"
 * @return   Return whooing style integer date like 20121212 otherwise -1
 * *///  ww  w  .  j a v a2s.co m
static public int convertWhooingDate(String dateStr) {
    String convertDate = dateStr.replace("/", "");
    if (convertDate.length() == 3) {
        convertDate = "0" + convertDate;
    }
    Calendar rightNow = Calendar.getInstance();

    int year = rightNow.get(Calendar.YEAR);
    int month = rightNow.get(Calendar.MONTH) + 1;
    int day = rightNow.get(Calendar.DAY_OF_MONTH);

    int today = year * 10000 + month * 100 + day;
    convertDate = year + convertDate;
    int convertDateInt = 0;
    try {
        convertDateInt = Integer.valueOf(convertDate);
        // In case of receiving message 12/31 on 1 Jan
        if ((today / 10000) < (convertDateInt / 10000)) {
            convertDateInt -= 10000;
        }

    } catch (NumberFormatException e) {
        e.printStackTrace();
    }

    //guard wrong date
    if (convertDateInt < ((year * 10000) + 101)) {
        convertDateInt = today;
    }
    return convertDateInt;
}