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 Integer getCurrentLevelAttributeIntValue(Element ele, String attribute) {
    Integer attributeInt = null;//from   w  ww. j  av  a  2 s  . co  m
    if (ele == null || attribute == null) {
        return attributeInt;
    }
    String attributeString = ele.getAttribute(attribute);
    if (attributeString != null) {
        attributeInt = new Integer(attributeString);
    }
    return attributeInt;
}

From source file:Platform.java

/**
 * Unmaximizes the specified Frame.//from   w w  w. j  a  va  2 s  .  co  m
 */
public static void unmaximize(Frame f) {
    if (!isJRE13) {
        try {
            Method m1 = Frame.class.getMethod("getExtendedState", (Class[]) null);
            Method m2 = Frame.class.getMethod("setExtendedState", new Class[] { Integer.TYPE });
            int i = ((Integer) m1.invoke(f, (Object[]) null)).intValue();
            m2.invoke(f, new Object[] { new Integer(i & ~6) });
        } catch (java.lang.reflect.InvocationTargetException ite) {
        } catch (NoSuchMethodException nsme) {
        } catch (IllegalAccessException iae) {
        }
    }
}

From source file:Main.java

public static Object getPropertyValue(Element element) {
    NamedNodeMap map = element.getAttributes();
    map.removeNamedItem(NAME_ATTR);//from   w  w  w . jav  a2 s . c  om

    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

/**
 * Calculates the average, and returns it in the correct class.
 * @param numbers/* w  w  w.j  av  a  2 s  .c  om*/
 */
static Number average(Number[] numbers) {
    Number sum = sum(numbers);

    return divide(sum, new Integer(numbers.length));
}

From source file:Main.java

public static synchronized SAXParser getSAXParser() {

    if (!stack.empty())
        return (SAXParser) stack.pop();
    try {//from  w  w w . j a  va2 s  .com
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        reader.setProperty("http://apache.org/xml/properties/input-buffer-size", new Integer(8192));
        return parser;
    } catch (Exception exc) {
        System.err.println("Error attempting to initialize SAXParserFactory: " + exc);
        exc.printStackTrace();
        return null;
    }
}

From source file:org.restsql.core.impl.SqlUtils.java

public static Object getObjectByColumnLabel(final ColumnMetaData column, final SqlRowSet resultSet) {
    Object value = null;// w  w w  .j a  va2 s  .  c o  m
    if (column.getColumnType() == Types.DATE && column.getColumnTypeName().equals("YEAR")) {
        value = new Integer(resultSet.getInt(column.getColumnLabel()));
        if (resultSet.wasNull()) {
            value = null;
        }
    } else {
        value = resultSet.getObject(column.getColumnLabel());
    }

    return value;
}

From source file:Main.java

public static ContentValues listToContentValues(List<String> values, String type) {
    ContentValues contentvalues = new ContentValues();

    //Place values into contentvalue structure
    for (int i = 0; i < values.size(); i++) {
        String current = values.get(i);

        try {/* w ww .j a va  2 s  . c o m*/
            //Separate the value by = in order to get key:value
            Integer indexOfEquals = current.indexOf("=");
            String key = current.substring(0, indexOfEquals);
            String value = current.substring(indexOfEquals + 1);

            if (type.toUpperCase().equals("STRING"))
                contentvalues.put(key, value);

            if (type.toUpperCase().equals("BOOLEAN"))
                contentvalues.put(key, Boolean.valueOf(value));

            if (type.toUpperCase().equals("INTEGER"))
                contentvalues.put(key, new Integer(value));

            if (type.toUpperCase().equals("DOUBLE"))
                contentvalues.put(key, new Double(value));

            if (type.toUpperCase().equals("FLOAT"))
                contentvalues.put(key, new Float(value));

            if (type.toUpperCase().equals("LONG"))
                contentvalues.put(key, new Long(value));

            if (type.toUpperCase().equals("SHORT"))
                contentvalues.put(key, new Short(value));
        } catch (Exception e) {
            Log.e("mercury", "Error with argument " + current);
        }

    }

    return contentvalues;
}

From source file:Main.java

public static Integer getCurrentLevelIntValue(Element ele, String tagName) {
    String textToInt = getCurrentLevelTextValue(ele, tagName);
    Integer valueInteger = null;/*w w  w  .ja v  a  2s. c  om*/
    if (textToInt != null) {
        valueInteger = new Integer(textToInt);
    }
    return valueInteger;
}

From source file:Main.java

public static Point positionToClickPoint(Container component, int caretPosition, Container invokedIn) {
    if (component == null) {
        return null;
    }// w w  w.j av  a  2s.  co m

    //System.err.println("Checking: " + component.getClass().getName());
    if (component.getClass().getName().indexOf("EditorPane") >= 0) {
        try {
            java.lang.reflect.Method pointGetter = component.getClass().getMethod("modelToView",
                    new Class[] { Integer.TYPE });
            Rectangle rec = (Rectangle) pointGetter.invoke(component,
                    new Object[] { new Integer(caretPosition) });
            //System.err.println("Before: " + (int)rec.getY());
            // FIXME: somehow it fails here to convert point from scrollable component
            Point point = SwingUtilities.convertPoint(component, (int) rec.getX(), (int) rec.getY() + 10,
                    invokedIn);
            // FIXME: ugly hack :(
            if (point.getY() > 1024) {
                point = new Point((int) point.getX(), 250);
            }
            //System.err.println("After: " + (int)point.getY());
            return point;
        } catch (Exception e) {
            System.err.println("Method invocation exception caught");
            e.printStackTrace();

            //FIXME: BUG
            return null;
            //throw new RuntimeException("Method invocation exception caught");
        }
    }

    for (int i = 0; i < component.getComponentCount(); i++) {
        java.awt.Component childComponent = component.getComponent(i);
        if (childComponent instanceof javax.swing.JComponent) {
            Point point = positionToClickPoint((javax.swing.JComponent) childComponent, caretPosition,
                    invokedIn);
            if (point != null) {
                return point;
            }
        }
    }

    return null;
}

From source file:Main.java

/**
 * Takes a number of tags of name 'name' that are children of 'root', and
 * looks for attributes of 'attrib' on them.  Converts attributes to an
 * int and returns in an array.//from  ww  w .  ja  va  2s . c  o  m
 */
public static int[] getElementArrayInt(Element root, String name, String attrib) {
    if (root == null)
        return null;

    NodeList nl = root.getChildNodes();
    LinkedList<Integer> elementCache = new LinkedList<Integer>();
    int size = nl.getLength();

    for (int i = 0; i < size; i++) {
        Node node = nl.item(i);
        if (!(node instanceof Element))
            continue;
        Element ele = (Element) node;
        if (!ele.getTagName().equals(name))
            continue;

        String valS = ele.getAttribute(attrib);
        int eleVal = 0;
        try {
            eleVal = Integer.parseInt(valS);
        } catch (Exception e) {
        }

        elementCache.addLast(new Integer(eleVal));
    }

    int[] retArr = new int[elementCache.size()];
    Iterator<Integer> it = elementCache.iterator();
    int idx = 0;
    while (it.hasNext()) {
        retArr[idx++] = it.next().intValue();
    }

    return retArr;
}