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

protected Object doInBackground() throws Exception {
    Integer result = new Integer(0);
    for (int i = 0; i < 10; i++) {
        result += i * 10;//w  w w. j  a  va2  s.c  o m
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return result;
}

From source file:Main.java

private static ArrayList<ArrayList> sortObjectArrayListSimpleMaster(ArrayList listIn, String paramName) {
    ArrayList<ArrayList> answer = new ArrayList<ArrayList>();
    ArrayList newList = new ArrayList();
    ArrayList<Integer> indices = new ArrayList<Integer>();
    try {//from  w  w  w.  j  av  a 2  s . c o m
        if (listIn.size() > 0) {
            Class<?> c = listIn.get(0).getClass();
            Field f = c.getDeclaredField(paramName);
            f.setAccessible(true);
            Class<?> t = f.getType();
            Double dd = new Double(14);
            Float ff = new Float(14);
            Integer ii = new Integer(14);
            Map sortedPos = new LinkedHashMap();
            Map sortedNeg = new LinkedHashMap();
            Map unsorted = new LinkedHashMap();
            int indexCount = 0;
            long count = 0;
            if (t.isPrimitive()) {
                for (Object thisObj : listIn) {
                    Object o = f.get(thisObj);
                    double d = 0;
                    if (t.getName().equals("char")) {
                        d = (int) ((Character) o);
                    } else if (t.isInstance(dd))
                        d = (Double) o;
                    else if (t.isInstance(ff))
                        d = (Float) o;
                    else if (t.isInstance(ii))
                        d = (Integer) o;
                    else
                        d = new Double(o.toString());

                    boolean isNegative = false;

                    if (d < 0) {
                        isNegative = true;
                        d = Math.abs(d);
                    }

                    String format = "%1$30f";
                    String newKey = String.format(format, d);
                    String format2 = "%1$20d";
                    String countString = String.format(format2, count);
                    newKey += "-" + countString;
                    if (isNegative) {
                        sortedNeg.put(newKey, thisObj);
                    } else {
                        sortedPos.put(newKey, thisObj);
                    }
                    unsorted.put(thisObj, indexCount);
                    count++;
                    indexCount++;
                }
                TreeMap<String, Object> resultPos = new TreeMap();
                resultPos.putAll(sortedPos);
                sortedPos = resultPos;
                TreeMap<String, Object> resultNeg = new TreeMap();
                resultNeg.putAll(sortedNeg);
                sortedNeg = resultNeg;
            } else if (t.isInstance(paramName)) {
                // System.out.println("is a string with value " + o);
                for (Object thisObj : listIn) {
                    String key = (String) (f.get(thisObj));
                    sortedPos.put(key + "-" + count, thisObj);
                    unsorted.put(thisObj, indexCount);
                    count++;
                    indexCount++;
                }
                TreeMap<String, Object> result = new TreeMap(String.CASE_INSENSITIVE_ORDER);
                result.putAll(sortedPos);
                sortedPos = result;
            }

            Iterator itNeg = sortedNeg.entrySet().iterator();
            while (itNeg.hasNext()) {
                Map.Entry pairs = (Map.Entry) itNeg.next();
                newList.add(pairs.getValue());
                itNeg.remove();
            }

            Collections.reverse(newList);

            Iterator itPos = sortedPos.entrySet().iterator();
            while (itPos.hasNext()) {
                Map.Entry pairs = (Map.Entry) itPos.next();
                Object obj = pairs.getValue();
                newList.add(obj);
                indices.add((Integer) unsorted.get(obj));
                itPos.remove();
            }
        }
    } catch (Exception e) {
        System.out
                .println("problem sorting list.  listIn.size(): " + listIn.size() + " and param: " + paramName);
        answer.add(newList);
        answer.add(indices);
        return answer;
    }
    answer.add(newList);
    answer.add(indices);
    return answer;
}

From source file:com.sharmila.hibernatespringsecurity.dao.impl.UserRolesDaoImpl.java

@Override
public void delete(int id) {
    session = sessionFactory.openSession();
    transaction = session.beginTransaction();
    UserRoles userRoles = (UserRoles) session.load(UserRoles.class, new Integer(id));
    if (userRoles != null) {
        session.delete(userRoles);//ww w.  j a  v a  2s.  co  m
    }
    transaction.commit();
    session.close();
}

From source file:com.alibaba.sample.petstore.dal.dao.ibatis.IbatisOrderDao.java

@SuppressWarnings("unchecked")
public Order getOrderById(int orderId) {
    Order order = null;/*from   ww  w.ja va2 s.c o  m*/
    Object parameterObject = new Integer(orderId);

    order = (Order) getSqlMapClientTemplate().queryForObject("getOrder", parameterObject);
    order.setOrderItems(
            getSqlMapClientTemplate().queryForList("getOrderItemsByOrderId", new Integer(order.getOrderId())));

    return order;
}

From source file:MyCounter.java

public void init(org.apache.xalan.extensions.XSLProcessorContext context, org.w3c.dom.Element elem) {
    String name = elem.getAttribute("name");
    String value = elem.getAttribute("value");
    int val;
    try {//from   w w  w .j a va 2 s.  c om
        val = Integer.parseInt(value);
    } catch (NumberFormatException e) {
        e.printStackTrace();
        val = 0;
    }
    counters.put(name, new Integer(val));
}

From source file:com.yobidrive.diskmap.TokenSynchronizer.java

public TokenSynchronizer(int allowedConcurrent) {
    super();//from  ww  w . j  ava  2  s  . c o  m
    processingQ = new ArrayBlockingQueue<Integer>(allowedConcurrent, true);
    try {
        for (int i = 0; i < allowedConcurrent; i++) {
            Integer iInt = new Integer(i);
            processingQ.put(iInt);
        }
    } catch (Throwable th) {
        logger.error("Error putting tokens", th);
    }
}

From source file:com.yahoo.egads.models.adm.KSigmaModel.java

public KSigmaModel(Properties config) {
    super(config);

    if (config.getProperty("MAX_ANOMALY_TIME_AGO") == null) {
        throw new IllegalArgumentException("MAX_ANOMALY_TIME_AGO is NULL");
    }//from   www  .  ja  v  a 2  s . c  o m
    this.maxHrsAgo = new Integer(config.getProperty("MAX_ANOMALY_TIME_AGO"));

    this.threshold = parseMap(config.getProperty("THRESHOLD"));

    if (config.getProperty("THRESHOLD") != null && this.threshold.isEmpty() == true) {
        throw new IllegalArgumentException("THRESHOLD PARSE ERROR");
    }
}

From source file:jGW2API.util.item.ItemList.java

public ItemList(JSONArray json) {
    this.itemIDs = new ArrayList();
    for (int i = 0; i < json.length(); i++) {
        this.itemIDs.add(new Integer(json.getString(i)));
    }/*from   ww w .jav  a  2 s. c  o  m*/
}

From source file:com.discursive.jccook.collections.typed.TypedListExample.java

public void start() {
    // Make sure that items added to this
    hostNames = TypedList.decorate(new ArrayList(), String.class);

    // Add two String objects
    hostNames.add("papp01.thestreet.com");
    hostNames.add("test.slashdot.org");

    // Try to add an Integer
    try {/*w  ww.  j a  va2 s .  c o  m*/
        hostNames.add(new Integer(43));
    } catch (IllegalArgumentException iae) {
        System.out.println("Adding an Integer Failed as expected");
    }

    // Now we can safely cast without the possibility of a ClassCastException
    String hostName = (String) hostNames.get(0);

}

From source file:org.pluroid.pluroium.HttpClientFactory.java

public static ClientConnectionManager createConnectionManager() {
    HttpParams params = new BasicHttpParams();
    params.setParameter("http.socket.timeout", new Integer(READ_TIMEOUT));
    params.setParameter("http.connection.timeout", new Integer(CONNECT_TIMEOUT));
    return new ThreadSafeClientConnManager(params, supportedSchemes);
}