Changeset 11721 in josm for trunk/src


Ignore:
Timestamp:
2017-03-13T16:59:10+01:00 (7 years ago)
Author:
michael2402
Message:

Throw exception if clamp cannot produce any valid values.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r11692 r11721  
    15071507     * @param max maximum value
    15081508     * @return the value
     1509     * @throws IllegalArgumentException if min > max
    15091510     * @since 10805
    15101511     */
    15111512    public static double clamp(double val, double min, double max) {
    1512         if (val < min) {
     1513        if (min > max) {
     1514            throw new IllegalArgumentException(MessageFormat.format("Parameter min ({0}) cannot be greather than max ({1})", min, max));
     1515        } else if (val < min) {
    15131516            return min;
    15141517        } else if (val > max) {
     
    15251528     * @param max maximum value
    15261529     * @return the value
     1530     * @throws IllegalArgumentException if min > max
    15271531     * @since 11055
    15281532     */
    15291533    public static int clamp(int val, int min, int max) {
    1530         if (val < min) {
     1534        if (min > max) {
     1535            throw new IllegalArgumentException(MessageFormat.format("Parameter min ({0}) cannot be greather than max ({1})", min, max));
     1536        } else if (val < min) {
    15311537            return min;
    15321538        } else if (val > max) {
Note: See TracChangeset for help on using the changeset viewer.