Java Code Examples for java.lang.Long#parseLong()
The following examples show how to use
java.lang.Long#parseLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheUtil.java From MicroReader with MIT License | 6 votes |
/** * 判断缓存的byte数据是否到期 * * @param data * @return true:到期了 false:还没有到期 */ private static boolean isDue(byte[] data) { String[] strs = getDateInfoFromDate(data); if (strs != null && strs.length == 2) { String saveTimeStr = strs[0]; while (saveTimeStr.startsWith("0")) { saveTimeStr = saveTimeStr.substring(1, saveTimeStr.length()); } long saveTime = Long.parseLong(saveTimeStr); long deleteAfter = Long.parseLong(strs[1]); if (System.currentTimeMillis() > saveTime + deleteAfter * 1000) { return true; } } return false; }
Example 2
Source File: GameController.java From eb-java-scorekeep with Apache License 2.0 | 5 votes |
/** PUT /game/SESSION/GAME/endtime/ENDTIME **/ @RequestMapping(value="/{gameId}/endtime/{endTime}",method=RequestMethod.PUT) public void setEndTime(@PathVariable String sessionId, @PathVariable String gameId, @PathVariable String endTime) throws SessionNotFoundException, GameNotFoundException, NumberFormatException { Game game = gameFactory.getGame(sessionId, gameId); Long seconds = Long.parseLong(endTime); Date date = new Date(seconds); game.setEndTime(date); model.saveGame(game); }
Example 3
Source File: GameController.java From eb-java-scorekeep with Apache License 2.0 | 5 votes |
/** PUT /game/SESSION/GAME/starttime/STARTTIME **/ @RequestMapping(value="/{gameId}/starttime/{startTime}",method=RequestMethod.PUT) public void setStartTime(@PathVariable String sessionId, @PathVariable String gameId, @PathVariable String startTime) throws SessionNotFoundException, GameNotFoundException, NumberFormatException { Game game = gameFactory.getGame(sessionId, gameId); Long seconds = Long.parseLong(startTime); Date date = new Date(seconds); logger.info("Setting start time."); game.setStartTime(date); logger.info("Start time: " + game.getStartTime()); model.saveGame(game); }
Example 4
Source File: AbstractPreferences.java From hottub with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 5
Source File: AbstractPreferences.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 6
Source File: AbstractPreferences.java From jdk-1.7-annotated with Apache License 2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 7
Source File: AbstractPreferences.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 8
Source File: AbstractPreferences.java From jdk8u_jdk with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 9
Source File: AbstractPreferences.java From openjdk-8 with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 10
Source File: AbstractPreferences.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 11
Source File: AbstractPreferences.java From jdk1.8-source-analysis with Apache License 2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 12
Source File: AbstractPreferences.java From Java8CN with Apache License 2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 13
Source File: AbstractPreferences.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 14
Source File: AbstractPreferences.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Implements the {@code getLong} method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) get(key, * null)}. If the return value is non-null, the implementation * attempts to translate it to a {@code long} with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, {@code def} is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with {@code key} * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * {@code key} in this preference node, or {@code def} if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if {@code key} is {@code null}. * @throws IllegalArgumentException if key contains the null control * character, code point U+0000. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 15
Source File: AbstractPreferences.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 16
Source File: AbstractPreferences.java From openjdk-jdk8u with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 17
Source File: AbstractPreferences.java From JDKSourceCode1.8 with MIT License | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 18
Source File: AbstractPreferences.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 19
Source File: AbstractPreferences.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }
Example 20
Source File: AbstractPreferences.java From dragonwell8_jdk with GNU General Public License v2.0 | 3 votes |
/** * Implements the <tt>getLong</tt> method as per the specification in * {@link Preferences#getLong(String,long)}. * * <p>This implementation invokes {@link #get(String,String) <tt>get(key, * null)</tt>}. If the return value is non-null, the implementation * attempts to translate it to a <tt>long</tt> with * {@link Long#parseLong(String)}. If the attempt succeeds, the return * value is returned by this method. Otherwise, <tt>def</tt> is returned. * * @param key key whose associated value is to be returned as a long. * @param def the value to be returned in the event that this * preference node has no value associated with <tt>key</tt> * or the associated value cannot be interpreted as a long. * @return the long value represented by the string associated with * <tt>key</tt> in this preference node, or <tt>def</tt> if the * associated value does not exist or cannot be interpreted as * a long. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>. */ public long getLong(String key, long def) { long result = def; try { String value = get(key, null); if (value != null) result = Long.parseLong(value); } catch (NumberFormatException e) { // Ignoring exception causes specified default to be returned } return result; }