Example usage for java.lang Long parseLong

List of usage examples for java.lang Long parseLong

Introduction

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

Prototype

public static long parseLong(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal long .

Usage

From source file:com.inkubator.hrm.web.converter.PaySalaryComponentConverter.java

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    PaySalaryComponentService paySalaryComponentService = (PaySalaryComponentService) ServiceWebUtil
            .getService("paySalaryComponentService");
    Object object = null;/*from ww  w.  j  av a  2  s . c o m*/
    try {
        object = paySalaryComponentService.getEntiyByPK(Long.parseLong(value));
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage());
    }
    return object;
}

From source file:eionet.cr.web.util.FactsheetObjectId.java

/**
 *
 * @param s//  ww w . j ava2 s  .  c  o m
 * @return
 */
public static ObjectDTO parse(String s) {

    if (StringUtils.isBlank(s)) {
        throw new IllegalArgumentException("Supplied string must not be blank");
    }

    String[] parts = StringUtils.split(s, SEPARATOR);
    if (parts.length != 4) {
        throw new IllegalArgumentException("Supplied string has wrong format");
    }

    long[] hashes = new long[4];
    for (int i = 0; i < parts.length; i++) {
        try {
            hashes[i] = Long.parseLong(parts[i]);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Supplied string has wrong format");
        }
    }

    return ObjectDTO.create(hashes[0], hashes[1], hashes[2], hashes[3]);
}

From source file:de.msg.terminfindung.gui.util.ViewUtil.java

/**
 * Liest einen Request-Parameter aus der URL, wandelt ihn in einen Long-Wert um
 * und gibt diesen Wert zurck.//  w w  w  .  ja va 2s.  c om
 **
 * @param name  der Namen des Request-Parameters
 * @param context der Spring Request Context
 */
@Deprecated
public static TFNumberHolder getRequestParameterAsLong(String name, ExternalContext context) {

    Long result = 0L;
    String paramValueStr = getRequestParameter(name, context);
    try {
        result = Long.parseLong(paramValueStr);
    } catch (NumberFormatException e) {
        LOG.warn("Request Parameter " + name + " konnte nicht in Long konvertiert werden, gebe 0L zurck",
                e.getMessage());
    }
    return new TFNumberHolder(result);
}

From source file:Main.java

private static boolean isNumberValid(String number) {
    try {// w  w  w. j  av  a 2s.  co m
        long value = Long.parseLong(number);
        if (is32bitValue(value)) {
            return true;
        }
    } catch (NumberFormatException e) {
        // do nothing
    }

    Log.d(LOG_TAG, "Invalid UID value: " + number);

    return false;
}

From source file:fr.hoteia.qalingo.core.service.impl.EngineSettingServiceImpl.java

public EngineSetting getEngineSettingById(final String id) {
    long engineSettingId = -1;
    try {//w w w  .  j ava 2 s.  c  o  m
        engineSettingId = Long.parseLong(id);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException(e);
    }
    return engineSettingDao.getEngineSettingById(engineSettingId);
}

From source file:com.liferay.mobile.android.auth.SignIn.java

public static void signIn(final Session session, final JSONObjectCallback callback, final SignInMethod method) {

    GroupService groupService = new GroupService(session);

    session.setCallback(new JSONArrayCallback() {

        @Override//  w  w w .  j a  va2  s .  c om
        public void onSuccess(JSONArray sites) {
            if (sites.length() == 0) {
                onFailure(new Exception("User doesn't belong to any site"));
            }

            try {
                JSONObject site = sites.getJSONObject(0);
                long companyId = site.getLong("companyId");

                Session userSession = new SessionImpl(session);
                userSession.setCallback(callback);

                UserService userService = new UserService(userSession);

                String username = getUsername(session);

                if (method == SignInMethod.EMAIL) {
                    userService.getUserByEmailAddress(companyId, username);
                } else if (method == SignInMethod.USER_ID) {
                    userService.getUserById(Long.parseLong(username));
                } else {
                    userService.getUserByScreenName(companyId, username);
                }
            } catch (Exception e) {
                onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception exception) {
            callback.onFailure(exception);
        }

    });

    try {
        groupService.getUserSitesGroups();
    } catch (Exception e) {
        callback.onFailure(e);
    }
}

From source file:MutableLong.java

/**   Create MutableLong object from a string.
 *
 *   @param   s   String containing an integer value.
 *//*from  www .  ja v  a2  s .co m*/

public MutableLong(String s) throws NumberFormatException {
    mutableLong = Long.parseLong(s);
}

From source file:eu.planets_project.tb.utils.ExperimentUtils.java

/**
 * /*from   w  ww .  ja v a  2  s  . c o m*/
 * @param os
 * @param expId
 * @throws IOException 
 */
public static void outputResults(OutputStream os, String expId, DATA_FORMAT format) throws IOException {
    log.info("Writing out experiment " + expId + " as " + format);

    Writer out = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
    CSVWriter writer = new CSVWriter(out);

    long id = Long.parseLong(expId);

    ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance();
    Experiment exp = edao.findExperiment(id);

    // The string array 
    String sa[] = new String[8];
    sa[0] = "Name";
    sa[1] = "Run #";
    sa[2] = "Date";
    sa[3] = "Digital Object #";
    sa[4] = "Digital Object Source";
    sa[5] = "Stage";
    sa[6] = "Property Identifier";
    sa[7] = "Property Value";
    // write the headers out:
    writer.writeNext(sa);

    // Loop through:
    int bi = 1;
    for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) {
        // log.info("Found batch... "+batch);
        int doi = 1;
        for (ExecutionRecordImpl exr : batch.getRuns()) {
            // log.info("Found Record... "+exr+" stages: "+exr.getStages());
            if (exr != null && exr.getStages() != null) {
                for (ExecutionStageRecordImpl exsr : exr.getStages()) {
                    // log.info("Found Stage... "+exsr);
                    for (MeasurementImpl m : exsr.getMeasurements()) {
                        // log.info("Looking at result for property "+m.getIdentifier());
                        sa[0] = exp.getExperimentSetup().getBasicProperties().getExperimentName();
                        sa[1] = "" + bi;
                        sa[2] = batch.getStartDate().getTime().toString();
                        sa[3] = "" + doi;
                        sa[4] = exr.getDigitalObjectSource();
                        sa[5] = exsr.getStage();
                        sa[6] = m.getIdentifier();
                        sa[7] = m.getValue();
                        // Write out CSV:
                        writer.writeNext(sa);
                    }
                }
            }
            // Increment, for the next DO.
            doi++;
            out.flush();
        }
        // Increment to the next batch:
        bi++;
    }

}

From source file:org.shredzone.cilla.web.converter.StringToGallerySection.java

@Override
public GallerySection convert(String string) {
    try {//from  ww  w.  j  av  a  2s. c  o m
        return (GallerySection) sectionDao.fetch(Long.parseLong(string));
    } catch (NumberFormatException | ClassCastException ex) {
        return null;
    }
}

From source file:com.veera.secondarysort.demo2.SsMapper.java

@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
    String[] tokens = value.toString().split(",");

    String symbol = tokens[0].trim();
    Long timestamp = Long.parseLong(tokens[1].trim());
    Double v = Double.parseDouble(tokens[2].trim());

    StockKey stockKey = new StockKey(symbol, timestamp);
    DoubleWritable stockValue = new DoubleWritable(v);

    context.write(stockKey, stockValue);
    _log.debug(stockKey.toString() + " => " + stockValue.toString());
}