804 |
804 |
805 /** |
805 /** |
806 * Determines the {@code long} value of the system property |
806 * Determines the {@code long} value of the system property |
807 * with the specified name. |
807 * with the specified name. |
808 * |
808 * |
809 * <p>The first argument is treated as the name of a system property. |
809 * <p>The first argument is treated as the name of a system |
810 * System properties are accessible through the {@link |
810 * property. System properties are accessible through the {@link |
811 * java.lang.System#getProperty(java.lang.String)} method. The |
811 * java.lang.System#getProperty(java.lang.String)} method. The |
812 * string value of this property is then interpreted as a |
812 * string value of this property is then interpreted as a {@code |
813 * {@code long} value and a {@code Long} object |
813 * long} value using the grammar supported by {@link Long#decode decode} |
814 * representing this value is returned. Details of possible |
814 * and a {@code Long} object representing this value is returned. |
815 * numeric formats can be found with the definition of |
|
816 * {@code getProperty}. |
|
817 * |
815 * |
818 * <p>If there is no property with the specified name, if the |
816 * <p>If there is no property with the specified name, if the |
819 * specified name is empty or {@code null}, or if the |
817 * specified name is empty or {@code null}, or if the property |
820 * property does not have the correct numeric format, then |
818 * does not have the correct numeric format, then {@code null} is |
821 * {@code null} is returned. |
819 * returned. |
822 * |
820 * |
823 * <p>In other words, this method returns a {@code Long} object equal to |
821 * <p>In other words, this method returns a {@code Long} object |
824 * the value of: |
822 * equal to the value of: |
825 * |
823 * |
826 * <blockquote> |
824 * <blockquote> |
827 * {@code getLong(nm, null)} |
825 * {@code getLong(nm, null)} |
828 * </blockquote> |
826 * </blockquote> |
829 * |
827 * |
838 |
836 |
839 /** |
837 /** |
840 * Determines the {@code long} value of the system property |
838 * Determines the {@code long} value of the system property |
841 * with the specified name. |
839 * with the specified name. |
842 * |
840 * |
843 * <p>The first argument is treated as the name of a system property. |
841 * <p>The first argument is treated as the name of a system |
844 * System properties are accessible through the {@link |
842 * property. System properties are accessible through the {@link |
845 * java.lang.System#getProperty(java.lang.String)} method. The |
843 * java.lang.System#getProperty(java.lang.String)} method. The |
846 * string value of this property is then interpreted as a |
844 * string value of this property is then interpreted as a {@code |
847 * {@code long} value and a {@code Long} object |
845 * long} value using the grammar supported by {@link Long#decode decode} |
848 * representing this value is returned. Details of possible |
846 * and a {@code Long} object representing this value is returned. |
849 * numeric formats can be found with the definition of |
|
850 * {@code getProperty}. |
|
851 * |
847 * |
852 * <p>The second argument is the default value. A {@code Long} object |
848 * <p>The second argument is the default value. A {@code Long} object |
853 * that represents the value of the second argument is returned if there |
849 * that represents the value of the second argument is returned if there |
854 * is no property of the specified name, if the property does not have |
850 * is no property of the specified name, if the property does not have |
855 * the correct numeric format, or if the specified name is empty or null. |
851 * the correct numeric format, or if the specified name is empty or null. |
887 * the specified name. The first argument is treated as the name |
883 * the specified name. The first argument is treated as the name |
888 * of a system property. System properties are accessible through |
884 * of a system property. System properties are accessible through |
889 * the {@link java.lang.System#getProperty(java.lang.String)} |
885 * the {@link java.lang.System#getProperty(java.lang.String)} |
890 * method. The string value of this property is then interpreted |
886 * method. The string value of this property is then interpreted |
891 * as a {@code long} value, as per the |
887 * as a {@code long} value, as per the |
892 * {@code Long.decode} method, and a {@code Long} object |
888 * {@link Long#decode decode} method, and a {@code Long} object |
893 * representing this value is returned. |
889 * representing this value is returned; in summary: |
894 * |
890 * |
895 * <ul> |
891 * <ul> |
896 * <li>If the property value begins with the two ASCII characters |
892 * <li>If the property value begins with the two ASCII characters |
897 * {@code 0x} or the ASCII character {@code #}, not followed by |
893 * {@code 0x} or the ASCII character {@code #}, not followed by |
898 * a minus sign, then the rest of it is parsed as a hexadecimal integer |
894 * a minus sign, then the rest of it is parsed as a hexadecimal integer |
919 * specified name is empty or {@code null}. |
915 * specified name is empty or {@code null}. |
920 * |
916 * |
921 * @param nm property name. |
917 * @param nm property name. |
922 * @param val default value. |
918 * @param val default value. |
923 * @return the {@code Long} value of the property. |
919 * @return the {@code Long} value of the property. |
924 * @see java.lang.System#getProperty(java.lang.String) |
920 * @see System#getProperty(java.lang.String) |
925 * @see java.lang.System#getProperty(java.lang.String, java.lang.String) |
921 * @see System#getProperty(java.lang.String, java.lang.String) |
926 * @see java.lang.Long#decode |
|
927 */ |
922 */ |
928 public static Long getLong(String nm, Long val) { |
923 public static Long getLong(String nm, Long val) { |
929 String v = null; |
924 String v = null; |
930 try { |
925 try { |
931 v = System.getProperty(nm); |
926 v = System.getProperty(nm); |
932 } catch (IllegalArgumentException e) { |
927 } catch (IllegalArgumentException | NullPointerException e) { |
933 } catch (NullPointerException e) { |
|
934 } |
928 } |
935 if (v != null) { |
929 if (v != null) { |
936 try { |
930 try { |
937 return Long.decode(v); |
931 return Long.decode(v); |
938 } catch (NumberFormatException e) { |
932 } catch (NumberFormatException e) { |