Example usage for java.lang Integer Integer

List of usage examples for java.lang Integer Integer

Introduction

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

Prototype

@Deprecated(since = "9")
public Integer(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Integer object that represents the int value indicated by the String parameter.

Usage

From source file:Main.java

public static Date getDateObj(String argsDate, String split) {
    String[] temp = argsDate.split(split);
    int year = new Integer(temp[0]).intValue();
    int month = new Integer(temp[1]).intValue();
    int day = new Integer(temp[2]).intValue();
    return getDateObj(year, month, day);
}

From source file:Main.java

/**
 * @param el an Element//from   w  ww .jav a2  s  .  c  o m
 * @return the ordinal position 1..N of this element amongst its sibling
 * elements (of any name), as a String; 
 * or '0' if the element has no parent
 */
public static String ordinalPosition(Element el) {
    String position = "0";
    Node parent = el.getParentNode();
    if (parent instanceof Element) {
        int pos = 0;
        NodeList nl = ((Element) parent).getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node n = nl.item(i);
            if (n instanceof Element)
                pos++;
            if (n.equals(el))
                position = new Integer(pos).toString();
        }
    }
    return position;
}

From source file:Main.java

static void serialize(Document document, Writer writer) {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    transformerFactory.setAttribute("indent-number", new Integer(4));
    try {/*w ww .ja  v  a  2s  .c om*/
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        StreamResult result = new StreamResult(writer);
        transformer.transform(new DOMSource(document), result);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Map getIndexMap(List list) {
    Map indexes = new HashMap();
    int index = 0;
    for (Iterator it = list.iterator(); it.hasNext();) {
        indexes.put(it.next(), new Integer(index++));
    }//from   w w  w . j av a  2s  .c om
    return indexes;
}

From source file:Main.java

/**
 *
 * @param doc Document//from w  ww .j a  v  a2  s  . com
 * @param parent Node
 * @param name String
 * @param value int
 * @return Element
 */
public static Element appendChildNodeCDATA(Document doc, Node parent, String name, int value) {
    Element child = doc.createElement(name);
    child.appendChild(doc.createCDATASection(new Integer(value).toString()));
    parent.appendChild(child);
    return child;
}

From source file:Main.java

/** Write an XML DOM tree to a file
 *
 * @param doc the document to write//ww w  . j  a va  2s .c  om
 * @param file the file to write to
 * @throws IOException if a file I/O error occurs
 */
public static void write(Document doc, File file) throws IOException {
    try {
        DOMSource domSource = new DOMSource(doc);
        FileOutputStream stream = new FileOutputStream(file);
        // OutputStreamWriter works around indent bug 6296446 in JDK
        // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6296446
        StreamResult streamResult = new StreamResult(new OutputStreamWriter(stream));
        TransformerFactory tf = TransformerFactory.newInstance();
        tf.setAttribute("indent-number", new Integer(2));
        Transformer serializer = tf.newTransformer();
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.transform(domSource, streamResult);
    } catch (TransformerException e) {
        // This exception is never thrown, treat as fatal if it is
        throw new RuntimeException(e);
    }
}

From source file:Main.java

/**
 * Get int from the JTextField input//from  w  ww .j a  va2s  . c o m
 * 
 * @param input the JTextField object
 * @return the int number
 */
public static int getInt(javax.swing.JTextField input) throws Exception {
    return new Integer(input.getText()).intValue();
}

From source file:Main.java

public static Object getPropertyValue(Element element) {
    NamedNodeMap map = element.getAttributes();
    map.removeNamedItem(NAME_ATTR);/* ww w  .j av a 2  s . c  o  m*/

    if (map.item(0).getNodeName().equals(STRING_ATTR))
        return map.item(0).getNodeValue();
    else if (map.item(0).getNodeName().equals(INTEGER_ATTR))
        return new Integer(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(DOUBLE_ATTR))
        return new Double(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(FLOAT_ATTR))
        return new Float(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(BOOLEAN_ATTR))
        return Boolean.valueOf(map.item(0).getNodeValue());
    else if (map.item(0).getNodeName().equals(COLOR_ATTR)) {
        String[] rgb = map.item(0).getNodeValue().split(",");
        return new Color(new Integer(rgb[0]), new Integer(rgb[1]), new Integer(rgb[2]));
    } else if (map.item(0).getNodeName().equals(FONT_ATTR)) {
        String[] font = map.item(0).getNodeValue().split(",");
        return new Font(font[0], new Integer(font[1]), new Integer(font[2]));
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * convert str to an int. Return defaultValue number if empty. 
 * //from   w w  w  . ja  va2s .  c  o  m
 * @param str input string
 * @return the number
 */
public static int getInt(String str, int defaultValue) {
    try {
        return new Integer(str.trim()).intValue();
    } catch (Exception e) {
        return defaultValue;
    }
}

From source file:Main.java

private static void addNumberToBase(StringBuffer base, boolean bracketed, HashSet<Integer> set) {
    if (set.size() > 0) {
        // Limit on the number of auto-generated item numbers to check for
        int limit = 100;
        // Check the set for the numbers encountered and generate the 
        // lowest number accordingly
        if (set.contains(new Integer(0)) == false) {
            // Use base
        } else {/*  w  w  w  .java  2  s  .  com*/
            for (int x = 1; x < limit; x++) {
                // Check if the number was already used to auto-generate an
                // existing item
                if (set.contains(new Integer(x)) == false) {
                    if (bracketed)
                        base.append(" ("); //$NON-NLS-1$
                    base.append(x);
                    if (bracketed)
                        base.append(")"); //$NON-NLS-1$
                    break;
                }
            }
        }
    }
}