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:com.apus.hades.admin.web.controller.ad.source.SourceController.java

/**
 * ajax ?./*ww w . j  av a  2s .  co m*/
 */
public void getSourceLimit() {
    JSONObject json = new JSONObject();
    JSONArray array = new JSONArray();
    boolean success = true;
    try {
        Long id = Struts2Utils.getLong("id");
        Long typeId = Struts2Utils.getLong("typeId");
        source = sourceManager.find(id);
        ShowType showType = showTypeManager.find(typeId);
        List<ShowLimit> limits = showType.getShowLimitList();
        List<SourceRelValue> values = null;
        // ? ?
        if (source.getAd_type_id().longValue() == typeId.longValue()) {
            values = source.getSourceRelValueList();
        }
        JSONObject obj;
        if (null != values && !values.isEmpty()) {
            ShowLimit limit;
            for (SourceRelValue value : values) {
                obj = new JSONObject();
                limit = showType.getShowLimit(value.getRel_ad_show_limit_id());
                if (null == limit) {
                    obj.put("fail", true);
                    obj.put("source", source.getId());
                } else {
                    obj.put("style", limit.getStyleEnum());
                    obj.put("size", limit.getPic_size());
                    obj.put("limit", limit.getLimit_size());
                    obj.put("proportion", limit.getPic_proportion());
                    obj.put("name", limit.getStyleEnum().getName());
                    obj.put("fail", false);
                }
                obj.put("value", getSourceVal(limit, value.getValue()));
                obj.put("id", value.getRel_ad_show_limit_id());
                obj.put("clickAction", value.getClick_action());
                obj.put("actionUrl", value.getAction_url());
                array.add(obj);
            }
        }
        // 
        if (null != limits && !limits.isEmpty()) {
            for (ShowLimit limit : limits) {
                if (!source.isExistsLimit(limit.getId())) {
                    obj = new JSONObject();
                    obj.put("id", limit.getId());
                    obj.put("style", limit.getStyleEnum());
                    obj.put("name", limit.getStyleEnum().getName());
                    obj.put("size", limit.getPic_size());
                    obj.put("proportion", limit.getPic_proportion());
                    obj.put("limit", limit.getLimit_size());
                    obj.put("value", StringUtils.EMPTY);
                    obj.put("fail", false);
                    array.add(obj);
                }
            }
        }
    } catch (Exception e) {
        success = false;
        e.printStackTrace();
        json.put("msg", e.getMessage());
    }
    json.put("success", success);
    json.put("array", array);
    Struts2Utils.renderJson(json);
}

From source file:com.acentera.utils.ProjectsHelpers.java

public static ProjectTasks createNewDroplet(Long projectId, Long providerId, JSONObject jsonData)
        throws Exception, RequestUnsuccessfulException, AccessDeniedException, ResourceNotFoundException {

    Droplet d = new Droplet();

    d.setName(jsonData.getString("name"));
    d.setImageId(jsonData.getInt("image_id"));

    d.setSizeId(jsonData.getInt("size_id"));

    /*// w  w w. j av  a2s .  com
    @SerializedName("image_id")
    private Integer imageId;
            
    @SerializedName("region_id")
    private Integer regionId;
            
    @SerializedName("size_id")
    private Integer sizeId;
    */

    ProjectProviders prov = ProjectImpl.getCloudProvider(projectId, providerId);

    DigitalOcean apiClient = new DigitalOceanClient(prov.getApikey(), prov.getSecretkey());

    List<SshKey> lstKeys = apiClient.getAvailableSshKeys();

    List<ProjectSshKey> lstProjectKeys = ProjectImpl.getAvailableSshKeys(projectId);

    String sshKeyIds = "";

    Droplet res = null;

    ProjectTasks task = new ProjectTasks();
    task.setName("Create Server");
    task.setType("server");
    task.setProviderId(prov.getId());
    task.setProjects(prov.getProject());
    ProjectImpl.save(task);

    ProjectRegions pr = ProjectRegionsImpl.getProjectRegionById(projectId, jsonData.getLong("region_id"));
    List<Region> lstRegions = apiClient.getAvailableRegions();
    Iterator<Region> itrRegion = lstRegions.iterator();
    Integer regionId = null;
    while (itrRegion.hasNext() && regionId == null) {
        Region r = itrRegion.next();
        if (r.getSlug().compareToIgnoreCase(pr.getSlug()) == 0) {
            regionId = r.getId();
        }
    }
    d.setRegionId(regionId);

    if (jsonData.has("sshkeys_id")) {

        JSONArray jsoKeyArray = jsonData.getJSONArray("sshkeys_id");
        String keysId = "";
        for (int i = 0; i < jsoKeyArray.size(); i++) {
            Long keyId = jsoKeyArray.getLong(i);

            ProjectSshKey currentKey = null;
            Iterator<ProjectSshKey> itrKeys = lstProjectKeys.iterator();
            while (itrKeys.hasNext() && currentKey == null) {
                ProjectSshKey key = itrKeys.next();
                if (key.getId().longValue() == keyId.longValue()) {
                    currentKey = key;
                }
            }

            if (currentKey == null) {
                //Uh Oh, the key does not exists on this project ???
                throw new Exception("KEY_NOT_FOUND");
            }
            //Ok key exists on this project great.... lets find if the api have it too..

            SshKey projectKey = null;
            Iterator<SshKey> itrProjKeys = lstKeys.iterator();
            while (itrProjKeys.hasNext() && projectKey == null) {
                SshKey key = itrProjKeys.next();

                if (key.getName().compareTo(currentKey.getName()) == 0) {
                    projectKey = key;
                }

            }

            if (projectKey == null) {
                //Key does not exists ? lets create it..
                projectKey = apiClient.addSshKey(currentKey.getName(), currentKey.getPublicKey());
            }

            //Ok at this point we have all the ssh key reqruied.. lets build the string..
            if (i == 0) {
                sshKeyIds = String.valueOf(projectKey.getId());
            } else {
                sshKeyIds += "," + projectKey.getId();
            }
        }
        res = apiClient.createDropletWithPrivateNetworking(d, sshKeyIds);

    } else {
        res = apiClient.createDropletWithPrivateNetworking(d);
    }

    task.setExtId(res.getEventId());
    ProjectImpl.update(task);

    Project p = ProjectImpl.getProject(projectId);
    Device device = new Device();
    device.setGUID(Utils.getUniqueGUID());
    //d.setId(task.getExtId());

    ProjectDevices pd = new ProjectDevices();
    pd.setProject(p);
    pd.setDevice(device);
    pd.setPartner_id(SecurityController.getUser().getPartnerId());

    pd.setExternalId(String.valueOf(res.getId()));

    pd.setProviders(prov);

    Logger.debug("SAVIGN DEVICE");
    HibernateSessionFactory.getSession().saveOrUpdate(device);
    Logger.debug("SAVIGN PROJECT DEVICE");
    HibernateSessionFactory.getSession().saveOrUpdate(pd);

    return task;

}

From source file:com.projity.job.Job.java

public void logEnd(String s) {
    Long t = (Long) times.get(s);
    if (t == null)
        log(s + "...end");
    else//from w ww .j av a 2  s.c om
        log(s + "...end, " + (System.currentTimeMillis() - t.longValue()) + " ms");
}

From source file:com.ebay.pulsar.metriccalculator.processor.MCSummingProcessor.java

private long getFrequencyByMetricName(String metricName) {
    Long frequency = metricFrequencies.get(metricName);
    if (frequency == null) {
        return -1;
    }//from ww w  .  jav  a  2  s  .co m
    return frequency.longValue();
}

From source file:com.redhat.rhn.frontend.action.multiorg.OrgDeleteAction.java

/** {@inheritDoc} */
@Override//www.  j a  v  a 2  s  . co  m
public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
        HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    Long oid = requestContext.getParamAsLong(RequestContext.ORG_ID);

    ActionForward retval = mapping.findForward(RhnHelper.DEFAULT_FORWARD);
    DynaActionForm dynaForm = (DynaActionForm) formIn;

    if (!AclManager.hasAcl("user_role(satellite_admin)", request, null)) {
        LocalizationService ls = LocalizationService.getInstance();
        PermissionException pex = new PermissionException("Only satellite admin's can delete organizations");
        pex.setLocalizedTitle(ls.getMessage("permission.jsp.title.orgdetail"));
        pex.setLocalizedSummary(ls.getMessage("permission.jsp.summary.general"));
        throw pex;
    }

    if (isSubmitted(dynaForm)) {
        Org bOrg = OrgFactory.getSatelliteOrg();
        if (oid.longValue() == bOrg.getId().longValue()) {
            createErrorMessage(request, "org.base.delete.error", bOrg.getName());
            retval = mapping.findForward("error");
        } else {
            deleteOrg(oid, request);
            retval = mapping.findForward("success");
        }
        retval = getStrutsDelegate().forwardParam(retval, "oid", oid.toString());
    } else {
        setupFormValues(request, dynaForm);
    }
    return retval;
}

From source file:edu.stanford.mobisocial.dungbeetle.MessagingManagerThread.java

@Override
public void run() {
    ProfileScanningObjHandler profileScanningObjHandler = new ProfileScanningObjHandler();
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
    Set<Long> notSendingObjects = new HashSet<Long>();
    if (DBG)/* ww w . j  a va2s . c om*/
        Log.i(TAG, "Running...");
    mMessenger.init();
    long max_sent = -1;
    while (!interrupted()) {
        mOco.waitForChange();
        mOco.clearChanged();
        Cursor objs = mHelper.queryUnsentObjects(max_sent);
        try {
            Log.i(TAG, "Sending " + objs.getCount() + " objects...");
            if (objs.moveToFirst())
                do {
                    Long objId = objs.getLong(objs.getColumnIndexOrThrow(DbObject._ID));
                    String jsonSrc = objs.getString(objs.getColumnIndexOrThrow(DbObject.JSON));

                    max_sent = objId.longValue();
                    JSONObject json = null;
                    if (jsonSrc != null) {
                        try {
                            json = new JSONObject(jsonSrc);
                        } catch (JSONException e) {
                            Log.e(TAG, "bad json", e);
                        }
                    } else {
                        json = new JSONObject();
                    }

                    if (json != null) {
                        /*
                         * if you update latest feed here then there is a
                         * race condition between when you put a message
                         * into your db, when you actually have a connection
                         * to send the message (which is here) when other
                         * people send you messages the processing gets all
                         * out of order, so instead we update latest
                         * immediately when you add messages into your db
                         * inside DBHelper.java addToFeed();
                         */
                        // mFeedModifiedObjHandler.handleObj(mContext,
                        // feedUri, objId);

                        // TODO: Don't be fooled! This is not truly an
                        // EncodedObj
                        // and does not yet have a hash.
                        DbObj signedObj = App.instance().getMusubi().objForId(objId);
                        if (signedObj == null) {
                            Log.e(TAG, "Error, object " + objId + " not found in database");
                            notSendingObjects.add(objId);
                            continue;
                        }
                        DbEntryHandler h = DbObjects.getObjHandler(json);
                        h.afterDbInsertion(mContext, signedObj);

                        // TODO: Constraint error thrown for now b/c local
                        // user not in contacts
                        profileScanningObjHandler.handleObj(mContext, h, signedObj);
                    }

                    OutgoingMessage m = new OutgoingMsg(objs);
                    if (m.contents().getRecipients().isEmpty()) {
                        Log.w(TAG, "No addressees for direct message " + objId);
                        notSendingObjects.add(objId);
                    } else {
                        mMessenger.sendMessage(m);
                    }
                } while (objs.moveToNext());
            if (notSendingObjects.size() > 0) {
                if (DBG)
                    Log.d(TAG, "Marking " + notSendingObjects.size() + " objects sent");
                mHelper.markObjectsAsSent(notSendingObjects);
                notSendingObjects.clear();
            }
        } catch (Exception e) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
                Log.wtf(TAG, "error running notify loop", e);
            } else {
                Log.e(TAG, "error running notify loop", e);
            }
        } finally {
            objs.close();
        }
    }
    mHelper.close();
}

From source file:net.kamhon.ieagle.function.user.dao.impl.UserMenuFrameworkDaoImpl.java

public void findUserMenuForListing(DatagridModel<UserMenu> datagridModel, Long menuId, Long menuId2,
        String menuName, String menuName2, Long parentMenuId, Long parentMenuId2, String parentMenuName,
        String parentMenuName2, String accessCode, String accessCode2, Integer treeLevel, Integer treeLevel2,
        String status, String status2, Long sortSeq2, String menuTarget2, String menuUrl2, String menuDesc2) {
    List<Object> params = new ArrayList<Object>();

    String sql = " SELECT userMenu FROM userMenu IN " + UserMenu.class
            + " LEFT JOIN userMenu.parentMenu parentMenu " + " WHERE 1=1 ";
    if (menuId != null) {
        sql += " AND CONCAT(userMenu.menuId,'') LIKE ? ";
        params.add(menuId.longValue() + "%");
    }/* w ww  .  ja va 2 s .  c o m*/
    if (menuId2 != null) {
        sql += " AND CONCAT(userMenu.menuId,'') LIKE ? ";
        params.add(menuId2.longValue() + "%");
    }

    if (StringUtils.isNotBlank(menuName)) {
        sql += " AND userMenu.menuName LIKE ? ";
        params.add(menuName + "%");
    }
    if (StringUtils.isNotBlank(menuName2)) {
        sql += " AND userMenu.menuName LIKE ? ";
        params.add(menuName2 + "%");
    }

    if (parentMenuId != null) {
        sql += " AND CONCAT(parentMenu.menuId,'') LIKE ? ";
        params.add(parentMenuId + "%");
    }
    if (parentMenuId2 != null) {
        sql += " AND CONCAT(parentMenu.menuId,'') LIKE ? ";
        params.add(parentMenuId2 + "%");
    }

    if (StringUtils.isNotBlank(parentMenuName)) {
        sql += " AND parentMenu.menuName LIKE ? ";
        params.add(parentMenuName + "%");
    }
    if (StringUtils.isNotBlank(parentMenuName2)) {
        sql += " AND parentMenu.menuName LIKE ? ";
        params.add(parentMenuName2 + "%");
    }

    if (StringUtils.isNotBlank(accessCode)) {
        sql += " AND userMenu.accessCode LIKE ? ";
        params.add(accessCode + "%");
    }
    if (StringUtils.isNotBlank(accessCode2)) {
        sql += " AND userMenu.accessCode LIKE ? ";
        params.add(accessCode2 + "%");
    }

    if (treeLevel != null) {
        sql += " AND userMenu.treeLevel=?";
        params.add(treeLevel);
    }
    if (treeLevel2 != null) {
        sql += " AND userMenu.treeLevel=?";
        params.add(treeLevel2);
    }

    if (StringUtils.isNotBlank(status)) {
        sql += " AND userMenu.status = ? ";
        params.add(status);
    }
    if (StringUtils.isNotBlank(status2)) {
        sql += " AND userMenu.status = ? ";
        params.add(status2);
    }

    if (sortSeq2 != null) {
        sql += " AND CONCAT(userMenu.sortSeq,'') LIKE ? ";
        params.add(sortSeq2.longValue() + "%");
    }

    if (StringUtils.isNotBlank(menuUrl2)) {
        sql += " AND userMenu.menuUrl LIKE ? ";
        params.add(menuUrl2 + "%");
    }
    if (StringUtils.isNotBlank(menuTarget2)) {
        sql += " AND userMenu.menuTarget LIKE ?";
        params.add(menuTarget2 + "%");
    }
    if (StringUtils.isNotBlank(menuDesc2)) {
        sql += " AND userMenu.menuDesc LIKE ?";
        params.add(menuDesc2 + "%");
    }

    findForDatagrid(datagridModel, "userMenu", sql, params.toArray());
}

From source file:org.killbill.queue.TestDBBackedQueue.java

@Test(groups = "slow")
public void testWithOneReaderOneWriter() throws InterruptedException {

    final PersistentBusConfig config = createConfig(7, 100, false, true);
    queue = new DBBackedQueue<BusEventModelDao>(clock, sqlDao, config, "oneReaderOneWriter-bus_event",
            metricRegistry, databaseTransactionNotificationApi);
    queue.initialize();/*from  w  w w . ja v  a2s . co  m*/

    Thread writer = new Thread(new WriterRunnable(0, 1000, queue));
    final AtomicLong consumed = new AtomicLong(0);
    final ReaderRunnable readerRunnable = new ReaderRunnable(0, consumed, 1000, queue);
    final Thread reader = new Thread(readerRunnable);

    writer.start();
    while (queue.isQueueOpenForWrite()) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
    }
    reader.start();

    try {
        writer.join();
        reader.join();
    } catch (InterruptedException e) {
        Assert.fail("InterruptedException ", e);
    }

    final List<BusEventModelDao> ready = sqlDao.getReadyEntries(clock.getUTCNow().toDate(), 1000, OWNER,
            "bus_events");
    assertEquals(ready.size(), 0);

    log.info("Got inflightProcessed = " + queue.getTotalInflightFetched() + "/1000, inflightWritten = "
            + queue.getTotalInflightInsert() + "/1000");
    assertEquals(queue.getTotalInsert(), 1000L);

    // Verify ordering
    long expected = 999;
    for (Long cur : readerRunnable.getSearch1()) {
        assertEquals(cur.longValue(), expected);
        expected--;
    }
}

From source file:gr.abiss.calipso.domain.User.java

/**
 * Get a list of roles the user has for this space    
 * @param spaceId the space id of which the roles must belong to
 * @return//w  w  w. j  a  v a 2  s . c  om
 */
public List<SpaceRole> getSpaceRoles(Long spaceId) {
    long spId = spaceId.longValue();
    List<SpaceRole> spaceRolesList = new ArrayList<SpaceRole>();
    for (UserSpaceRole userSpaceRole : userSpaceRoles) {
        SpaceRole spaceRole = userSpaceRole.getSpaceRole();
        if (spaceRole != null && spaceRole.getSpace() != null && spaceRole.getSpace().getId() == spId) {
            spaceRolesList.add(spaceRole);
        }
    }
    return spaceRolesList;
}

From source file:io.ucoin.ucoinj.core.client.service.bma.WotRemoteServiceImpl.java

private Certification toCertifiedByCerticication(final WotLookup.SignedSignature source) {

    Certification target = new Certification();
    // uid/* w ww  .j  a  v a2  s  .c o  m*/
    target.setUid(source.uid);

    // certifieb by
    target.setCertifiedBy(true);

    if (source.meta != null) {

        // timestamp
        Long timestamp = source.meta != null ? source.meta.timestamp : null;
        if (timestamp != null) {
            target.setTimestamp(timestamp.longValue());
        }
    }

    // Pubkey
    target.setPubkey(source.pubkey);

    // Is member
    target.setMember(source.isMember);

    // add to result list
    return target;
}