Java Properties Get getIntProperty(Properties props, String keyword, int defaultValue)

Here you can find the source of getIntProperty(Properties props, String keyword, int defaultValue)

Description

get Int Property

License

Open Source License

Declaration

public static int getIntProperty(Properties props, String keyword,
            int defaultValue) 

Method Source Code

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

import java.util.*;

public class Main {
    public static int getIntProperty(Properties props, String keyword,
            int defaultValue) {
        int rv = defaultValue;
        if (props != null) {
            String s = props.getProperty(keyword);
            if (s != null) {
                s = s.trim();/*from   ww  w  .  jav a 2s.c om*/
                if (!s.isEmpty()) {
                    try {
                        rv = Integer.parseInt(s);
                    } catch (NumberFormatException ex) {
                    }
                }
            }
        }
        return rv;
    }

    public static String getProperty(Properties props, String keyword) {
        String rv = null;
        if (props != null) {
            rv = props.getProperty(keyword);
        }
        if (rv != null) {
            if (rv.trim().isEmpty()) {
                rv = "";
            }
        } else {
            rv = "";
        }
        return rv;
    }

    public static int parseInt(String text, int minValue, int defaultValue) {
        int value = defaultValue;
        if (text != null) {
            try {
                value = Integer.parseInt(text);
            } catch (NumberFormatException ex) {
            }
        }
        return value >= minValue ? value : minValue;
    }
}

Related

  1. getBoolean(Properties props, String name, boolean defaultValue)
  2. getInt(Properties props, String name)
  3. getInt(Properties props, String name, int defaultValue)
  4. getIntersectionOfPropertyValues(Properties propertyFileOne, Properties propertyFileTwo)
  5. getIntInRange(Properties props, String name, int defaultValue, int min, int max)
  6. getIsB37PropertyValue(final Properties dataSourceProperties)
  7. getLocalizedProperties(String[] propertyKeys, Properties properties)
  8. getLong(Properties props, String string, long defaultV)
  9. getNestedProperties(String prefix, Properties properties)