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:net.sf.ginp.config.Configuration.java

/**
 * Sets the value of filmStripThumbSize.
 * @param newFilmStripThumbSize The value to assign filmStripThumbSize.
 */// w ww. j  a  v  a2 s . c  om
public static void setFilmStripThumbSize(final String newFilmStripThumbSize) {
    try {
        Integer iTmp = new Integer(newFilmStripThumbSize);
        filmStripThumbSize = iTmp.intValue();
    } catch (Exception ex) {
        log.error("Error seting filmStripThumbSize in Configuration", ex);
    }
}

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

/**
 * Use Sun-specific internal plugin proxy classes for 1.3.X
 * Look around for the 1.3.X plugin proxy detection class. Without it,
 * cannot autodetect...//from www.ja  v  a 2  s. co m
 *
 * @param sampleURL the URL to check proxy settings for
 * @return ProxyHost the host and port of the proxy that should be used
 * @throws ProxyDetectionException if detection failed
 */
private static HttpHost detectProxySettingsJDK13(URL sampleURL) throws ProxyDetectionException {
    HttpHost result = null;
    try {
        // Attempt to discover proxy info by asking internal plugin
        // code to locate proxy path to server sampleURL...
        Class<?> pluginProxyHandler = Class.forName("sun.plugin.protocol.PluginProxyHandler");
        Method getDefaultProxyHandlerMethod = pluginProxyHandler.getDeclaredMethod("getDefaultProxyHandler",
                (Class[]) null);
        Object proxyHandlerObj = getDefaultProxyHandlerMethod.invoke(null, (Object[]) null);
        if (proxyHandlerObj != null) {
            Class<?> proxyHandlerClass = proxyHandlerObj.getClass();
            Method getProxyInfoMethod = proxyHandlerClass.getDeclaredMethod("getProxyInfo",
                    new Class[] { URL.class });
            Object proxyInfoObject = getProxyInfoMethod.invoke(proxyHandlerObj, new Object[] { sampleURL });
            if (proxyInfoObject != null) {
                Class<?> proxyInfoClass = proxyInfoObject.getClass();
                Method getProxyMethod = proxyInfoClass.getDeclaredMethod("getProxy", (Class[]) null);
                boolean useProxy = (getProxyMethod.invoke(proxyInfoObject, (Object[]) null) != null);
                if (useProxy) {
                    String proxyIP = (String) getProxyMethod.invoke(proxyInfoObject, (Object[]) null);
                    Method getProxyPortMethod = proxyInfoClass.getDeclaredMethod("getPort", (Class[]) null);
                    Integer portInteger = (Integer) getProxyPortMethod.invoke(proxyInfoObject, (Object[]) null);
                    int proxyPort = portInteger.intValue();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("1.3.X: proxy=" + proxyIP + " port=" + proxyPort);
                    }
                    result = new HttpHost(proxyIP, proxyPort);
                } else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("1.3.X reported NULL for " + "proxyInfo.getProxy (no proxy assumed)");
                    }
                    result = NO_PROXY_HOST;
                }
            } else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("NULL proxyInfo in 1.3.X auto proxy " + "detection, (no proxy assumed)");
                }
                result = NO_PROXY_HOST;
            }
        } else {
            throw new ProxyDetectionException("Sun Plugin 1.3.X failed to provide a default proxy handler");
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        LOG.debug("Sun Plugin 1.3.X proxy detection class not " + "found, will try failover detection" /*, e*/);
    }
    return result;
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.publico.teachersBody.ReadProfessorshipsAndResponsibilitiesByExecutionDegreeAndExecutionPeriod.java

@Atomic
public static List run(String executionDegreeId, Integer semester, Integer teacherType)
        throws FenixServiceException {

    final ExecutionDegree executionDegree = FenixFramework.getDomainObject(executionDegreeId);

    List professorships;// w  w  w . j av  a 2 s  .  co  m
    if (semester.intValue() == 0) {
        professorships = Professorship.readByDegreeCurricularPlanAndExecutionYear(
                executionDegree.getDegreeCurricularPlan(), executionDegree.getExecutionYear());
    } else {
        ExecutionSemester executionSemester = executionDegree.getExecutionYear()
                .getExecutionSemesterFor(semester);
        professorships = Professorship.readByDegreeCurricularPlanAndExecutionPeriod(
                executionDegree.getDegreeCurricularPlan(), executionSemester);
    }

    List responsibleFors = getResponsibleForsByDegree(executionDegree);

    List detailedProfessorships = getDetailedProfessorships(professorships, responsibleFors, teacherType);

    // Cleaning out possible null elements inside the list
    Iterator itera = detailedProfessorships.iterator();
    while (itera.hasNext()) {
        Object dp = itera.next();
        if (dp == null) {
            itera.remove();
        }
    }

    Collections.sort(detailedProfessorships, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            DetailedProfessorship detailedProfessorship1 = (DetailedProfessorship) o1;
            DetailedProfessorship detailedProfessorship2 = (DetailedProfessorship) o2;
            int result = detailedProfessorship1.getInfoProfessorship().getInfoExecutionCourse().getExternalId()
                    .compareTo(detailedProfessorship2.getInfoProfessorship().getInfoExecutionCourse()
                            .getExternalId());
            if (result == 0 && (detailedProfessorship1.getResponsibleFor().booleanValue()
                    || detailedProfessorship2.getResponsibleFor().booleanValue())) {
                if (detailedProfessorship1.getResponsibleFor().booleanValue()) {
                    return -1;
                }
                if (detailedProfessorship2.getResponsibleFor().booleanValue()) {
                    return 1;
                }
            }

            return result;
        }

    });

    List result = new ArrayList();
    Iterator iter = detailedProfessorships.iterator();
    List temp = new ArrayList();
    while (iter.hasNext()) {
        DetailedProfessorship detailedProfessorship = (DetailedProfessorship) iter.next();
        if (temp.isEmpty() || ((DetailedProfessorship) temp.get(temp.size() - 1)).getInfoProfessorship()
                .getInfoExecutionCourse()
                .equals(detailedProfessorship.getInfoProfessorship().getInfoExecutionCourse())) {
            temp.add(detailedProfessorship);
        } else {
            result.add(temp);
            temp = new ArrayList();
            temp.add(detailedProfessorship);
        }
    }
    if (!temp.isEmpty()) {
        result.add(temp);
    }
    return result;
}

From source file:msi.gaml.operators.Strings.java

@operator(value = "char", can_be_const = true, category = { IOperatorCategory.STRING }, concept = {
        IConcept.STRING })// www. j a va  2 s. c  o m
@doc(usages = @usage(value = "converts ACSII integer value to character", examples = @example(value = "char (34)", equals = "'\"'")))
static public String asChar(final Integer s) {
    if (s == null) {
        return "";
    }
    return Character.toString((char) s.intValue());
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.util.ExcelGeneratorUtils.java

/**
 * Adjusts the column widths for the specified sheet context. The {@code widthsMap} contains the
 * persistent names associated with the actual column width.
 * //from   w  w  w .  j a v a 2s  .  c o m
 * @param sheetContext the sheet context
 * @param widthsMap the map containing the column widths
 */
public static void adjustColumnWidths(SheetContext sheetContext, Map<String, Integer> widthsMap) {
    for (ColumnContext sheetColumn : sheetContext.getColumns()) {
        if (sheetColumn.getFeatureExpression() == null) {
            continue;
        }
        String persistentName = sheetColumn.getFeatureExpression().getPersistentName();

        if (widthsMap.containsKey(persistentName)) {
            Integer width = widthsMap.get(persistentName);
            sheetContext.getSheet().setColumnWidth(sheetColumn.getColumnNumber(), width.intValue());
        } else {
            sheetContext.getSheet().autoSizeColumn(sheetColumn.getColumnNumber());
        }
    }
}

From source file:Main.java

/**
 * <p>Converts an array of object Integer to primitives handling {@code null}.</p>
 *
 * <p>This method returns {@code null} for a {@code null} input array.</p>
 *
 * @param array  a {@code Integer} array, may be {@code null}
 * @param valueForNull  the value to insert if {@code null} found
 * @return an {@code int} array, {@code null} if null array input
 */// w  ww  .j a va  2s . c o  m
public static int[] toPrimitive(Integer[] array, int valueForNull) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_INT_ARRAY;
    }
    final int[] result = new int[array.length];
    for (int i = 0; i < array.length; i++) {
        Integer b = array[i];
        result[i] = (b == null ? valueForNull : b.intValue());
    }
    return result;
}

From source file:SftpClientFactory.java

/**
 * Creates a new connection to the server.
 * @param hostname The name of the host to connect to.
 * @param port The port to use.//from  w  w w.j av a 2  s .com
 * @param username The user's id.
 * @param password The user's password.
 * @param fileSystemOptions The FileSystem options.
 * @return A Session.
 * @throws FileSystemException if an error occurs.
 */
public static Session createConnection(String hostname, int port, char[] username, char[] password,
        FileSystemOptions fileSystemOptions) throws FileSystemException {
    JSch jsch = new JSch();

    File sshDir = null;

    // new style - user passed
    File knownHostsFile = SftpFileSystemConfigBuilder.getInstance().getKnownHosts(fileSystemOptions);
    File[] identities = SftpFileSystemConfigBuilder.getInstance().getIdentities(fileSystemOptions);

    if (knownHostsFile != null) {
        try {
            jsch.setKnownHosts(knownHostsFile.getAbsolutePath());
        } catch (JSchException e) {
            throw new FileSystemException("vfs.provider.sftp/known-hosts.error",
                    knownHostsFile.getAbsolutePath(), e);
        }
    } else {
        sshDir = findSshDir();
        // Load the known hosts file
        knownHostsFile = new File(sshDir, "known_hosts");
        if (knownHostsFile.isFile() && knownHostsFile.canRead()) {
            try {
                jsch.setKnownHosts(knownHostsFile.getAbsolutePath());
            } catch (JSchException e) {
                throw new FileSystemException("vfs.provider.sftp/known-hosts.error",
                        knownHostsFile.getAbsolutePath(), e);
            }
        }
    }

    if (identities != null) {
        for (int iterIdentities = 0; iterIdentities < identities.length; iterIdentities++) {
            final File privateKeyFile = identities[iterIdentities];
            try {
                jsch.addIdentity(privateKeyFile.getAbsolutePath());
            } catch (final JSchException e) {
                throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
            }
        }
    } else {
        if (sshDir == null) {
            sshDir = findSshDir();
        }

        // Load the private key (rsa-key only)
        final File privateKeyFile = new File(sshDir, "id_rsa");
        if (privateKeyFile.isFile() && privateKeyFile.canRead()) {
            try {
                jsch.addIdentity(privateKeyFile.getAbsolutePath());
            } catch (final JSchException e) {
                throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
            }
        }
    }

    Session session;
    try {
        session = jsch.getSession(new String(username), hostname, port);
        if (password != null) {
            session.setPassword(new String(password));
        }

        Integer timeout = SftpFileSystemConfigBuilder.getInstance().getTimeout(fileSystemOptions);
        if (timeout != null) {
            session.setTimeout(timeout.intValue());
        }

        UserInfo userInfo = SftpFileSystemConfigBuilder.getInstance().getUserInfo(fileSystemOptions);
        if (userInfo != null) {
            session.setUserInfo(userInfo);
        }

        Properties config = new Properties();

        //set StrictHostKeyChecking property
        String strictHostKeyChecking = SftpFileSystemConfigBuilder.getInstance()
                .getStrictHostKeyChecking(fileSystemOptions);
        if (strictHostKeyChecking != null) {
            config.setProperty("StrictHostKeyChecking", strictHostKeyChecking);
        }
        //set PreferredAuthentications property
        String preferredAuthentications = SftpFileSystemConfigBuilder.getInstance()
                .getPreferredAuthentications(fileSystemOptions);
        if (preferredAuthentications != null) {
            config.setProperty("PreferredAuthentications", preferredAuthentications);
        }

        //set compression property
        String compression = SftpFileSystemConfigBuilder.getInstance().getCompression(fileSystemOptions);
        if (compression != null) {
            config.setProperty("compression.s2c", compression);
            config.setProperty("compression.c2s", compression);
        }

        String proxyHost = SftpFileSystemConfigBuilder.getInstance().getProxyHost(fileSystemOptions);
        if (proxyHost != null) {
            int proxyPort = SftpFileSystemConfigBuilder.getInstance().getProxyPort(fileSystemOptions);
            SftpFileSystemConfigBuilder.ProxyType proxyType = SftpFileSystemConfigBuilder.getInstance()
                    .getProxyType(fileSystemOptions);
            Proxy proxy = null;
            if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) {
                if (proxyPort != 0) {
                    proxy = new ProxyHTTP(proxyHost, proxyPort);
                } else {
                    proxy = new ProxyHTTP(proxyHost);
                }
            } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) {
                if (proxyPort != 0) {
                    proxy = new ProxySOCKS5(proxyHost, proxyPort);
                } else {
                    proxy = new ProxySOCKS5(proxyHost);
                }
            }

            if (proxy != null) {
                session.setProxy(proxy);
            }
        }

        //set properties for the session
        if (config.size() > 0) {
            session.setConfig(config);
        }
        session.setDaemonThread(true);
        session.connect();
    } catch (final Exception exc) {
        throw new FileSystemException("vfs.provider.sftp/connect.error", new Object[] { hostname }, exc);
    }

    return session;
}

From source file:com.jdom.junit.utils.AbstractFixture.java

/**
 * Get a randomized value.//from   w ww .  j  a v  a2s . co m
 * 
 * @param value
 *            the value to randomize
 * @param salt
 *            the randomizer to use
 * @return the randomized value
 */
public static Integer getSaltedValue(Integer value, int salt) {
    Integer retValue;

    if (salt == 0) {
        retValue = value;
    } else {
        retValue = new Integer(value.intValue() * salt * salt + INT_FACTOR);
    }

    return retValue;
}

From source file:AWTUtilities.java

/**
 * Returns the state of the specified frame, as specified by
 * <code>Frame.getExtendedState()</code> if running under JDK 1.4 or later,
 * otherwise returns 0. The call to <code>Frame.getExtendedState()</code> is
 * done via reflection to avoid runtime errors.
 *//* w  w w.  j av a2  s  .  c  o m*/

public static int getExtendedFrameState(Frame frame) {
    if (PlatformUtils.isJavaBetterThan("1.4")) {
        try {
            Class frameClass = Class.forName("java.awt.Frame");
            Method getExtendedStateMethod = frameClass.getMethod("getExtendedState", new Class[0]);
            Integer state = (Integer) getExtendedStateMethod.invoke(frame, new Object[0]);
            return state.intValue();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    return 0;
}

From source file:Main.java

/**
 * <p>Converts an array of object Integer to primitives handling {@code null}.</p>
 *
 * <p>This method returns {@code null} for a {@code null} input array.</p>
 *
 * @param array  a {@code Integer} array, may be {@code null}
 * @param valueForNull  the value to insert if {@code null} found
 * @return an {@code int} array, {@code null} if null array input
 *//*from   w  w  w.  j a v a  2s .  c o m*/
public static int[] toPrimitive(final Integer[] array, final int valueForNull) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_INT_ARRAY;
    }
    final int[] result = new int[array.length];
    for (int i = 0; i < array.length; i++) {
        final Integer b = array[i];
        result[i] = (b == null ? valueForNull : b.intValue());
    }
    return result;
}