Example usage for java.lang Integer equals

List of usage examples for java.lang Integer equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this object to the specified object.

Usage

From source file:com.aurel.track.fieldType.runtime.system.select.SystemPersonBaseRT.java

/**
 * Get the ILabelBean by primary key //from   ww  w .j a v a 2 s .c  o  m
 * @return
 */
@Override
public ILabelBean getLabelBean(Integer optionID, Locale locale) {
    if (optionID != null && (optionID.equals(MatcherContext.LOGGED_USER_SYMBOLIC)
            || optionID.equals(MatcherContext.PARAMETER))) {
        TPersonBean personBean = new TPersonBean();
        String localizedName;
        if (optionID.equals(MatcherContext.LOGGED_USER_SYMBOLIC)) {
            localizedName = MatcherContext.getLocalizedLoggedInUser(locale);
        } else {
            localizedName = MatcherContext.getLocalizedParameter(locale);
        }
        personBean.setLastName(localizedName);
        personBean.setObjectID(optionID);
        return personBean;
    }
    return PersonBL.loadByPrimaryKey(optionID);
}

From source file:de.ingrid.portal.portlets.mdek.MdekEntryPortlet.java

private boolean hasUserAccessToMdekAdmin(String userName) throws SecurityException, PortletException {
    if (!roleManager.isUserInRole(userName, "mdek")) {
        return false;
    }/*from w ww . j  a va 2 s  . com*/

    UserData userData = getUserData(userName);

    // user couldn't be found in backend
    if (userData == null) {
        return false;
    }

    // Check for the idcRole of the user
    IngridDocument response = null;
    try {
        response = mdekCallerSecurity.getUserDetails(userData.getPlugId(), userData.getAddressUuid(),
                userData.getAddressUuid());

    } catch (Exception e) {
        throw new PortletException(
                "The connection to the iPlug with id '" + userData.getPlugId() + "' could not be established.",
                e);
    }

    IngridDocument userDoc = MdekUtils.getResultFromResponse(response);

    try {
        Integer role = (Integer) userDoc.get(MdekKeysSecurity.IDC_ROLE);
        return (role.equals(IdcRole.CATALOG_ADMINISTRATOR.getDbValue())
                || role.equals(IdcRole.METADATA_ADMINISTRATOR.getDbValue()));

    } catch (Exception e) {
        throw new PortletException("The connection to the iPlug with id '" + userData.getPlugId()
                + "' could not be established. The user with name '" + userName + "' and addressUuid '"
                + userData.getAddressUuid() + "' could not be found by the iPlug.", e);
    }
}

From source file:br.com.cobranca.util.Util.java

public static <T> boolean alterarRegistro(T objAlterado, Class<T> classe, Connection con, String strWhere)
        throws Exception, SQLException {

    if (strWhere == null || strWhere.trim().equals("")) {
        return false;
    }//from  w  w  w .j  a  va  2s. c  o m

    PreparedStatement ps = null;
    ResultSet rs = null;

    T objOriginal = classe.newInstance();

    try {

        // Recuperar objeto original no banco de dados
        String nomeTabela = objAlterado.getClass().getSimpleName();
        String strSql = "SELECT * FROM " + nomeTabela + " " + strWhere;

        ps = con.prepareStatement(strSql);
        rs = ps.executeQuery();

        if (rs.next()) {
            objOriginal = Util.atribuirValores(classe, rs);
        } else {
            return false;
        }

        rs.close();
        ps.close();

        // Comparar valores dos dois objetos
        strSql = "UPDATE " + nomeTabela + " SET ";

        boolean efetuarAlteracao;
        boolean usarVirgula = false;

        for (Field field : objAlterado.getClass().getDeclaredFields()) {

            efetuarAlteracao = false;

            String nomeColuna = field.getName();
            String tipoColuna = field.getType().getSimpleName();

            if (tipoColuna.toUpperCase().contains("INT")) {
                tipoColuna = "Int";
            } else {
                tipoColuna = StringPrimeiraLetraMaiuscula(tipoColuna);
            }

            // obj . get + nome do campo
            Method met = classe.getMethod("get" + StringPrimeiraLetraMaiuscula(field.getName()));

            if (tipoColuna.equals("Int")) {

                Integer valorOriginal = (Integer) met.invoke(objOriginal);
                Integer valorAlterado = (Integer) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    efetuarAlteracao = true;
                }

            } else if (tipoColuna.equals("String")) {

                String valorOriginal = (String) met.invoke(objOriginal);
                String valorAlterado = (String) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    efetuarAlteracao = true;
                }

            } else if (tipoColuna.equals("Double")) {

                Double valorOriginal = (Double) met.invoke(objOriginal);
                Double valorAlterado = (Double) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    efetuarAlteracao = true;
                }

            } else if (tipoColuna.equals("Float")) {

                Float valorOriginal = (Float) met.invoke(objOriginal);
                Float valorAlterado = (Float) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    efetuarAlteracao = true;
                }

            } else if (tipoColuna.equals("Long")) {

                Long valorOriginal = (Long) met.invoke(objOriginal);
                Long valorAlterado = (Long) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    efetuarAlteracao = true;
                }

            } else if (tipoColuna.equals("Boolean")) {

                Boolean valorOriginal = (Boolean) met.invoke(objOriginal);
                Boolean valorAlterado = (Boolean) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    efetuarAlteracao = true;
                }

            } else if (tipoColuna.equals("Date")) {

                Date valorOriginal = (Date) met.invoke(objOriginal);
                Date valorAlterado = (Date) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    efetuarAlteracao = true;
                }

            } else {
                return false;
            }

            if (efetuarAlteracao) {

                if (usarVirgula) {
                    strSql = strSql + ", ";
                    //usarVirgula = false;
                }

                strSql = strSql + nomeColuna + " = ? ";
                usarVirgula = true;
            }

        }

        //Se no houve alterao, retorna falso
        if (!strSql.contains("?")) {
            return true;
        }

        strSql = strSql + strWhere;
        ps = con.prepareStatement(strSql);

        int i = 1;

        // ps.set?()
        for (Field field : objAlterado.getClass().getDeclaredFields()) {

            String nomeColuna = field.getName();
            String tipoColuna = field.getType().getSimpleName();

            if (tipoColuna.toUpperCase().contains("INT")) {
                tipoColuna = "Int";
            } else {
                tipoColuna = StringPrimeiraLetraMaiuscula(tipoColuna);
            }

            // obj . get + nome do campo
            Method met = classe.getMethod("get" + StringPrimeiraLetraMaiuscula(field.getName()));

            if (tipoColuna.equals("Int")) {

                Integer valorOriginal = (Integer) met.invoke(objOriginal);
                Integer valorAlterado = (Integer) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    if (valorAlterado == null) {
                        ps.setString(i, null);
                    } else {
                        ps.setInt(i, valorAlterado);
                    }
                    i++;
                }

            } else if (tipoColuna.equals("String")) {
                String valorOriginal = (String) met.invoke(objOriginal);
                String valorAlterado = (String) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    ps.setString(i, valorAlterado);
                    i++;
                }

            } else if (tipoColuna.equals("Double")) {

                Double valorOriginal = (Double) met.invoke(objOriginal);
                Double valorAlterado = (Double) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    if (valorAlterado == null) {
                        ps.setString(i, null);
                    } else {
                        ps.setDouble(i, valorAlterado);
                    }
                    i++;
                }

            } else if (tipoColuna.equals("Float")) {

                Float valorOriginal = (Float) met.invoke(objOriginal);
                Float valorAlterado = (Float) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    if (valorAlterado == null) {
                        ps.setString(i, null);
                    } else {
                        ps.setFloat(i, valorAlterado);
                    }
                    i++;
                }

            } else if (tipoColuna.equals("Long")) {

                Long valorOriginal = (Long) met.invoke(objOriginal);
                Long valorAlterado = (Long) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    if (valorAlterado == null) {
                        ps.setString(i, null);
                    } else {
                        ps.setLong(i, valorAlterado);
                    }
                    i++;
                }

            } else if (tipoColuna.equals("Boolean")) {

                Boolean valorOriginal = (Boolean) met.invoke(objOriginal);
                Boolean valorAlterado = (Boolean) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    if (valorAlterado == null) {
                        ps.setString(i, null);
                    } else {
                        ps.setBoolean(i, valorAlterado);
                    }
                    i++;
                }

            } else if (tipoColuna.equals("Date")) {

                Date valorOriginal = (Date) met.invoke(objOriginal);
                Date valorAlterado = (Date) met.invoke(objAlterado);

                if (!valorOriginal.equals(valorAlterado)) {
                    if (valorAlterado == null) {
                        ps.setString(i, null);
                    } else {
                        ps.setDate(i, new java.sql.Date(valorAlterado.getTime()));
                    }
                    i++;
                }

            } else {
                return false;
            }

        }

        // fim
        int qtdLinhasAfetadas = ps.executeUpdate();

        if (qtdLinhasAfetadas <= 0) {
            return false;
        }
    } catch (Exception ex) {
        throw new Exception(ex.getMessage());
    } finally {

        if (rs != null) {
            rs.close();
        }

        if (ps != null) {
            ps.close();
        }
    }

    return true;

}

From source file:com.aurel.track.fieldType.runtime.matchers.run.CustomSelectMatcherRT.java

private boolean containsValue(Integer[] matcherValues, Object[] attributeValues) {
    for (Integer matcherValue : matcherValues) {
        if (matcherValue != null) {
            for (Object attributeValue : attributeValues) {
                if (matcherValue.equals(attributeValue)) {
                    return true;
                }//  w ww  .  ja va2s . c  o m
            }
        }
    }
    return false;
}

From source file:org.bozzo.ipplan.web.SubnetController.java

@RequestMapping(value = "/{subnetId}", method = RequestMethod.PUT, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public HttpEntity<SubnetResource> updateSubnet(@PathVariable Integer infraId, @PathVariable Long subnetId,
        @RequestBody @NotNull Subnet subnet) {
    Preconditions.checkArgument(infraId.equals(subnet.getInfraId()));
    Preconditions.checkArgument(subnetId.equals(subnet.getId()));
    logger.info("update subnet: {}", subnet);

    if (!Netmask.isValidNetmask(subnet.getSize())) {
        throw new ApiException(ApiError.BAD_NETMASK);
    } else if (!IpAddress.isNetworkAddress(subnet.getIp(), subnet.getSize())) {
        throw new ApiException(ApiError.BAD_NETWORK);
    }//w w  w.ja v a  2s  .  c  o  m

    Subnet sub = service.save(subnet);
    return new ResponseEntity<>(assembler.toResource(sub), HttpStatus.CREATED);
}

From source file:com.taobao.tddl.jdbc.group.dbselector.EquityDbManager.java

/**
 * dsKey0null//  w w w . ja v  a  2  s  . c  om
 * @param dsKey DataSourcekey, dbSelector
 * @return dsKey
 */
public DataSourceWrapper get(String dsKey) {
    DataSourceHolder holder = dataSourceMap.get(dsKey);
    Integer weigthValue = this.weightRandom.getWeightConfig().get(dsKey);
    if (weigthValue == null || weigthValue.equals(0))
        return null;
    return holder == null ? null : holder.dsw;
}

From source file:io.spring.initializr.util.VersionParser.java

private Version findLatestVersion(Integer major, Integer minor, Version.Qualifier qualifier) {
    List<Version> matches = this.latestVersions.stream().filter((it) -> {
        if (major != null && !major.equals(it.getMajor())) {
            return false;
        }//from   ww w.j a va  2  s.c o  m
        if (minor != null && !minor.equals(it.getMinor())) {
            return false;
        }
        if (qualifier != null && !qualifier.equals(it.getQualifier())) {
            return false;
        }
        return true;
    }).collect(Collectors.toList());
    return (matches.size() == 1 ? matches.get(0) : null);
}

From source file:org.bozzo.ipplan.web.AddressController.java

@RequestMapping(method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public HttpEntity<AddressResource> addAddress(@PathVariable Integer infraId, @PathVariable Long subnetId,
        @RequestBody @NotNull Address address) {
    Preconditions.checkArgument(infraId.equals(address.getInfraId()));
    Preconditions.checkArgument(subnetId.equals(address.getSubnetId()));
    logger.info("add new address: {}", address);
    if (address.getIp() == null) {
        Address freeAddress = this.service.findFreeAddressBySubnetId(subnetId);
        if (freeAddress == null) {
            throw new ApiException(ApiError.SUBNET_FULL);
        }/*from w ww.ja  v  a  2  s  .  c  om*/
        address.setIp(freeAddress.getIp());
    } else if (this.repository.exists(address.getIp())) {
        throw new ApiException(ApiError.IP_CONFLICT);
    }
    Address ip = service.save(address);
    ip.setInfraId(infraId);
    return new ResponseEntity<>(assembler.toResource(ip), HttpStatus.CREATED);
}

From source file:org.bozzo.ipplan.web.RangeController.java

@RequestMapping(value = "/{rangeId}", method = RequestMethod.PUT, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public HttpEntity<RangeResource> updateRange(@PathVariable Integer infraId, @PathVariable Long zoneId,
        @PathVariable Long rangeId, @RequestBody @NotNull Range range) {
    Preconditions.checkArgument(infraId.equals(range.getInfraId()));
    Preconditions.checkArgument(zoneId.equals(range.getZoneId()));
    Preconditions.checkArgument(rangeId.equals(range.getId()));

    if (!Netmask.isValidNetmask(range.getSize())) {
        throw new ApiException(ApiError.BAD_NETMASK);
    } else if (!IpAddress.isNetworkAddress(range.getIp(), range.getSize())) {
        throw new ApiException(ApiError.BAD_NETWORK);
    }//from  w w w .jav  a 2  s .  c om

    logger.info("update range: {}", range);
    Range rang = service.save(range);
    return new ResponseEntity<>(assembler.toResource(rang), HttpStatus.CREATED);
}

From source file:com.sshtools.appframework.api.ui.ActionBuilder.java

protected void rebuildContextMenu(Collection<AppAction> enabledActions) {
    contextMenu.invalidate();/*from  w  w w  .  j a va2 s.  c o  m*/

    // Build the context menu action list
    List<AppAction> contextMenuActions = new ArrayList<AppAction>();
    contextMenu.removeAll();
    for (AppAction action : enabledActions) {
        if (Boolean.TRUE.equals(action.getValue(AppAction.ON_CONTEXT_MENU))) {
            contextMenuActions.add(action);
        }
    }
    log.debug("There are " + contextMenuActions.size() + " on the context menu");
    Collections.sort(contextMenuActions, new ContextActionComparator());

    // Build the context menu
    Integer grp = null;
    for (AppAction action : contextMenuActions) {
        if ((grp != null) && !grp.equals(action.getValue(AppAction.CONTEXT_MENU_GROUP))) {
            contextMenu.addSeparator();
        }
        if (Boolean.TRUE.equals(action.getValue(AppAction.IS_TOGGLE_BUTTON))) {
            final JCheckBoxMenuItem item = new JCheckBoxMenuItem(action);
            action.addPropertyChangeListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    if (evt.getPropertyName().equals(AppAction.IS_SELECTED)) {
                        item.setSelected(((Boolean) evt.getNewValue()).booleanValue());
                    }
                }
            });
            contextMenu.add(item);
            item.setSelected(Boolean.TRUE.equals(action.getValue(AppAction.IS_SELECTED)));
        } else {
            contextMenu.add(action);
        }
        grp = (Integer) action.getValue(AppAction.CONTEXT_MENU_GROUP);
    }
    contextMenu.validate();
    contextMenu.repaint();
}