Example usage for java.lang Long intValue

List of usage examples for java.lang Long intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Long as an int after a narrowing primitive conversion.

Usage

From source file:it.grid.storm.namespace.util.userinfo.UserInfoCommand.java

/**
 * Extracts from the received string (with at least 3 fields separated by ":"
 * ) the GID value as a long/*from   w w  w  .j  a  v a  2 s. co m*/
 * 
 * @param line
 * @return
 */
private int getGroupId(String line) throws UserInfoException {

    int gidInt = -1;
    String[] fields = getElements(line);
    if ((fields != null) && (fields.length > 2) && (fields[2] != null)) {
        log.trace("field[2], GID ='" + fields[2] + "'");
        try {
            Long groupLong = new Long(Long.parseLong(fields[2]));
            if (groupLong.intValue() == groupLong.longValue()) {
                // The number in the output string fits in an integer (is at most 16
                // bits)
                gidInt = groupLong.intValue();
            } else {
                // The number in the output string does not fits in an integer (is
                // between 17 and 32 bits)
                log.warn("Group named '" + fields[2] + "' has a 32 bit GID " + groupLong.longValue()
                        + " . Long GID are not managed by LCMAPS. Ignoring the group");
            }
        } catch (NumberFormatException nfe) {
            log.error("Group named '" + fields[2]
                    + "' return a result different from a long. NumberFormatException : " + nfe);
            throw new UserInfoException("Group named '" + fields[2]
                    + "' return a result different from a long. NumberFormatException : " + nfe);
        }
    }
    return gidInt;
}

From source file:com.mauersu.util.redis.DefaultValueOperations.java

public Integer append(K key, String value) {
    final byte[] rawKey = rawKey(key);
    final byte[] rawString = rawString(value);

    return execute(new RedisCallback<Integer>() {

        public Integer doInRedis(RedisConnection connection) {
            connection.select(dbIndex);/*from  w w w  . j av a 2  s.c  o  m*/
            final Long result = connection.append(rawKey, rawString);
            return (result != null) ? result.intValue() : null;
        }
    }, true);
}

From source file:it.grid.storm.namespace.util.userinfo.UserInfoCommand.java

/**
 * //ww w . j  ava 2s  .  co  m
 * @param parameters
 * @return
 * @throws UserInfoException
 */
public int retrieveGroupID(UserInfoParameters parameters) throws UserInfoException {

    int groupId = -1;
    String[] command = buildCommandString(parameters);

    StringBuffer commandOutput = new StringBuffer();
    for (String element : command) {
        commandOutput.append(element).append(" ");
        log.debug("UserInfo Command INPUT String : " + commandOutput.toString());
    }
    String output = getOutput(command);
    if ((output != null) && (output.length() > 0)) {
        try {
            Long groupLong = new Long(Long.parseLong(output));
            if (groupLong.intValue() == groupLong.longValue()) {
                // The number in the output string fits in an integer (is at most 16
                // bits)
                groupId = groupLong.intValue();
            } else {
                // The number in the output string does not fits in an integer (is
                // between 17 and 32 bits)
                log.warn("Group named '" + parameters + "' has a 32 bit GID " + groupLong.longValue()
                        + " . Long GID are not managed by LCMAPS. Ignoring the group");
            }
        } catch (NumberFormatException nfe) {
            log.error("Group named '" + parameters
                    + "' return a result different from a long. NumberFormatException : " + nfe);
            throw new UserInfoException("Group named '" + parameters
                    + "' return a result different from a long. NumberFormatException : " + nfe);
        }
    } else {
        throw new UserInfoException(
                "Group named '" + parameters + "' return a result different from a integer");
    }
    return groupId;
}

From source file:it.jugpadova.controllers.BinController.java

/**
 * Produce the speaker image from the session, or the default no logo image.
 */// w w w  .j  av a  2 s  .  c  o m
@RequestMapping
public void pictureSpeakerInSession(HttpServletRequest req, HttpServletResponse res) throws IOException {
    String s = req.getParameter("indexSpeaker");
    if (StringUtils.isEmpty(s))
        return;
    Long id = new Long(s);
    List<Speaker> speakers = ((Event) req.getSession().getAttribute("event")).getSpeakers();
    byte[] pictureSpeaker = speakers.get(id.intValue() - 1).getPicture();
    flushResponse(pictureSpeaker, "pictureSpeaker", "noSpeakerImage", res);
}

From source file:edu.harvard.iq.dataverse.GuestbookPage.java

public void removeCustomQuestionValue(CustomQuestion cq, Long index) {
    cq.removeCustomQuestionValue(index.intValue());
}

From source file:mx.edu.um.mateo.general.dao.impl.EmpresaDaoHibernate.java

@Override
@Transactional(readOnly = true)//from  w  w  w.jav  a 2s .c om
public Map<String, Object> lista(Map<String, Object> params) {
    log.debug("Buscando lista de empresas con params {}", params);
    if (params == null) {
        params = new HashMap<>();
    }

    if (!params.containsKey("max")) {
        params.put("max", 10);
    } else {
        params.put("max", Math.min((Integer) params.get("max"), 100));
    }

    if (params.containsKey("pagina")) {
        Long pagina = (Long) params.get("pagina");
        Long offset = (pagina - 1) * (Integer) params.get("max");
        params.put("offset", offset.intValue());
    }

    if (!params.containsKey("offset")) {
        params.put("offset", 0);
    }
    Criteria criteria = currentSession().createCriteria(Empresa.class);
    Criteria countCriteria = currentSession().createCriteria(Empresa.class);

    if (params.containsKey("organizacion")) {
        criteria.createCriteria("organizacion").add(Restrictions.idEq(params.get("organizacion")));
        countCriteria.createCriteria("organizacion").add(Restrictions.idEq(params.get("organizacion")));
    }

    if (params.containsKey("filtro")) {
        String filtro = (String) params.get("filtro");
        Disjunction propiedades = Restrictions.disjunction();
        propiedades.add(Restrictions.ilike("nombre", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("nombreCompleto", filtro, MatchMode.ANYWHERE));
        criteria.add(propiedades);
        countCriteria.add(propiedades);
    }

    if (params.containsKey("order")) {
        String campo = (String) params.get("order");
        if (params.get("sort").equals("desc")) {
            criteria.addOrder(Order.desc(campo));
        } else {
            criteria.addOrder(Order.asc(campo));
        }
    } else {
        criteria.addOrder(Order.asc("nombre"));
    }

    if (!params.containsKey("reporte")) {
        criteria.setFirstResult((Integer) params.get("offset"));
        criteria.setMaxResults((Integer) params.get("max"));
    }
    params.put("empresas", criteria.list());

    countCriteria.setProjection(Projections.rowCount());
    params.put("cantidad", (Long) countCriteria.list().get(0));

    return params;
}

From source file:edu.harvard.iq.dataverse.GuestbookPage.java

public String removeCustomQuestion(Long index) {
    guestbook.removeCustomQuestion(index.intValue());
    return "";
}

From source file:io.codis.nedis.handler.RedisResponseDecoder.java

private boolean decode(ByteBuf in, List<Object> out, Object nullValue) throws Exception {
    if (in.readableBytes() < 2) {
        return false;
    }//w ww.  jav a  2  s. c om
    byte b = in.readByte();
    switch (b) {
    case '+': {
        String reply = decodeString(in);
        if (reply == null) {
            return false;
        }
        out.add(reply);
        return true;
    }
    case '-': {
        String reply = decodeString(in);
        if (reply == null) {
            return false;
        }
        out.add(new RedisResponseException(reply));
        return true;
    }
    case ':': {
        Long reply = decodeLong(in);
        if (reply == null) {
            return false;
        }
        out.add(reply);
        return true;
    }
    case '$': {
        Long numBytes = decodeLong(in);
        if (numBytes == null) {
            return false;
        }
        if (numBytes.intValue() == -1) {
            out.add(nullValue);
            return true;
        }
        if (in.readableBytes() < numBytes.intValue() + 2) {
            return false;
        }
        if (in.getByte(in.readerIndex() + numBytes.intValue()) != '\r'
                || in.getByte(in.readerIndex() + numBytes.intValue() + 1) != '\n') {
            throw new ProtocolException("Response is not ended by CRLF");
        }
        byte[] reply = new byte[numBytes.intValue()];
        in.readBytes(reply);
        // skip CRLF
        in.skipBytes(2);
        out.add(reply);
        return true;
    }
    case '*': {
        Long numReplies = decodeLong(in);
        if (numReplies == null) {
            return false;
        }
        if (numReplies.intValue() == -1) {
            out.add(nullValue);
            return true;
        }
        List<Object> replies = new ArrayList<>();
        for (int i = 0; i < numReplies.intValue(); i++) {
            if (!decode(in, replies, null)) {
                return false;
            }
        }
        out.add(replies);
        return true;
    }
    default:
        throw new ProtocolException("Unknown leading char: " + (char) b);
    }
}

From source file:org.tonguetied.usermanagement.UserRepositoryImpl.java

public PaginatedList<User> getUsers(final Integer firstResult, final Integer maxResults) {
    Query query = getSession().getNamedQuery(QUERY_GET_USERS);
    query.setCacheable(true);//from   w ww.  j a  v  a 2  s. c o m
    if (firstResult != null)
        query.setFirstResult(firstResult);
    if (maxResults != null)
        query.setMaxResults(maxResults);

    Long maxListSize = 0L;
    final List<User> queryList = query.list();
    if (queryList.size() > 0)
        maxListSize = (Long) getSession().getNamedQuery(QUERY_USER_COUNT).uniqueResult();

    return new PaginatedList<User>(queryList, maxListSize.intValue());
}

From source file:com.happyblueduck.lembas.datastore.LembasEntity.java

public void setStatus(Long l) {
    setStatus(l.intValue());
}