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.geosolutions.geofence.gui.server.service.impl.InstancesManagerServiceImpl.java

public PagingLoadResult<GSInstance> getInstances(int offset, int limit, boolean full)
        throws ApplicationException {
    int start = offset;

    List<GSInstance> instancesListDTO = new ArrayList<GSInstance>();

    if (full) {//from w  w w .j a v a2 s  . c o m
        GSInstance all = new GSInstance();
        all.setId(-1);
        all.setName("*");
        all.setBaseURL("*");
        instancesListDTO.add(all);
    }

    long instancesCount = geofenceRemoteService.getInstanceAdminService().getCount(null) + 1;

    Long t = new Long(instancesCount);

    int page = (start == 0) ? start : (start / limit);

    List<ShortInstance> instancesList = geofenceRemoteService.getInstanceAdminService().getList(null, page,
            limit);

    if (instancesList == null) {
        if (logger.isErrorEnabled()) {
            logger.error("No server instace found on server");
        }
        throw new ApplicationException("No server instance found on server");
    }

    Iterator<ShortInstance> it = instancesList.iterator();

    while (it.hasNext()) {
        long id = it.next().getId();
        it.geosolutions.geofence.core.model.GSInstance remote = geofenceRemoteService.getInstanceAdminService()
                .get(id);

        GSInstance local = new GSInstance();
        local.setId(remote.getId());
        local.setName(remote.getName());
        local.setDescription(remote.getDescription());
        local.setDateCreation(remote.getDateCreation());
        local.setBaseURL(remote.getBaseURL());
        local.setUsername(remote.getUsername());
        local.setPassword(remote.getPassword());
        instancesListDTO.add(local);
    }

    return new RpcPageLoadResult<GSInstance>(instancesListDTO, offset, t.intValue());
}

From source file:org.opennms.ng.services.collectd.Collectd.java

/**
 * This method is responsible for handling nodeDeleted events.
 *
 * @param event The event to process.//from  ww w .jav  a2  s. c  o  m
 * @throws InsufficientInformationException
 */
private void handleNodeCategoryMembershipChanged(Event event) throws InsufficientInformationException {
    EventUtils.checkNodeId(event);

    Long nodeId = event.getNodeid();

    unscheduleNodeAndMarkForDeletion(nodeId);

    LOG.debug("nodeCategoryMembershipChanged: unscheduling nodeid {} completed.", nodeId);

    scheduleNode(nodeId.intValue(), true);
}

From source file:persistence.OrderDao.java

public int getCountAll(OrderStatus status) {
    Criteria crit = getCriteriaDistinctRootEntity(Order.class);
    crit.setProjection(Projections.rowCount());
    if (status != null) {
        crit.add(Restrictions.eq("status", status));
    }/*from  w ww .j a va2s .  c  o m*/
    Long count = (Long) crit.uniqueResult();
    return count.intValue();
}

From source file:persistence.OrderDao.java

/**
 *
 * @param status//from   w w w  .jav a 2  s  . co  m
 * @return ? ,   ?    
 *  
 */
public int getCountOrdersWithFiles(OrderStatus status) {
    Criteria crit = getCriteriaDistinctRootEntity(Order.class);
    crit.setProjection(Projections.rowCount());
    if (status != null) {
        crit.add(Restrictions.eq("status", status));
    }
    crit.add(Restrictions.or(Restrictions.isNotEmpty("files"), Restrictions.isNotEmpty("readyFiles")));
    Long count = (Long) crit.uniqueResult();
    return count.intValue();
}

From source file:com.redhat.lightblue.crud.ldap.LdapCRUDController.java

@Override
public CRUDFindResponse find(CRUDOperationContext ctx, QueryExpression query, Projection projection, Sort sort,
        Long from, Long to) {

    if (query == null) {
        throw new IllegalArgumentException("No query was provided.");
    }/*from  w  w w  .jav a  2s  .  com*/
    if (projection == null) {
        throw new IllegalArgumentException("No projection was provided");
    }

    EntityMetadata md = ctx.getEntityMetadata(ctx.getEntityName());
    LdapDataStore store = LdapCrudUtil.getLdapDataStore(md);

    CRUDFindResponse response = new CRUDFindResponse();
    response.setSize(0);

    LDAPConnection connection = getNewLdapConnection(store);

    LdapFieldNameTranslator fieldNameTranslator = LdapCrudUtil.getLdapFieldNameTranslator(md);

    try {
        //TODO: Support scopes other than SUB
        SearchRequest request = new SearchRequest(store.getBaseDN(), SearchScope.SUB,
                new FilterBuilder(fieldNameTranslator).build(query),
                translateFieldNames(fieldNameTranslator, gatherRequiredFields(md, projection, query, sort))
                        .toArray(new String[0]));
        if (sort != null) {
            request.addControl(new ServerSideSortRequestControl(false,
                    new SortTranslator(fieldNameTranslator).translate(sort)));
        }
        if ((from != null) && (from > 0)) {
            int endPos = to.intValue() - from.intValue();
            request.addControl(new VirtualListViewRequestControl(from.intValue(), 0, endPos, 0, null, false));
        }

        SearchResult result = connection.search(request);

        response.setSize(result.getEntryCount());
        ResultTranslator resultTranslator = new ResultTranslator(ctx.getFactory().getNodeFactory(), md,
                fieldNameTranslator);
        List<DocCtx> translatedDocs = new ArrayList<DocCtx>();
        for (SearchResultEntry entry : result.getSearchEntries()) {
            try {
                translatedDocs.add(resultTranslator.translate(entry));
            } catch (Exception e) {
                ctx.addError(Error.get(e));
            }
        }
        ctx.setDocuments(translatedDocs);

        Projector projector = Projector
                .getInstance(
                        Projection
                                .add(projection,
                                        new FieldAccessRoleEvaluator(md, ctx.getCallerRoles())
                                                .getExcludedFields(FieldAccessRoleEvaluator.Operation.find)),
                        md);
        for (DocCtx document : ctx.getDocumentsWithoutErrors()) {
            document.setOutputDocument(projector.project(document, ctx.getFactory().getNodeFactory()));
        }
    } catch (LDAPException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return response;
}

From source file:com.abssh.util.GenericDao.java

/**
 * countCriteria./* ww w  .j  a v a2 s.com*/
 */
@SuppressWarnings("unchecked")
protected int countCriteriaResult(final Criteria c) {
    CriteriaImpl impl = (CriteriaImpl) c;

    // Projection?ResultTransformer?OrderBy??,??Count?
    Projection projection = impl.getProjection();
    ResultTransformer transformer = impl.getResultTransformer();

    List<CriteriaImpl.OrderEntry> orderEntries = null;
    try {
        orderEntries = (List) ReflectionUtils.getFieldValue(impl, "orderEntries");
        ReflectionUtils.setFieldValue(impl, "orderEntries", new ArrayList());
    } catch (Exception e) {
        logger.error("can not throw Exception:{}", e.getMessage());
    }

    // Count
    Long ct = (Long) c.setProjection(Projections.rowCount()).uniqueResult();
    int totalCount = ct == null ? 0 : ct.intValue();

    // ?Projection,ResultTransformerOrderBy??
    c.setProjection(projection);

    if (projection == null) {
        c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
    }
    if (transformer != null) {
        c.setResultTransformer(transformer);
    }
    try {
        ReflectionUtils.setFieldValue(impl, "orderEntries", orderEntries);
    } catch (Exception e) {
        logger.error("can not throw Exception:{}", e.getMessage());
    }

    return totalCount;
}

From source file:edu.brown.api.BenchmarkComponent.java

/**
 * /*from   w  w w  .j a va2 s  . co m*/
 * @param txnName
 * @param weightIfNull
 * @return
 */
protected final Integer getTransactionWeight(String txnName, Integer weightIfNull) {
    if (debug.val)
        LOG.debug(String.format("Looking for txn weight for '%s' [weightIfNull=%s]", txnName, weightIfNull));

    Long val = this.m_txnWeights.get(txnName.toUpperCase());
    if (val != null) {
        return (val.intValue());
    } else if (m_txnWeightsDefault != null) {
        return (m_txnWeightsDefault);
    }
    return (weightIfNull);
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * @param dateType//from   w w w .  j  ava2s.c  om
 * @param srcList
 * @return
 */
private Vector<Pair<String, Integer>> getDateValuesFromListByTable(final DateType dateType,
        final String tableName) {
    String sql = "";
    switch (dateType) {
    case Time:
        sql = "SELECT hrs, COUNT(hrs) FROM (SELECT (hr + mn + sc) as hrs FROM (SELECT HOUR(TimestampCreated) as hr, ROUND(MINUTE(TimestampCreated) / 60) as mn, ROUND(SECOND(TimestampCreated) / 3600) as sc FROM "
                + tableName + " WHERE TimestampCreated > '2009-04-12') AS T1) as T2 GROUP BY hrs";
        break;

    case Monthly:
        sql = "SELECT nm,COUNT(mon) FROM (SELECT MONTH(TimestampCreated) as mon, MONTHNAME(TimestampCreated) as nm FROM "
                + tableName + " WHERE TimestampCreated > '2009-04-12') AS T1 GROUP BY mon";
        break;

    case Yearly:
        sql = "SELECT yr,count(yr) FROM (SELECT YEAR(TimestampCreated) as yr FROM " + tableName
                + " WHERE TimestampCreated > '2009-04-12') AS T1 group by yr";
        break;

    case Date:
        sql = "SELECT dt,count(dt) FROM (SELECT DATE(TimestampCreated) as dt FROM " + tableName
                + " WHERE TimestampCreated > '2009-04-12') AS T1 group by dt";
        break;

    case None:
        break;
    }

    Vector<Pair<String, Integer>> values = new Vector<Pair<String, Integer>>();
    for (Object[] colData : BasicSQLUtils.query(sql)) {
        Long longVal = (Long) colData[1];
        String desc = "";
        if (colData[0] instanceof String) {
            desc = (String) colData[0];

        } else if (colData[0] instanceof Long) {
            Long val = (Long) colData[0];
            desc = val.toString();

        } else if (colData[0] instanceof Date) {
            Date val = (Date) colData[0];
            desc = val.toString();

        } else if (colData[0] instanceof Integer) {
            Integer val = (Integer) colData[0];
            desc = val.toString();

        } else if (colData[0] instanceof BigDecimal) {
            BigDecimal val = (BigDecimal) colData[0];
            desc = String.format("%02d", val.intValue());

        } else if (colData[0] instanceof byte[]) {
            //Byte val = (Byte)colData[0]; 
            desc = new String((byte[]) colData[0]);
        } else {
            System.out.println(colData[0].getClass());
        }
        values.add(new Pair<String, Integer>(desc, longVal.intValue()));
    }
    return values;
}

From source file:fr.duminy.jbackup.swing.ProgressPanelTest.java

private void checkState(TaskState taskState, Long value, Long maxValue, Throwable error, Future<?> task) {
    assertThat(panel.getBorder()).isExactlyInstanceOf(TitledBorder.class);
    assertThatPanelHasTitle(panel, TITLE);

    JPanelFixture progressPanel = new JPanelFixture(robot(), panel);
    robot().settings().componentLookupScope(ComponentLookupScope.ALL);
    JProgressBarFixture progressBar = progressPanel.progressBar();
    robot().settings().componentLookupScope(ComponentLookupScope.SHOWING_ONLY);
    String expectedMessage;//from  ww  w .j av a  2s . c o m
    final boolean taskInProgress;
    switch (taskState) {
    case NOT_STARTED:
        taskInProgress = false;
        progressBar.requireIndeterminate().requireText("Not started");
        assertThat(panel.isFinished()).as("isFinished").isFalse();
        break;

    case TASK_DEFINED:
        taskInProgress = false;
        break;

    case STARTED:
        taskInProgress = (task != null);
        progressBar.requireIndeterminate().requireText("Estimating total size");
        assertThat(panel.isFinished()).as("isFinished").isFalse();
        break;

    case TOTAL_SIZE_COMPUTED:
    case PROGRESS:
        taskInProgress = (task != null);
        int iValue;
        int iMaxValue;
        if (maxValue > Integer.MAX_VALUE) {
            iValue = Utils.toInteger(value, maxValue);
            iMaxValue = Integer.MAX_VALUE;
        } else {
            iValue = value.intValue();
            iMaxValue = maxValue.intValue();
        }

        expectedMessage = format("%s/%s written (%1.2f %%)", byteCountToDisplaySize(value),
                byteCountToDisplaySize(maxValue), Utils.percent(value, maxValue));
        progressBar.requireDeterminate().requireValue(iValue).requireText(expectedMessage);
        assertThat(progressBar.component().getMinimum()).isEqualTo(0);
        assertThat(progressBar.component().getMaximum()).isEqualTo(iMaxValue);
        assertThat(panel.isFinished()).as("isFinished").isFalse();
        break;

    case FINISHED:
    default:
        taskInProgress = false;
        if (error == null) {
            progressBar.requireDeterminate().requireText("Finished");
        } else {
            expectedMessage = error.getMessage();
            if (expectedMessage == null) {
                expectedMessage = error.getClass().getSimpleName();
            }
            progressBar.requireDeterminate().requireText("Error : " + expectedMessage);
        }
        assertThat(panel.isFinished()).as("isFinished").isTrue();
        break;
    }

    Container parent = null;
    if (!TaskState.FINISHED.equals(taskState)) {
        // checks progress panel is visible
        parent = panel.getParent();
        assertThat(parent).isNotNull();
        assertThat(parent.getComponents()).contains(panel);
    }

    if (taskInProgress) {
        assertThat(panel.isFinished()).isFalse();
        assertThat(task.isCancelled()).as("task cancelled").isFalse();

        // cancel the task
        JButtonFixture cancelButton = progressPanel.button();
        cancelButton.requireText("").requireToolTip("Cancel the task");
        assertThat(cancelButton.component().getIcon()).isNotNull();
        cancelButton.click();

        // checks progress panel is not visible
        assertThat(panel.isFinished()).isTrue();
        assertThat(panel.getParent()).isNull();
        assertThat(parent.getComponents()).doesNotContain(panel);
        assertThat(task.isCancelled()).as("task cancelled").isTrue();
        assertThat(((TestableTask) task).getMayInterruptIfRunning()).as("MayInterruptIfRunning").isFalse();
    } else {
        // check no cancel button is visible if the task has been defined
        requireCancelButton(progressPanel, taskState == TaskState.TASK_DEFINED);
    }
}

From source file:edu.brown.benchmark.BenchmarkComponent.java

/**
 * /*from  w  w  w.  j a v a 2  s. c  om*/
 * @param txnName
 * @param weightIfNull
 * @return
 */
protected final Integer getTransactionWeight(String txnName, Integer weightIfNull) {
    Long val = this.m_txnWeights.get(txnName.toUpperCase());
    if (val != null) {
        return (val.intValue());
    } else if (m_txnWeightsDefault != null) {
        return (m_txnWeightsDefault);
    }
    return (weightIfNull);
}