Example usage for java.lang Long longValue

List of usage examples for java.lang Long longValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public long longValue() 

Source Link

Document

Returns the value of this Long as a long value.

Usage

From source file:codeswarm.repository.svn.SVNHistory.java

/**
 * looks up the cache. Stops proceeding if a cached version for this
 * repository was found./*from ww  w. ja  v a2s . co m*/
 * @param pRevision the latest repository revision.
 * @return false if a cached version was found, true if the history shall
 * be fetched from repository.
 */
public boolean handleFetchingLatestRepositoryRevision(Long pRevision) {
    long revision = pRevision.longValue();
    Preferences p = Preferences.userNodeForPackage(SVNHistory.class);
    long l = p.getLong(Integer.toString(this.url.hashCode()), -1l);
    if (l == revision) {
        if (logger.isDebugEnabled()) {
            logger.debug("skip fetching " + String.valueOf(l) + " (latest revision is " + revision + ") for "
                    + this.url);
        }
        return false;
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("proceed fetching (latest revision is " + String.valueOf(pRevision)
                    + " , cached revision is " + String.valueOf(l) + " for repository " + this.url);
        }
        Preferences.userNodeForPackage(SVNHistory.class).putLong(Integer.toString(this.url.hashCode()),
                revision);
        try {
            Preferences.userNodeForPackage(SVNHistory.class).flush();
        } catch (BackingStoreException ex) {
            logger.error(null, ex);
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("fetching until revision " + revision);
    }
    return true;
}

From source file:com.hichinaschool.flashcards.libanki.Utils.java

public static long[] toPrimitive(Collection<Long> array) {
    long[] results = new long[array.size()];
    if (array != null) {
        int i = 0;
        for (Long item : array) {
            results[i++] = item.longValue();
        }//from w  w  w. j  av  a 2 s .c o  m
    }
    return results;
}

From source file:com.turbospaces.network.NetworkCommunicationDispatcher.java

/**
 * send message(in form of {@link MethodCall}) to the remote destination with assigned correlation id.
 * //from w w  w .ja  v a  2  s . c  o  m
 * @param destinations
 *            the target server nodes
 * @param methodCall
 *            remote method call
 * @param objectBuffer
 *            kryo's object buffer for entity serialization
 * @return original methodCall (pre-populated with correlation id)
 */
public MethodCall[] sendAndReceive(final MethodCall methodCall, final ObjectBuffer objectBuffer,
        final Address... destinations) {
    int size = destinations.length;
    MethodCall[] result = new MethodCall[size];
    Long[] ids = new Long[size];
    Object[] monitors = new Object[size];
    Message[] messages = new Message[size];

    for (int i = 0; i < size; i++) {
        Long correlationId = correlationIds.incrementAndGet();
        methodCall.setCorrelationId(correlationId.longValue());

        Message message = new Message();
        message.setSrc(configuration.getJChannel().getAddress());
        message.setDest(destinations[i]);
        message.setBuffer(objectBuffer.writeClassAndObject(methodCall));

        try {
            monitors[i] = requestResponseCorrelator.put(correlationId, null);
            ids[i] = correlationId;
            messages[i] = message;
            configuration.getJChannel().send(message);
            LOGGER.debug("sent jgroups message with correlation_id={} and destinations={}, methodCall={}",
                    new Object[] { correlationId, destinations, methodCall });
        } catch (Exception t) {
            requestResponseCorrelator.clear(correlationId);
            throw new RemoteConnectFailureException("unable to send message to " + destinations[i], t);
        }
    }

    // now collect all results in synchronous manner
    for (int i = 0; i < size; i++) {
        Long id = ids[i];
        Object monitor = monitors[i];
        result[i] = requestResponseCorrelator.responseFor(id, monitor,
                configuration.getCommunicationTimeoutInMillis());
    }

    return verifyNoExceptions(result, messages, methodCall);
}

From source file:cherry.example.web.basic.ex10.BasicEx10ControllerImpl.java

@Override
public ModelAndView execute(BasicEx10Form form, BindingResult binding, Authentication auth, Locale locale,
        SitePreference sitePref, NativeWebRequest request) {

    if (hasErrors(form, binding)) {
        return withViewname(viewnameOfStart).build();
    }//w  w w  . j a  va  2 s. co m

    if (!oneTimeTokenValidator.isValid(request.getNativeRequest(HttpServletRequest.class))) {
        LogicalErrorUtil.rejectOnOneTimeTokenError(binding);
        return withViewname(viewnameOfStart).build();
    }

    Long id = service.create(form);
    checkState(id != null, "failed to create: form=%s", form);

    return redirect(redirectOnExecute(id.longValue())).build();
}

From source file:com.romeikat.datamessie.core.base.dao.impl.AbstractEntityWithGeneratedIdDaoTest.java

@Test
public void getMaxId() {
    final Long maxId = dao.getMaxId(sessionProvider.getStatelessSession());
    assertEquals(3l, maxId.longValue());

    dbSetupTracker.skipNextLaunch();/*  w  w  w. j a  va2s. c om*/
}

From source file:gridool.deployment.GridPerNodeClassLoader.java

Class<?> defineClassIfNeeded(String clsName, byte[] b, long timestamp) {
    final Class<?> loaded = findLoadedClass(clsName);
    if (loaded != null) {
        final Long prevTimestamp = networkLoadedClazzWithTimestamp.get(clsName);
        if (prevTimestamp == null) {// the given class is already loaded locally
            return loaded;
        }/*from  w w  w .j  a va  2  s.com*/
        if (prevTimestamp.longValue() >= timestamp) {// previously loaded class is older than the given class
            return loaded;
        }
        return null;
    }
    final Class<?> defined = defineClass(clsName, b, 0, b.length);
    networkLoadedClazzWithTimestamp.put(clsName, timestamp);
    if (LOG.isInfoEnabled()) {
        LOG.info("A class '" + clsName + "' with timestamp '" + timestamp + "' is defined");
    }
    return defined;
}

From source file:de.berlios.jhelpdesk.dao.jpa.TicketCategoryDAOJpa.java

@Transactional(readOnly = false)
public void insertRootCategory(final TicketCategory rootCategory) {
    this.jpaTemplate.execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query getMaxTRightQuery = em.createNativeQuery("SELECT max(t_right) FROM ticket_category",
                    Long.class);
            final Long maxTRight = (Long) getMaxTRightQuery.getSingleResult();

            rootCategory.setLeft(new Long(maxTRight.longValue() + 1));
            rootCategory.setRight(new Long(maxTRight.longValue() + 2));
            rootCategory.setDepth(0);//from  ww w.j  a  v a 2 s  . c  o  m
            em.persist(rootCategory);
            return null;
        }
    });
}

From source file:org.kuali.mobility.push.service.DeviceServiceImplTest.java

@Test
public void testCountDevicesByType() {
    Long count = getService().countDevices("Android");
    assertEquals("Found incorrect number of Android devices.", 2L, count.longValue());
}

From source file:com.anite.antelope.modules.actions.AntelopeSessionValidator.java

/**
 * @param data//w  w w.j  a  v a  2 s.com
 * @param conf
 */
private void checkForNoCacheId(RunData data, Configuration conf) {
    long requestTime;
    // the session_access_counter can be placed as a hidden field in
    // forms. This can be used to prevent a user from using the
    // browsers back button and submitting stale data.
    if (!data.getParameters().containsKey("nocacheid")) {
        //can't compare cache ids so return
        return;
    }
    requestTime = data.getParameters().getLong("nocacheid");

    /*
     * The following few lines of code take care of the instances where the
     * request is being forwarded from a servlet (or something similar)
     * within the same context. In this instance, it is possible that the
     * cacheid will not be present in the request parameters. This code
     * tries to obtain the requestTime from the request attributes instead,
     * effectively allowing the forwarded request to successfully pass
     * through this validation. Added by SPC on 16 December 2003 to cater
     * for TRIM integration
     */
    if (requestTime == 0) {
        Long noCache = (Long) data.getRequest().getAttribute("nocacheid");
        if (noCache != null) {
            requestTime = noCache.longValue();
        }
    }

    Long lrt = (Long) data.getSession().getAttribute("lastRequestTime");
    long lastRequestTime = 0;
    if (lrt != null) {
        lastRequestTime = lrt.longValue();
    }
    if (requestTime <= lastRequestTime) {
        if (!((requestTime == 0) && (lastRequestTime == 0))) {
            data.getTemplateInfo().setScreenTemplate(conf.getString(TurbineConstants.TEMPLATE_INVALID_STATE));
            log.error("Found an invalid request");

            data.setScreen(null);
            data.setAction(null);

            TemplateScreen.setTemplate(data, ZebraHelper.getInstance().getTaskListScreenName());

        }
    }
    data.getSession().setAttribute("lastRequestTime", new Long(requestTime));

}

From source file:com.redhat.rhn.manager.configuration.ConfigFileBuilder.java

/**
 * Updates a config file//from   w w w  .  j a v  a  2s . c om
 * depending on the data in the given  configFileForm..
 * @param form the ConfigFileData form containing the input data
 * @param user the logged in user.
 * @param file the config file to update.
 * @return the create revision of the file.
 * @throws ValidatorException in the case of invalid data.
 */
public ConfigRevision update(ConfigFileData form, User user, ConfigFile file) throws ValidatorException {
    form.validatePath();
    ValidatorResult result;
    ConfigRevision latestRevision = file.getLatestConfigRevision();
    if (!form.getType().equals(latestRevision.getConfigFileType())) {

        LocalizationService ls = LocalizationService.getInstance();
        String fromType = ls.getMessage(latestRevision.getConfigFileType().getMessageKey());
        String toType = ls.getMessage(form.getType().getMessageKey());
        ValidatorException.raiseException("error.config-cannot-change-type", form.getPath(), fromType, toType);
    }

    try {
        if (!StringUtils.isBlank(form.getRevNumber())) {
            Long l = Long.parseLong(form.getRevNumber());
            if (l.longValue() <= latestRevision.getRevision()) {
                result = new ValidatorResult();
                result.addError(new ValidatorError("error.config.revnum.too-old", form.getPath()));
                throw new ValidatorException(result);
            }
        } else {
            form.setRevNumber(String.valueOf(latestRevision.getRevision() + 1));
        }
    } catch (NumberFormatException nfe) {
        result = new ValidatorResult();
        result.addError(new ValidatorError("error.config.revnum.invalid", form.getPath()));
        throw new ValidatorException(result);
    }

    form.validate(false);
    return makeNewRevision(user, form, file, false);
}