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:com.redhat.rhn.manager.rhnpackage.PackageManager.java

/**
 * Helper method to figure out the dependency modifier. I honestly have no clue
 * why the bitwise ANDs work or what the sense field in the db really means. This was
 * pretty much a line for line port of the perl code.
 * @param sense A number whose number can tell us what kind of modifier is needed
 * @param version The version of the dependency we're investigating
 * @return Returns a string in the form of something like '>= 4.1-3'
 *//*from   w  w w  .  j av a  2  s. com*/
public static String getDependencyModifier(Long sense, String version) {
    StringBuilder depmod = new StringBuilder();

    if (sense != null) { //how ironic ;)
        int senseIntVal = sense.intValue();
        //Bitwise AND with 4 --> '>'
        if ((senseIntVal & 4) > 0) {
            depmod.append(">");
        }
        //Bitwise AND with 2 --> '<'
        else if ((senseIntVal & 2) > 0) {
            depmod.append("<");
        }
        //Bitwise AND with 8 tells us whether or not this should have an '=' on it
        if ((senseIntVal & 8) > 0) {
            depmod.append("=");
        }
        //Add the version so we get something like '<= 4.0-1'
        depmod.append(" ");
        depmod.append(version);
    } else {
        //Robin thinks that this represents a "anything but this version" scenario.
        depmod.append("-");
        depmod.append(version);
    }

    return depmod.toString();
}

From source file:mx.edu.um.mateo.rh.dao.impl.EmpleadoDaoHibernate.java

/**
 * @see mx.edu.um.mateo.rh.dao.EmpleadoDao#lista(java.util.Map)
 *//*from w  w  w.  j a v a  2  s  .c  o  m*/
@Override
public Map<String, Object> lista(Map<String, Object> params) {
    log.debug("Buscando lista de empleados 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(Empleado.class);
    Criteria countCriteria = currentSession().createCriteria(Empleado.class);

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

    if (params.containsKey("filtro")) {
        String filtro = (String) params.get("filtro");
        Disjunction propiedades = Restrictions.disjunction();
        propiedades.add(Restrictions.ilike("clave", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("nombre", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("apMaterno", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("apPaterno", 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));
        }
    }

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

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

    log.debug("Elementos en lista de empleados {}", params.get(Constants.EMPLEADO_LIST));

    return params;
}

From source file:GenricDAOImpl.java

/**
 * statementName  ?statementNameCount SQL
 * @param statementName/*from   www . jav a2s.  co m*/
 * @param QueryCondition condition  pageNo,pageSize
 * @return
 */
@Override
public Pagination<Object> queryForPage(final String statementName, final QueryCondition condition) {
    Long count = (Long) getSqlMapClientTemplate()
            .queryForObject(getQualifiedStatementName(statementName + COUNT), condition.asMap());
    List<Object> data = getSqlMapClientTemplate().queryForList(getQualifiedStatementName(statementName),
            condition.asMap());
    Pagination<Object> page = new Pagination<Object>(condition.get("pageNo", Integer.class),
            condition.get("pageSize", Integer.class));
    page.setTotal(count.intValue());
    page.setData(data);
    return page;
}

From source file:org.esupportail.portlet.filemanager.services.sardine.SardineAccessImpl.java

@Override
public DownloadFile getFile(String path, SharedUserPortletParameters userParameters) {
    try {/* w  w  w.j  av a  2  s .co  m*/
        this.open(userParameters);

        DavResource resource = null;
        List<DavResource> resources = root.list(this.uri + path);
        resource = resources.get(0);

        Long size = resource.getContentLength();
        String baseName = resource.getName();
        String contentType = JsTreeFile.getMimeType(baseName.toLowerCase());
        InputStream inputStream = root.get(this.uri + path);

        return new DownloadFile(contentType, size.intValue(), baseName, inputStream);
    } catch (SardineException se) {
        log.error("Error in download of " + this.uri + path, se);
    } catch (IOException ioe) {
        log.error("IOException downloading this file  : " + this.uri + path, ioe);
    }
    return null;
}

From source file:org.squale.squaleweb.util.graph.BubbleMaker.java

/**
 * Constructeur avec juste la position des axes Permet de factoriser le traitement du cas null
 * //from  w ww. ja  va 2s. co  m
 * @param pHorizontalAxisPos la position de l'axe horizontal
 * @param pVerticalAxisPos la position de l'axe vertical
 */
public BubbleMaker(Long pHorizontalAxisPos, Long pVerticalAxisPos) {
    this();
    // Si c'est null on garde la valeur par dfaut
    if (pHorizontalAxisPos != null & pHorizontalAxisPos.intValue() != -1) {
        mHorizontalAxisPos = pHorizontalAxisPos.intValue();
    }
    // Si c'est null on garde la valeur par dfaut
    if (pVerticalAxisPos != null && pVerticalAxisPos.intValue() != -1) {
        mVerticalAxisPos = pVerticalAxisPos.intValue();
    }
}

From source file:de.powerstaff.business.dao.hibernate.NavigatingDAOHibernateImpl.java

public T findByRecordNumber(final Long aNumber) {
    if (aNumber == null) {
        return findFirst();
    }/*from  w w  w .j  a v a2s .com*/

    return (T) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session aSession) {
            Query theQuery = aSession.createQuery("from " + getEntityClass().getName() + " order by id");
            theQuery.setFirstResult(aNumber.intValue() - 1);
            theQuery.setMaxResults(1);
            Iterator theIt = theQuery.iterate();
            if (theIt.hasNext()) {
                return theIt.next();
            }
            return findFirst();
        }

    });
}

From source file:grisu.frontend.view.swing.jobmonitoring.single.appSpecific.Gold.java

protected void calculateCurrentLigandNoAndCpusAndLicenses() {

    if (StringUtils.isBlank(currentStatusPath)) {
        return;/*from  ww w.  ja v  a  2 s  .  c o  m*/
    }

    getCpusProgressBar().setString("Updating...");
    getLicensesAllProgressbar().setString("Updating...");
    getLicensesJobProgressBar().setString("Updating...");
    getWalltimeProgressbar().setString("Updating...");
    getProgressBar().setString("Updating...");

    List<String> lines = null;
    Long timestampTemp = -1L;
    try {
        final File currentStatusFile = fm.downloadFile(currentStatusPath);
        lines = FileUtils.readLines(currentStatusFile);
        timestampTemp = fm.getLastModified(currentStatusPath);
    } catch (final Exception e) {
        myLogger.error(e.getLocalizedMessage(), e);
        getCpusProgressBar().setString("n/a");
        getLicensesAllProgressbar().setString("n/a");
        getLicensesJobProgressBar().setString("n/a");
        getWalltimeProgressbar().setString("n/a");
        getProgressBar().setString("n/a");
        return;
    }

    final Long deltaInSeconds = (timestampTemp - startTimestamp) / 1000L;
    getWalltimeProgressbar().setValue(deltaInSeconds.intValue());

    final Long hours = deltaInSeconds / 3600L;
    getWalltimeProgressbar().setString(hours + "  (of " + (walltime / 3600) + ")");

    if (lines.size() != 1) {
        getCpusProgressBar().setString("Error...");
        getLicensesAllProgressbar().setString("Error...");
        getLicensesJobProgressBar().setString("Error...");
        return;
    }

    final String[] tokens = lines.get(0).split(",");

    int cpusTemp = -1;
    try {
        cpusTemp = Integer.parseInt(tokens[1]);
    } catch (final Exception e) {
        myLogger.error(e.getLocalizedMessage(), e);
    }

    int licensesUserTemp = -1;
    try {
        licensesUserTemp = Integer.parseInt(tokens[2]);
    } catch (final Exception e) {
        myLogger.error(e.getLocalizedMessage(), e);
    }

    int licensesAllTemp = -1;
    try {
        licensesAllTemp = Integer.parseInt(tokens[3]);
    } catch (final Exception e) {
        myLogger.error(e.getLocalizedMessage(), e);
    }

    if (cpusTemp <= 0) {
        getCpusProgressBar().setString("n/a");
        getCpusProgressBar().setValue(0);
    } else {
        getCpusProgressBar().setString(cpusTemp + "   (of " + noCpus + ")");
        getCpusProgressBar().setValue(cpusTemp);
    }
    if (licensesUserTemp <= 0) {
        getLicensesJobProgressBar().setString("n/a");
        getLicensesJobProgressBar().setValue(0);
    } else {
        getLicensesJobProgressBar().setString(licensesUserTemp + "   (of " + noCpus + ")");
        getLicensesJobProgressBar().setValue(licensesUserTemp);
    }
    if (licensesAllTemp <= 0) {
        getLicensesAllProgressbar().setString("n/a");
        getLicensesAllProgressbar().setValue(0);
    } else {
        getLicensesAllProgressbar().setString(licensesAllTemp + "   (of " + GOLD_LICENSES + ")");
        getLicensesAllProgressbar().setValue(licensesAllTemp);
    }

    Integer ligands = -1;
    try {
        ligands = Integer.parseInt(tokens[4]);
    } catch (final Exception e) {
        myLogger.error(e.getLocalizedMessage(), e);
        getProgressBar().setString("n/a");
        getProgressBar().setValue(0);
        return;
    }

    getProgressBar().setString(ligands.toString() + "  (of " + noLigands + ")");
    getProgressBar().setValue(ligands);
}

From source file:GenricDAOImpl.java

/**
 * statementName  ?statementNameCount SQL
 * @param statementName/*from  www  .  ja  v a 2s  .com*/
 * @return
 */
@Override
public <E> Pagination<E> queryForPage(Class<E> classz, final String statementName, final PageParam param) {
    Long count = (Long) getSqlMapClientTemplate()
            .queryForObject(getQualifiedStatementName(statementName + COUNT), param);
    @SuppressWarnings("unchecked")
    List<E> data = getSqlMapClientTemplate().queryForList(getQualifiedStatementName(statementName), param);
    Pagination<E> page = new Pagination<E>(param.getPageNumber(), param.getLength());//condition.get("pageNo", Integer.class),condition.get("pageSize", Integer.class));
    page.setTotal(count.intValue());
    page.setData(data);
    return page;
}

From source file:dk.netarkivet.harvester.harvesting.controller.JMXHeritrixController.java

/** @see HeritrixController#getCurrentProcessedKBPerSec() */
public int getCurrentProcessedKBPerSec() {
    Long currentDownloadRate = (Long) getCrawlJobAttribute(CURRENT_KB_RATE_ATTRIBUTE);
    if (currentDownloadRate == null) {
        return 0;
    }/*from   w w w  . j a v  a2  s .  c om*/
    return currentDownloadRate.intValue();
}

From source file:com.abiquo.server.core.enterprise.RoleDAO.java

public Collection<Role> find(final Enterprise enterprise, final String filter, final String orderBy,
        final boolean desc, final Integer offset, final Integer numResults,
        final boolean discardNullEnterprises) {
    Criteria criteria = createCriteria(enterprise, filter, orderBy, desc, discardNullEnterprises);

    Long total = count(criteria);

    criteria = createCriteria(enterprise, filter, orderBy, desc, discardNullEnterprises);

    criteria.setFirstResult(offset);//from w w w  .j a v  a 2s .c o  m
    criteria.setMaxResults(numResults);

    List<Role> result = getResultList(criteria);

    PagedList<Role> page = new PagedList<Role>();
    page.addAll(result);
    page.setCurrentElement(offset);
    page.setPageSize(numResults);
    page.setTotalResults(total.intValue());

    return page;
}