Java Code Examples for java.lang.Double#parseDouble()

The following examples show how to use java.lang.Double#parseDouble() . 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: TaskQueueServlet.java    From appengine-java-vm-runtime with Apache License 2.0 6 votes vote down vote up
private void leaseAndDeleteTasks(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  int numTasks = Integer.parseInt(req.getParameter("numTasks"));
  Double lease = Double.parseDouble(req.getParameter("lease"));
  String queue = req.getParameter("queue");
  Queue q = QueueFactory.getQueue(queue);
  Boolean doDelete = Boolean.parseBoolean(req.getParameter("doDelete"));

  List<TaskHandle> tasks = q.leaseTasks(lease.intValue() * 1000, TimeUnit.MILLISECONDS, numTasks);

  for (TaskHandle task : tasks) {
    if (doDelete) {
      q.deleteTask(task.getName());
    }
  }
  resp.getWriter().print(queue + "," + tasks.size());
}
 
Example 2
Source File: MaxFloatingPointTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testDoubleStringParsing() {
  Double.parseDouble("9223372036854775804");
  Double.parseDouble("9223372036854775805");
  Double.parseDouble("9223372036854775806");
  Double.parseDouble("9223372036854775807");
  assertEquals(Long.MAX_VALUE, (long) Double.parseDouble(MAX_LONG_AS_STRING));
}
 
Example 3
Source File: ReadDocument.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public static AarhusTrafficObservation getStreamData(String dataFile) throws NumberFormatException, IOException {
	CsvReader streamData = new CsvReader(String.valueOf(dataFile));
	streamData.readHeaders();
	// Reads csv document for traffic metadata
	try {
		CsvReader metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
		metaData.readHeaders();
		AarhusTrafficObservation data = new AarhusTrafficObservation();
		while (streamData.readRecord()) {

			while (metaData.readRecord()) {
				if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
					data = new AarhusTrafficObservation(Double.parseDouble(streamData.get("REPORT_ID")),
							Double.parseDouble(streamData.get("avgSpeed")), Double.parseDouble(streamData
									.get("vehicleCount")), Double.parseDouble(streamData.get("avgMeasuredTime")),
							0, 0, metaData.get("POINT_1_STREET"), metaData.get("POINT_1_CITY"),
							Double.parseDouble(metaData.get("POINT_1_LAT")), Double.parseDouble(metaData
									.get("POINT_1_LNG")), metaData.get("POINT_2_STREET"),
							metaData.get("POINT_2_CITY"), Double.parseDouble(metaData.get("POINT_2_LAT")),
							Double.parseDouble(metaData.get("POINT_2_LNG")), metaData.get("POINT_1_COUNTRY"),
							metaData.get("POINT_2_COUNTRY"), metaData.get("TIMESTAMP"));
					Double distance = Double.parseDouble(metaData.get("DISTANCE_IN_METERS"));
					data.setEstimatedTime(distance / data.getAverageSpeed());
					data.setCongestionLevel(data.getVehicle_count() / distance);
				}
			}

		}
		streamData.close();
		metaData.close();
		return data;
	} catch (Exception e) {

		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: AbstractPreferences.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the {@code getDouble} method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an {@code double} with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(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 vote down vote up
/**
 * Implements the <tt>getDouble</tt> method as per the specification in
 * {@link Preferences#getDouble(String,double)}.
 *
 * <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 an <tt>double</tt> with
 * {@link Double#parseDouble(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 double.
 * @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 double.
 * @return the double 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 double.
 * @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 double getDouble(String key, double def) {
    double result = def;
    try {
        String value = get(key, null);
        if (value != null)
            result = Double.parseDouble(value);
    } catch (NumberFormatException e) {
        // Ignoring exception causes specified default to be returned
    }

    return result;
}