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:jp.primecloud.auto.tool.management.main.IaasGatewayMain.java

public static void importExecute(CommandLine commandLine) {
    Long userNo = Long.parseLong(commandLine.getOptionValue("userno"));
    Long platformNo = Long.parseLong(commandLine.getOptionValue("platformno"));
    String platformKind = commandLine.getOptionValue("platformkind");
    String keyName = commandLine.getOptionValue("keyname");
    String publicKey = commandLine.getOptionValue("publickey");

    try {//from w  w  w  .ja  va  2  s  .  c  o m
        log.info("IaasGatewayScriptFactory");
        String platformSql = "SELECT * FROM PLATFORM WHERE PLATFORM_NO=" + platformNo;
        List<Platform> platforms = SQLMain.selectExecuteWithResult(platformSql, Platform.class);
        Platform platform = platforms.get(0);

        IaasGatewayScriptService scriptService = IaasGatewayScriptFactory.createIaasGatewayScriptService(userNo,
                platformNo, platform.getPlatformName());
        if ("aws".equals(platformKind)) {
            String platformAwsSql = "SELECT * FROM PLATFORM_AWS WHERE PLATFORM_NO=" + platformNo;
            List<PlatformAws> platformAwses = SQLMain.selectExecuteWithResult(platformAwsSql,
                    PlatformAws.class);
            PlatformAws aws = platformAwses.get(0);
            if (BooleanUtils.isTrue(aws.getVpc()) && !scriptService.hasSubnets(aws.getVpcId())) {
                // AWS?VPC??
                // Subnet???VPC??????
                return;
            }
        }
        scriptService.importKeyPair(keyName, publicKey);
    } catch (AutoException e) {
        log.error("????????keyName:" + keyName
                + " platformNo:" + platformNo, e);
        System.out.println("IMPORT_ERROR");
    } catch (Exception e) {
        log.error("????????keyName:" + keyName
                + " platformNo:" + platformNo, e);
        System.out.println("????????");
    } finally {
    }
}

From source file:Main.java

public static void IcsMakeNewCalendarEntry(String title, String description, String location, long startTime,
        long endTime, int allDay, int hasAlarm, int calendarId, int selectedReminderValue) {

    ContentResolver cr = activityObj.getContentResolver();
    ContentValues values = new ContentValues();
    values.put(Events.DTSTART, startTime);
    values.put(Events.DTEND, endTime);/*from w w  w. j  a  v  a  2s. co  m*/
    values.put(Events.TITLE, title);
    values.put(Events.DESCRIPTION, description);
    values.put(Events.CALENDAR_ID, calendarId);

    if (allDay == 1) {
        values.put(Events.ALL_DAY, true);
    }

    if (hasAlarm == 1) {
        values.put(Events.HAS_ALARM, true);
    }

    //Get current timezone
    values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
    Log.i(DEBUG_TAG, "Timezone retrieved=>" + TimeZone.getDefault().getID());
    Uri uri = cr.insert(Events.CONTENT_URI, values);
    Log.i(DEBUG_TAG, "Uri returned=>" + uri.toString());
    // get the event ID that is the last element in the Uri
    long eventID = Long.parseLong(uri.getLastPathSegment());

    if (hasAlarm == 1) {
        ContentValues reminders = new ContentValues();
        reminders.put(Reminders.EVENT_ID, eventID);
        reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT);
        reminders.put(Reminders.MINUTES, selectedReminderValue);

        Uri uri2 = cr.insert(Reminders.CONTENT_URI, reminders);
    }

}

From source file:Main.java

public static long[] toLongArray(String[] strings, char c) {
    long[] array = new long[strings.length];

    for (int i = 0; i < strings.length; i++) {
        String string = strings[i].trim();
        if (string.charAt(0) == c && string.charAt(string.length() - 1) == c) {
            string = string.substring(1, string.length() - 1);
        }//  www . j av a 2  s.  c  o m
        array[i] = Long.parseLong(string);
    }

    return array;
}

From source file:com.nokia.example.lwuit.rlinks.model.LinkThing.java

/**
 * Create a LinkThing from a JSON data String.
 *
 * @param obj JSONObject containing data for the Link
 * @return A LinkThing object//from ww w  .  jav  a2s  .  c om
 * @throws JSONException If the given JSONObject can't be parsed
 */
public static LinkThing fromJson(JSONObject obj) throws JSONException {
    LinkThing thing = new LinkThing();
    thing.setAuthor(obj.getString("author"));

    try {
        // "1329913184.0" -> "13299131840000"
        String dateStr = obj.getString("created_utc").substring(0, 9) + "0000";
        thing.setCreated(new Date(Long.parseLong(dateStr)));
    } catch (Exception e) {
        System.out.println("Couldn't set date: " + e.getMessage());
    }
    thing.setDomain(obj.getString("domain"));
    thing.setId(obj.getString("id"));
    thing.setName(obj.getString("name"));
    thing.setNumComments(obj.getInt("num_comments"));
    thing.setPermalink(obj.getString("permalink"));
    thing.setSubreddit(obj.getString("subreddit"));
    thing.setScore(obj.getInt("score"));
    thing.setThumbnail(obj.getString("thumbnail"));
    thing.setTitle(HtmlEntityDecoder.decode(obj.getString("title")));
    thing.setUrl(obj.getString("url"));

    // 'Likes' can be true, false or null; map that to 1, -1, and 0
    thing.setVote(obj.isNull("likes") ? 0 : obj.getBoolean("likes") ? 1 : -1);

    return thing;
}

From source file:com.fatsecret.platform.utils.FoodUtility.java

/**
 * Returns detailed information about the food
 * //from   w  w w.ja va  2 s .  co  m
 * @param json         json object representing of the food
 * @return            detailed information about the food
 */
public static Food parseFoodFromJSONObject(JSONObject json) {
    String name = json.getString("food_name");
    String url = json.getString("food_url");
    String type = json.getString("food_type");
    Long id = Long.parseLong(json.getString("food_id"));
    String brandName = "";

    try {
        brandName = json.getString("brand_name");
    } catch (Exception ignore) {
    }

    JSONObject servingsObj = json.getJSONObject("servings");

    JSONArray array = null;
    List<Serving> servings = new ArrayList<Serving>();

    try {
        array = servingsObj.getJSONArray("serving");
        servings = ServingUtility.parseServingsFromJSONArray(array);
    } catch (Exception ignore) {
        System.out.println("Servings not found");
        array = null;
    }

    if (array == null) {
        try {
            JSONObject servingObj = servingsObj.getJSONObject("serving");
            Serving serving = ServingUtility.parseServingFromJSONObject(servingObj);
            servings.add(serving);
        } catch (Exception ignore) {
            System.out.println("Serving not found");
        }
    }

    Food food = new Food();

    food.setName(name);
    food.setUrl(url);
    food.setType(type);
    food.setId(id);
    food.setBrandName(brandName);
    food.setServings(servings);

    return food;
}

From source file:jp.primecloud.auto.tool.management.pccapi.PccApiGenerateService.java

public static void genarate(CommandLine commandLine) throws AutoException {
    Long userNo = Long.parseLong(commandLine.getOptionValue("userno"));
    String generateType = commandLine.getOptionValue("generatetype");

    try {/*from w  ww .j av a 2 s  .c o m*/
        String userSql = "SELECT * FROM USER WHERE USER_NO =" + userNo;
        List<User> users = SQLMain.selectExecuteWithResult(userSql, User.class);
        User user = users.get(0);

        if (generateType != null && generateType.equals("accessId")) {
            String apiAccessId = "";
            while (true) {
                apiAccessId = generateAccessId();
                String apiSql = "SELECT * FROM API_CERTIFICATE WHERE API_ACCESS_ID ='" + apiAccessId + "'";
                List<ApiCertificate> apiCertificates = SQLMain.selectExecuteWithResult(apiSql,
                        ApiCertificate.class);
                if (apiCertificates.isEmpty()) {
                    break;
                }
            }
            log.info(user.getUsername() + " ? accessId ?????");
            System.out.println(apiAccessId);
        } else if (generateType != null && generateType.equals("secretKey")) {
            String apiSecretKey = "";
            while (true) {
                apiSecretKey = generateSecretKey();
                String apiSql = "SELECT * FROM API_CERTIFICATE WHERE API_SECRET_KEY ='" + apiSecretKey + "'";
                List<ApiCertificate> apiCertificates = SQLMain.selectExecuteWithResult(apiSql,
                        ApiCertificate.class);
                if (apiCertificates.isEmpty()) {
                    break;
                }
            }
            log.info(user.getUsername() + " ? secretKey ?????");
            System.out.println(apiSecretKey);
        } else {
            log.error("generateType ?????");
            System.out.println("GENERATE_ERROR");
        }
    } catch (Exception e) {
        log.error("PCC-API????????userNo:" + userNo
                + " generateType:" + generateType, e);
        System.out.println("GENERATE_ERROR");
    }
}

From source file:Main.java

/**
 * Get a long value.  Try the runtime attributes first and then back off to
 * the document element.  Throw a RuntimeException if the attribute is not
 * found or if the value is not parseable as a long.
 *
 * @param attrName attribute name to find
 * @param runtimeAttributes runtime attributes
 * @param docElement correct element that should have specified attribute
 * @return specified long value/*from   w ww .ja v  a2s. co  m*/
 */
public static long getLong(String attrName, Map<String, String> runtimeAttributes, Node docElement) {
    String stringValue = getStringValue(attrName, runtimeAttributes, docElement);
    if (stringValue != null) {
        try {
            return Long.parseLong(stringValue);
        } catch (NumberFormatException e) {
            //swallow
        }
    }
    throw new RuntimeException(
            "Need to specify a \"long\" value in -- " + attrName + " -- in commandline or in config file!");
}

From source file:com.ignorelist.kassandra.steam.scraper.LibraryScanner.java

public static Set<Long> findGames(Path path) throws IOException {
    Set<Long> gameIds = new HashSet<>();
    DirectoryStream<Path> directoryStream = null;
    try {/*  w  w w  . jav a 2 s.  co m*/
        directoryStream = Files.newDirectoryStream(path, new DirectoryStream.Filter<Path>() {

            @Override
            public boolean accept(Path entry) throws IOException {
                return Files.isRegularFile(entry);
            }
        });
        for (Path f : directoryStream) {
            final String fileName = f.getFileName().toString();
            Matcher matcher = PATTERN.matcher(fileName);
            if (matcher.matches()) {
                gameIds.add(Long.parseLong(matcher.group(1)));
            }
        }
        return gameIds;
    } finally {
        IOUtils.closeQuietly(directoryStream);
    }
}

From source file:com.qwazr.search.index.BackupStatus.java

final static BackupStatus newBackupStatus(File backupDir) {
    if (backupDir == null)
        return null;
    try {//from   w w w .j a  v  a  2 s. c o  m
        long generation = Long.parseLong(backupDir.getName());
        File[] files = backupDir.listFiles((FileFilter) FileFileFilter.FILE);
        long bytes_size = 0;
        if (files == null)
            return null;
        for (File file : files)
            bytes_size += file.length();
        return new BackupStatus(generation, backupDir.lastModified(), bytes_size, files.length);
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:com.canoo.webtest.util.ConversionUtil.java

/**
 * Convert a string value to a long. If the value is null, return the specified default value.
 *
 * @return parsed value. If value is null return default value.
 * @throws NumberFormatException/*  www.  ja  v  a2  s  .co m*/
 */
public static long convertToLong(String value, long defaultValue) {
    if (value != null) {
        return Long.parseLong(value);
    }
    return defaultValue;
}