780 * property. System properties are accessible through the {@link 781 * java.lang.System#getProperty(java.lang.String)} method. The 782 * string value of this property is then interpreted as an integer 783 * value using the grammar supported by {@link Integer#decode decode} and 784 * an {@code Integer} object representing this value is returned. 785 * 786 * <p>If there is no property with the specified name, if the 787 * specified name is empty or {@code null}, or if the property 788 * does not have the correct numeric format, then {@code null} is 789 * returned. 790 * 791 * <p>In other words, this method returns an {@code Integer} 792 * object equal to the value of: 793 * 794 * <blockquote> 795 * {@code getInteger(nm, null)} 796 * </blockquote> 797 * 798 * @param nm property name. 799 * @return the {@code Integer} value of the property. 800 * @see java.lang.System#getProperty(java.lang.String) 801 * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 802 */ 803 public static Integer getInteger(String nm) { 804 return getInteger(nm, null); 805 } 806 807 /** 808 * Determines the integer value of the system property with the 809 * specified name. 810 * 811 * <p>The first argument is treated as the name of a system 812 * property. System properties are accessible through the {@link 813 * java.lang.System#getProperty(java.lang.String)} method. The 814 * string value of this property is then interpreted as an integer 815 * value using the grammar supported by {@link Integer#decode decode} and 816 * an {@code Integer} object representing this value is returned. 817 * 818 * <p>The second argument is the default value. An {@code Integer} object 819 * that represents the value of the second argument is returned if there 824 * <p>In other words, this method returns an {@code Integer} object 825 * equal to the value of: 826 * 827 * <blockquote> 828 * {@code getInteger(nm, new Integer(val))} 829 * </blockquote> 830 * 831 * but in practice it may be implemented in a manner such as: 832 * 833 * <blockquote><pre> 834 * Integer result = getInteger(nm, null); 835 * return (result == null) ? new Integer(val) : result; 836 * </pre></blockquote> 837 * 838 * to avoid the unnecessary allocation of an {@code Integer} 839 * object when the default value is not needed. 840 * 841 * @param nm property name. 842 * @param val default value. 843 * @return the {@code Integer} value of the property. 844 * @see java.lang.System#getProperty(java.lang.String) 845 * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 846 */ 847 public static Integer getInteger(String nm, int val) { 848 Integer result = getInteger(nm, null); 849 return (result == null) ? Integer.valueOf(val) : result; 850 } 851 852 /** 853 * Returns the integer value of the system property with the 854 * specified name. The first argument is treated as the name of a 855 * system property. System properties are accessible through the 856 * {@link java.lang.System#getProperty(java.lang.String)} method. 857 * The string value of this property is then interpreted as an 858 * integer value, as per the {@link Integer#decode decode} method, 859 * and an {@code Integer} object representing this value is 860 * returned; in summary: 861 * 862 * <ul><li>If the property value begins with the two ASCII characters 863 * {@code 0x} or the ASCII character {@code #}, not 864 * followed by a minus sign, then the rest of it is parsed as a 865 * hexadecimal integer exactly as by the method 866 * {@link #valueOf(java.lang.String, int)} with radix 16. 867 * <li>If the property value begins with the ASCII character 868 * {@code 0} followed by another character, it is parsed as an 869 * octal integer exactly as by the method 870 * {@link #valueOf(java.lang.String, int)} with radix 8. 871 * <li>Otherwise, the property value is parsed as a decimal integer 872 * exactly as by the method {@link #valueOf(java.lang.String, int)} 873 * with radix 10. 874 * </ul> 875 * 876 * <p>The second argument is the default value. The default value is 877 * returned if there is no property of the specified name, if the 878 * property does not have the correct numeric format, or if the 879 * specified name is empty or {@code null}. 880 * 881 * @param nm property name. 882 * @param val default value. 883 * @return the {@code Integer} value of the property. 884 * @see System#getProperty(java.lang.String) 885 * @see System#getProperty(java.lang.String, java.lang.String) 886 */ 887 public static Integer getInteger(String nm, Integer val) { 888 String v = null; 889 try { 890 v = System.getProperty(nm); 891 } catch (IllegalArgumentException | NullPointerException e) { 892 } 893 if (v != null) { 894 try { 895 return Integer.decode(v); 896 } catch (NumberFormatException e) { 897 } 898 } 899 return val; 900 } 901 902 /** 903 * Decodes a {@code String} into an {@code Integer}. | 780 * property. System properties are accessible through the {@link 781 * java.lang.System#getProperty(java.lang.String)} method. The 782 * string value of this property is then interpreted as an integer 783 * value using the grammar supported by {@link Integer#decode decode} and 784 * an {@code Integer} object representing this value is returned. 785 * 786 * <p>If there is no property with the specified name, if the 787 * specified name is empty or {@code null}, or if the property 788 * does not have the correct numeric format, then {@code null} is 789 * returned. 790 * 791 * <p>In other words, this method returns an {@code Integer} 792 * object equal to the value of: 793 * 794 * <blockquote> 795 * {@code getInteger(nm, null)} 796 * </blockquote> 797 * 798 * @param nm property name. 799 * @return the {@code Integer} value of the property. 800 * @throws SecurityException for the same reasons as 801 * {@link System#getProperty(String) System.getProperty} 802 * @see java.lang.System#getProperty(java.lang.String) 803 * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 804 */ 805 public static Integer getInteger(String nm) { 806 return getInteger(nm, null); 807 } 808 809 /** 810 * Determines the integer value of the system property with the 811 * specified name. 812 * 813 * <p>The first argument is treated as the name of a system 814 * property. System properties are accessible through the {@link 815 * java.lang.System#getProperty(java.lang.String)} method. The 816 * string value of this property is then interpreted as an integer 817 * value using the grammar supported by {@link Integer#decode decode} and 818 * an {@code Integer} object representing this value is returned. 819 * 820 * <p>The second argument is the default value. An {@code Integer} object 821 * that represents the value of the second argument is returned if there 826 * <p>In other words, this method returns an {@code Integer} object 827 * equal to the value of: 828 * 829 * <blockquote> 830 * {@code getInteger(nm, new Integer(val))} 831 * </blockquote> 832 * 833 * but in practice it may be implemented in a manner such as: 834 * 835 * <blockquote><pre> 836 * Integer result = getInteger(nm, null); 837 * return (result == null) ? new Integer(val) : result; 838 * </pre></blockquote> 839 * 840 * to avoid the unnecessary allocation of an {@code Integer} 841 * object when the default value is not needed. 842 * 843 * @param nm property name. 844 * @param val default value. 845 * @return the {@code Integer} value of the property. 846 * @throws SecurityException for the same reasons as 847 * {@link System#getProperty(String) System.getProperty} 848 * @see java.lang.System#getProperty(java.lang.String) 849 * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 850 */ 851 public static Integer getInteger(String nm, int val) { 852 Integer result = getInteger(nm, null); 853 return (result == null) ? Integer.valueOf(val) : result; 854 } 855 856 /** 857 * Returns the integer value of the system property with the 858 * specified name. The first argument is treated as the name of a 859 * system property. System properties are accessible through the 860 * {@link java.lang.System#getProperty(java.lang.String)} method. 861 * The string value of this property is then interpreted as an 862 * integer value, as per the {@link Integer#decode decode} method, 863 * and an {@code Integer} object representing this value is 864 * returned; in summary: 865 * 866 * <ul><li>If the property value begins with the two ASCII characters 867 * {@code 0x} or the ASCII character {@code #}, not 868 * followed by a minus sign, then the rest of it is parsed as a 869 * hexadecimal integer exactly as by the method 870 * {@link #valueOf(java.lang.String, int)} with radix 16. 871 * <li>If the property value begins with the ASCII character 872 * {@code 0} followed by another character, it is parsed as an 873 * octal integer exactly as by the method 874 * {@link #valueOf(java.lang.String, int)} with radix 8. 875 * <li>Otherwise, the property value is parsed as a decimal integer 876 * exactly as by the method {@link #valueOf(java.lang.String, int)} 877 * with radix 10. 878 * </ul> 879 * 880 * <p>The second argument is the default value. The default value is 881 * returned if there is no property of the specified name, if the 882 * property does not have the correct numeric format, or if the 883 * specified name is empty or {@code null}. 884 * 885 * @param nm property name. 886 * @param val default value. 887 * @return the {@code Integer} value of the property. 888 * @throws SecurityException for the same reasons as 889 * {@link System#getProperty(String) System.getProperty} 890 * @see System#getProperty(java.lang.String) 891 * @see System#getProperty(java.lang.String, java.lang.String) 892 */ 893 public static Integer getInteger(String nm, Integer val) { 894 String v = null; 895 try { 896 v = System.getProperty(nm); 897 } catch (IllegalArgumentException | NullPointerException e) { 898 } 899 if (v != null) { 900 try { 901 return Integer.decode(v); 902 } catch (NumberFormatException e) { 903 } 904 } 905 return val; 906 } 907 908 /** 909 * Decodes a {@code String} into an {@code Integer}. |