src/share/classes/java/lang/Long.java

Print this page




 810      * property.  System properties are accessible through the {@link
 811      * java.lang.System#getProperty(java.lang.String)} method. The
 812      * string value of this property is then interpreted as a {@code
 813      * long} value using the grammar supported by {@link Long#decode decode}
 814      * and a {@code Long} object representing this value is returned.
 815      *
 816      * <p>If there is no property with the specified name, if the
 817      * specified name is empty or {@code null}, or if the property
 818      * does not have the correct numeric format, then {@code null} is
 819      * returned.
 820      *
 821      * <p>In other words, this method returns a {@code Long} object
 822      * equal to the value of:
 823      *
 824      * <blockquote>
 825      *  {@code getLong(nm, null)}
 826      * </blockquote>
 827      *
 828      * @param   nm   property name.
 829      * @return  the {@code Long} value of the property.


 830      * @see     java.lang.System#getProperty(java.lang.String)
 831      * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 832      */
 833     public static Long getLong(String nm) {
 834         return getLong(nm, null);
 835     }
 836 
 837     /**
 838      * Determines the {@code long} value of the system property
 839      * with the specified name.
 840      *
 841      * <p>The first argument is treated as the name of a system
 842      * property.  System properties are accessible through the {@link
 843      * java.lang.System#getProperty(java.lang.String)} method. The
 844      * string value of this property is then interpreted as a {@code
 845      * long} value using the grammar supported by {@link Long#decode decode}
 846      * and a {@code Long} object representing this value is returned.
 847      *
 848      * <p>The second argument is the default value. A {@code Long} object
 849      * that represents the value of the second argument is returned if there


 853      * <p>In other words, this method returns a {@code Long} object equal
 854      * to the value of:
 855      *
 856      * <blockquote>
 857      *  {@code getLong(nm, new Long(val))}
 858      * </blockquote>
 859      *
 860      * but in practice it may be implemented in a manner such as:
 861      *
 862      * <blockquote><pre>
 863      * Long result = getLong(nm, null);
 864      * return (result == null) ? new Long(val) : result;
 865      * </pre></blockquote>
 866      *
 867      * to avoid the unnecessary allocation of a {@code Long} object when
 868      * the default value is not needed.
 869      *
 870      * @param   nm    property name.
 871      * @param   val   default value.
 872      * @return  the {@code Long} value of the property.


 873      * @see     java.lang.System#getProperty(java.lang.String)
 874      * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 875      */
 876     public static Long getLong(String nm, long val) {
 877         Long result = Long.getLong(nm, null);
 878         return (result == null) ? Long.valueOf(val) : result;
 879     }
 880 
 881     /**
 882      * Returns the {@code long} value of the system property with
 883      * the specified name.  The first argument is treated as the name
 884      * of a system property.  System properties are accessible through
 885      * the {@link java.lang.System#getProperty(java.lang.String)}
 886      * method. The string value of this property is then interpreted
 887      * as a {@code long} value, as per the
 888      * {@link Long#decode decode} method, and a {@code Long} object
 889      * representing this value is returned; in summary:
 890      *
 891      * <ul>
 892      * <li>If the property value begins with the two ASCII characters


 900      * #valueOf(java.lang.String, int)} with radix 8.
 901      * <li>Otherwise the property value is parsed as a decimal
 902      * integer exactly as by the method
 903      * {@link #valueOf(java.lang.String, int)} with radix 10.
 904      * </ul>
 905      *
 906      * <p>Note that, in every case, neither {@code L}
 907      * (<code>'&#92;u004C'</code>) nor {@code l}
 908      * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 909      * of the property value as a type indicator, as would be
 910      * permitted in Java programming language source code.
 911      *
 912      * <p>The second argument is the default value. The default value is
 913      * returned if there is no property of the specified name, if the
 914      * property does not have the correct numeric format, or if the
 915      * specified name is empty or {@code null}.
 916      *
 917      * @param   nm   property name.
 918      * @param   val   default value.
 919      * @return  the {@code Long} value of the property.


 920      * @see     System#getProperty(java.lang.String)
 921      * @see     System#getProperty(java.lang.String, java.lang.String)
 922      */
 923     public static Long getLong(String nm, Long val) {
 924         String v = null;
 925         try {
 926             v = System.getProperty(nm);
 927         } catch (IllegalArgumentException | NullPointerException e) {
 928         }
 929         if (v != null) {
 930             try {
 931                 return Long.decode(v);
 932             } catch (NumberFormatException e) {
 933             }
 934         }
 935         return val;
 936     }
 937 
 938     /**
 939      * Compares two {@code Long} objects numerically.




 810      * property.  System properties are accessible through the {@link
 811      * java.lang.System#getProperty(java.lang.String)} method. The
 812      * string value of this property is then interpreted as a {@code
 813      * long} value using the grammar supported by {@link Long#decode decode}
 814      * and a {@code Long} object representing this value is returned.
 815      *
 816      * <p>If there is no property with the specified name, if the
 817      * specified name is empty or {@code null}, or if the property
 818      * does not have the correct numeric format, then {@code null} is
 819      * returned.
 820      *
 821      * <p>In other words, this method returns a {@code Long} object
 822      * equal to the value of:
 823      *
 824      * <blockquote>
 825      *  {@code getLong(nm, null)}
 826      * </blockquote>
 827      *
 828      * @param   nm   property name.
 829      * @return  the {@code Long} value of the property.
 830      * @throws  SecurityException for the same reasons as
 831      *          {@link System#getProperty(String) System.getProperty}
 832      * @see     java.lang.System#getProperty(java.lang.String)
 833      * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 834      */
 835     public static Long getLong(String nm) {
 836         return getLong(nm, null);
 837     }
 838 
 839     /**
 840      * Determines the {@code long} value of the system property
 841      * with the specified name.
 842      *
 843      * <p>The first argument is treated as the name of a system
 844      * property.  System properties are accessible through the {@link
 845      * java.lang.System#getProperty(java.lang.String)} method. The
 846      * string value of this property is then interpreted as a {@code
 847      * long} value using the grammar supported by {@link Long#decode decode}
 848      * and a {@code Long} object representing this value is returned.
 849      *
 850      * <p>The second argument is the default value. A {@code Long} object
 851      * that represents the value of the second argument is returned if there


 855      * <p>In other words, this method returns a {@code Long} object equal
 856      * to the value of:
 857      *
 858      * <blockquote>
 859      *  {@code getLong(nm, new Long(val))}
 860      * </blockquote>
 861      *
 862      * but in practice it may be implemented in a manner such as:
 863      *
 864      * <blockquote><pre>
 865      * Long result = getLong(nm, null);
 866      * return (result == null) ? new Long(val) : result;
 867      * </pre></blockquote>
 868      *
 869      * to avoid the unnecessary allocation of a {@code Long} object when
 870      * the default value is not needed.
 871      *
 872      * @param   nm    property name.
 873      * @param   val   default value.
 874      * @return  the {@code Long} value of the property.
 875      * @throws  SecurityException for the same reasons as
 876      *          {@link System#getProperty(String) System.getProperty}
 877      * @see     java.lang.System#getProperty(java.lang.String)
 878      * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
 879      */
 880     public static Long getLong(String nm, long val) {
 881         Long result = Long.getLong(nm, null);
 882         return (result == null) ? Long.valueOf(val) : result;
 883     }
 884 
 885     /**
 886      * Returns the {@code long} value of the system property with
 887      * the specified name.  The first argument is treated as the name
 888      * of a system property.  System properties are accessible through
 889      * the {@link java.lang.System#getProperty(java.lang.String)}
 890      * method. The string value of this property is then interpreted
 891      * as a {@code long} value, as per the
 892      * {@link Long#decode decode} method, and a {@code Long} object
 893      * representing this value is returned; in summary:
 894      *
 895      * <ul>
 896      * <li>If the property value begins with the two ASCII characters


 904      * #valueOf(java.lang.String, int)} with radix 8.
 905      * <li>Otherwise the property value is parsed as a decimal
 906      * integer exactly as by the method
 907      * {@link #valueOf(java.lang.String, int)} with radix 10.
 908      * </ul>
 909      *
 910      * <p>Note that, in every case, neither {@code L}
 911      * (<code>'&#92;u004C'</code>) nor {@code l}
 912      * (<code>'&#92;u006C'</code>) is permitted to appear at the end
 913      * of the property value as a type indicator, as would be
 914      * permitted in Java programming language source code.
 915      *
 916      * <p>The second argument is the default value. The default value is
 917      * returned if there is no property of the specified name, if the
 918      * property does not have the correct numeric format, or if the
 919      * specified name is empty or {@code null}.
 920      *
 921      * @param   nm   property name.
 922      * @param   val   default value.
 923      * @return  the {@code Long} value of the property.
 924      * @throws  SecurityException for the same reasons as
 925      *          {@link System#getProperty(String) System.getProperty}
 926      * @see     System#getProperty(java.lang.String)
 927      * @see     System#getProperty(java.lang.String, java.lang.String)
 928      */
 929     public static Long getLong(String nm, Long val) {
 930         String v = null;
 931         try {
 932             v = System.getProperty(nm);
 933         } catch (IllegalArgumentException | NullPointerException e) {
 934         }
 935         if (v != null) {
 936             try {
 937                 return Long.decode(v);
 938             } catch (NumberFormatException e) {
 939             }
 940         }
 941         return val;
 942     }
 943 
 944     /**
 945      * Compares two {@code Long} objects numerically.