Example usage for java.lang Integer intValue

List of usage examples for java.lang Integer intValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public int intValue() 

Source Link

Document

Returns the value of this Integer as an int .

Usage

From source file:com.zimbra.cs.util.GalSyncAccountUtil.java

private static int lookupCmd(String cmd) {
    Integer i = mCommands.get(cmd.toLowerCase());
    if (i == null) {
        usage();//w ww . ja v a2  s . c  o m
    }
    return i.intValue();
}

From source file:com.dnielfe.manager.preview.MimeTypes.java

public static int getIconForExt(String ext) {
    final Integer res = EXT_ICONS.get(ext);
    return res == null ? 0 : res.intValue();
}

From source file:org.apache.commons.httpclient.contrib.proxy.PluginProxyUtil.java

/**
 * Returns the proxy information for the specified sampleURL using JRE 1.4+
 * specific plugin classes./*from  w  w  w . j  a va 2s . c  o m*/
 *
 * Notes:
 *     Plugin 1.4+ Final added
 *     com.sun.java.browser.net.* classes ProxyInfo & ProxyService...
 *     Use those with JREs => 1.4+
 *
 * @param sampleURL the URL to check proxy settings for
 * @return ProxyHost the host and port of the proxy that should be used
 */
private static HttpHost detectProxySettingsJDK14_JDK15_JDK16(URL sampleURL) {
    HttpHost result = null;
    try {
        // Look around for the 1.4+ plugin proxy detection class...
        // Without it, cannot autodetect...
        Class<?> ProxyServiceClass = Class.forName("com.sun.java.browser.net.ProxyService");
        Method getProxyInfoMethod = ProxyServiceClass.getDeclaredMethod("getProxyInfo",
                new Class[] { URL.class });
        Object proxyInfoArrayObj = getProxyInfoMethod.invoke(null, new Object[] { sampleURL });

        if (proxyInfoArrayObj == null || Array.getLength(proxyInfoArrayObj) == 0) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("1.4+ reported NULL proxy (no proxy assumed)");
            }
            result = NO_PROXY_HOST;
        } else {
            Object proxyInfoObject = Array.get(proxyInfoArrayObj, 0);
            Class<?> proxyInfoClass = proxyInfoObject.getClass();
            Method getHostMethod = proxyInfoClass.getDeclaredMethod("getHost", (Class[]) null);
            String proxyIP = (String) getHostMethod.invoke(proxyInfoObject, (Object[]) null);
            Method getPortMethod = proxyInfoClass.getDeclaredMethod("getPort", (Class[]) null);
            Integer portInteger = (Integer) getPortMethod.invoke(proxyInfoObject, (Object[]) null);
            int proxyPort = portInteger.intValue();
            if (LOG.isDebugEnabled()) {
                LOG.debug("1.4+ Proxy info get Proxy:" + proxyIP + " get Port:" + proxyPort);
            }
            result = new HttpHost(proxyIP, proxyPort);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        LOG.debug("Sun Plugin 1.4+ proxy detection class not found, " + "will try failover detection" /*, e*/);
    }
    return result;
}

From source file:com.glaf.core.util.ParamUtils.java

public static int getInt(Map<String, Object> dataMap, String key) {
    int result = 0;
    Object value = dataMap.get(key);
    if (value == null) {
        value = dataMap.get(key.toLowerCase());
    }/*from   w  w  w  .j  a  va2s.  c o m*/
    if (value == null) {
        value = dataMap.get(key.toUpperCase());
    }
    if (value != null && StringUtils.isNotEmpty(value.toString())) {
        if (value instanceof String) {
            String tmp = (String) value;
            result = Integer.parseInt(tmp);
        } else if (value instanceof Integer) {
            Integer x = (Integer) value;
            result = x.intValue();
        } else if (value instanceof Long) {
            Long x = (Long) value;
            result = x.intValue();
        } else if (value instanceof Double) {
            Double x = (Double) value;
            result = x.intValue();
        } else {
            String tmp = value.toString();
            result = Integer.parseInt(tmp);
        }
    }
    return result;
}

From source file:com.glaf.core.util.ParamUtils.java

public static Integer getIntValue(Map<String, Object> dataMap, String key) {
    Integer result = null;/*from w ww. ja  v a2s . c  o  m*/
    Object value = dataMap.get(key);
    if (value == null) {
        value = dataMap.get(key.toLowerCase());
    }
    if (value == null) {
        value = dataMap.get(key.toUpperCase());
    }
    if (value != null && StringUtils.isNotEmpty(value.toString())) {
        if (value instanceof String) {
            String tmp = (String) value;
            result = Integer.parseInt(tmp);
        } else if (value instanceof Integer) {
            Integer x = (Integer) value;
            result = x.intValue();
        } else if (value instanceof Long) {
            Long x = (Long) value;
            result = x.intValue();
        } else if (value instanceof Double) {
            Double x = (Double) value;
            result = x.intValue();
        } else {
            String tmp = value.toString();
            result = Integer.parseInt(tmp);
        }
    }
    return result;
}

From source file:net.sf.ginp.config.Configuration.java

/**
 * Sets the value of thumbSize.//from w ww  . j  a va  2s. com
 * @param newThumbSize The value to assign thumbSize.
 */
public static void setThumbSize(final String newThumbSize) {
    try {
        Integer iTmp = new Integer(newThumbSize);
        thumbSize = iTmp.intValue();
    } catch (Exception ex) {
        log.error("Error seting thumbSize in Configuration", ex);
    }
}

From source file:Main.java

/**
 * Returns a {@link Map} mapping each unique element in the given
 * {@link Collection} to an {@link Integer} representing the number of
 * occurrences of that element in the {@link Collection}.
 * <p>//from  w  w w  .  j a va 2 s. c  o  m
 * Only those elements present in the collection will appear as keys in the
 * map.
 * 
 * @param coll
 *            the collection to get the cardinality map for, must not be
 *            null
 * @return the populated cardinality map
 */
public static <E> Map<E, Integer> getCardinalityMap(final Collection<E> coll) {
    if (coll == null) {
        return null;
    }
    Map<E, Integer> count = getHashMap();
    for (E e : coll) {
        Integer c = count.get(e);
        if (c == null) {
            count.put(e, INTEGER_ONE);
        } else {
            count.put(e, new Integer(c.intValue() + 1));
        }

    }

    return count;
}

From source file:com.glaf.core.util.ParamUtils.java

public static long getLong(Map<String, Object> dataMap, String key) {
    long result = 0;
    Object value = dataMap.get(key);
    if (value == null) {
        value = dataMap.get(key.toLowerCase());
    }//ww w . j a v  a 2s .  com
    if (value == null) {
        value = dataMap.get(key.toUpperCase());
    }
    if (value != null && StringUtils.isNotEmpty(value.toString())) {
        if (value instanceof String) {
            String tmp = (String) value;
            result = Long.parseLong(tmp);
        } else if (value instanceof Integer) {
            Integer x = (Integer) value;
            result = Long.valueOf(x.intValue());
        } else if (value instanceof Long) {
            Long x = (Long) value;
            result = x.longValue();
        } else if (value instanceof Double) {
            Double x = (Double) value;
            result = x.longValue();
        } else {
            String tmp = value.toString();
            result = Long.parseLong(tmp);
        }
    }
    return result;
}

From source file:com.glaf.core.util.ParamUtils.java

public static Long getLongValue(Map<String, Object> dataMap, String key) {
    Long result = null;//from w w w . j  a  va2  s  .  com
    Object value = dataMap.get(key);
    if (value == null) {
        value = dataMap.get(key.toLowerCase());
    }
    if (value == null) {
        value = dataMap.get(key.toUpperCase());
    }
    if (value != null && StringUtils.isNotEmpty(value.toString())) {
        if (value instanceof String) {
            String tmp = (String) value;
            result = Long.parseLong(tmp);
        } else if (value instanceof Integer) {
            Integer x = (Integer) value;
            result = Long.valueOf(x.intValue());
        } else if (value instanceof Long) {
            Long x = (Long) value;
            result = x.longValue();
        } else if (value instanceof Double) {
            Double x = (Double) value;
            result = x.longValue();
        } else {
            String tmp = value.toString();
            result = Long.parseLong(tmp);
        }
    }
    return result;
}

From source file:Main.java

/**
 * Format a collection, array, or map (internal method).
 *
 * @param theLabel/* www. j av a 2 s  .c  o  m*/
 * @param coll
 * @param maxNumberReported
 * @param theClassName
 * @return The formatted collection, spans multiple lines.
 */
private static String format(String theLabel, Collection<?> coll, int maxNumberReported, String theClassName) {
    final boolean showCollectionIndexes = false;
    final int half = (maxNumberReported == 0) ? 10000 : ((maxNumberReported - 1) / 2) + 1;

    String label = theLabel;
    if (label == null) {
        label = "";
    }

    final Map<Class<?>, Integer> instancesByClass = new HashMap<Class<?>, Integer>();
    final StringBuilder sb = new StringBuilder(label);

    if (label.length() > 0) {
        sb.append(' ');
    }

    final int size = (coll != null) ? coll.size() : 0;

    if (size > 0) {
        sb.append('\n');
    }

    int counter = 0;
    boolean shownEllipsis = false;

    if (coll == null) {
        sb.append("null Collection or Map");
        return sb.toString();
    }

    for (final Object element : coll) {
        // Statistics
        final Class<?> theElementClass = (element != null) ? element.getClass() : null;
        Integer nbrOfThisClass = instancesByClass.get(theElementClass);

        if (nbrOfThisClass == null) {
            nbrOfThisClass = 0;
        }
        nbrOfThisClass = nbrOfThisClass.intValue() + 1;
        instancesByClass.put(theElementClass, nbrOfThisClass);

        // Report
        if (counter < half || counter >= size - half) {
            if (element instanceof Entry<?, ?>) {
                final Entry<?, ?> entry = (Entry<?, ?>) element;
                if (entry.getValue() instanceof Collection<?>) {
                    final int colLSize = ((Collection<?>) entry.getValue()).size();
                    sb.append(" ").append(entry.getKey()).append('[').append(colLSize).append("]=")
                            .append(entry.getValue()).append('\n');
                } else {
                    sb.append(" ").append(entry.getKey()).append('=').append(entry.getValue()).append('\n');
                }
            } else {
                sb.append(' ');
                if (showCollectionIndexes) {
                    sb.append('[');
                    sb.append(counter);
                    sb.append("]=");
                }
                sb.append(String.valueOf(element));
                sb.append('\n');
            }
        } else {
            if (!shownEllipsis) {
                sb.append(" [").append(half).append('-').append(size - half - 1).append("]=(")
                        .append(size - half - half).append(" skipped)\n");
            }
            shownEllipsis = true;
        }
        counter++;
    }

    // Special case for Arrays$ArrayList
    String className = theClassName;
    if ("Arrays$ArrayList".equals(className)) {
        className = "Object[]";
    }
    sb.append(className);
    sb.append(" size=");
    sb.append(size);

    if (!className.endsWith("Map")) {
        // Report number of classes
        for (final Entry<Class<?>, Integer> entry : instancesByClass.entrySet()) {
            final Class<?> key = entry.getKey();
            final Integer value = entry.getValue();
            sb.append(", ");
            sb.append(value);
            sb.append(' ');
            sb.append(key.getSimpleName());
        }
    }
    sb.append('.');
    return sb.toString();
}