Java Properties Get getInt(Properties props, String name)

Here you can find the source of getInt(Properties props, String name)

Description

get Int

License

Open Source License

Declaration

public static int getInt(Properties props, String name) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static int getInt(Properties props, String name) {
        if (props.containsKey(name)) {
            return getInt(props, name, -1);
        }//from  w  w  w . j  a v  a2 s .co  m
        throw new IllegalArgumentException("Missing required property '" + name + "'");
    }

    public static int getInt(Properties props, String name, int defaultValue) {
        return getIntInRange(props, name, defaultValue, Integer.MIN_VALUE, Integer.MAX_VALUE);
    }

    public static int getIntInRange(Properties props, String name, int defaultValue, int min, int max) {
        int v = defaultValue;
        if (props.containsKey(name)) {
            v = Integer.valueOf(props.getProperty(name));
        }
        if (v >= min && v <= max) {
            return v;
        }
        throw new IllegalArgumentException(name + " has value " + v + " which is not in the range");
    }
}

Related

  1. clearPrefixedSystemProperties(String prefix, Map targetPropertyMap)
  2. copyProperties(Hashtable src, Hashtable target)
  3. getBoolean(Properties props, String key)
  4. getBoolean(Properties props, String name, boolean defaultValue)
  5. getInt(Properties props, String name, int defaultValue)
  6. getIntersectionOfPropertyValues(Properties propertyFileOne, Properties propertyFileTwo)
  7. getIntInRange(Properties props, String name, int defaultValue, int min, int max)
  8. getIntProperty(Properties props, String keyword, int defaultValue)