📄 long.java
字号:
* * @serial */ private long value; /** * Constructs a newly allocated <code>Long</code> object that * represents the specified <code>long</code> argument. * * @param value the value to be represented by the * <code>Long</code> object. */ public Long(long value) { this.value = value; } /** * Constructs a newly allocated <code>Long</code> object that * represents the <code>long</code> value indicated by the * <code>String</code> parameter. The string is converted to a * <code>long</code> value in exactly the manner used by the * <code>parseLong</code> method for radix 10. * * @param s the <code>String</code> to be converted to a * <code>Long</code>. * @exception NumberFormatException if the <code>String</code> does not * contain a parsable <code>long</code>. * @see java.lang.Long#parseLong(java.lang.String, int) */ public Long(String s) throws NumberFormatException { this.value = parseLong(s, 10); } /** * Returns the value of this <code>Long</code> as a * <code>byte</code>. */ public byte byteValue() { return (byte)value; } /** * Returns the value of this <code>Long</code> as a * <code>short</code>. */ public short shortValue() { return (short)value; } /** * Returns the value of this <code>Long</code> as an * <code>int</code>. */ public int intValue() { return (int)value; } /** * Returns the value of this <code>Long</code> as a * <code>long</code> value. */ public long longValue() { return (long)value; } /** * Returns the value of this <code>Long</code> as a * <code>float</code>. */ public float floatValue() { return (float)value; } /** * Returns the value of this <code>Long</code> as a * <code>double</code>. */ public double doubleValue() { return (double)value; } /** * Returns a <code>String</code> object representing this * <code>Long</code>'s value. The value is converted to signed * decimal representation and returned as a string, exactly as if * the <code>long</code> value were given as an argument to the * {@link java.lang.Long#toString(long)} method. * * @return a string representation of the value of this object in * base 10. */ public String toString() { return String.valueOf(value); } /** * Returns a hash code for this <code>Long</code>. The result is * the exclusive OR of the two halves of the primitive * <code>long</code> value held by this <code>Long</code> * object. That is, the hashcode is the value of the expression: * <blockquote><pre> * (int)(this.longValue()^(this.longValue()>>>32)) * </pre></blockquote> * * @return a hash code value for this object. */ public int hashCode() { return (int)(value ^ (value >>> 32)); } /** * Compares this object to the specified object. The result is * <code>true</code> if and only if the argument is not * <code>null</code> and is a <code>Long</code> object that * contains the same <code>long</code> value as this object. * * @param obj the object to compare with. * @return <code>true</code> if the objects are the same; * <code>false</code> otherwise. */ public boolean equals(Object obj) { if (obj instanceof Long) { return value == ((Long)obj).longValue(); } return false; } /** * Determines the <code>long</code> value of the system property * with the specified name. * <p> * The first argument is treated as the name of a system property. * System properties are accessible through the {@link * java.lang.System#getProperty(java.lang.String)} method. The * string value of this property is then interpreted as a * <code>long</code> value and a <code>Long</code> object * representing this value is returned. Details of possible * numeric formats can be found with the definition of * <code>getProperty</code>. * <p> * If there is no property with the specified name, if the * specified name is empty or <code>null</code>, or if the * property does not have the correct numeric format, then * <code>null</code> is returned. * <p> * In other words, this method returns a <code>Long</code> object equal to * the value of: * <blockquote><code> * getLong(nm, null) * </code></blockquote> * * @param nm property name. * @return the <code>Long</code> value of the property. * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ public static Long getLong(String nm) { return getLong(nm, null); } /** * Determines the <code>long</code> value of the system property * with the specified name. * <p> * The first argument is treated as the name of a system property. * System properties are accessible through the {@link * java.lang.System#getProperty(java.lang.String)} method. The * string value of this property is then interpreted as a * <code>long</code> value and a <code>Long</code> object * representing this value is returned. Details of possible * numeric formats can be found with the definition of * <code>getProperty</code>. * <p> * The second argument is the default value. A <code>Long</code> object * that represents the value of the second argument is returned if there * is no property of the specified name, if the property does not have * the correct numeric format, or if the specified name is empty or null. * <p> * In other words, this method returns a <code>Long</code> object equal * to the value of: * <blockquote><code> * getLong(nm, new Long(val)) * </code></blockquote> * but in practice it may be implemented in a manner such as: * <blockquote><pre> * Long result = getLong(nm, null); * return (result == null) ? new Long(val) : result; * </pre></blockquote> * to avoid the unnecessary allocation of a <code>Long</code> object when * the default value is not needed. * * @param nm property name. * @param val default value. * @return the <code>Long</code> value of the property. * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) */ public static Long getLong(String nm, long val) { Long result = Long.getLong(nm, null); return (result == null) ? new Long(val) : result; } /** * Returns the <code>long</code> value of the system property with * the specified name. The first argument is treated as the name * of a system property. System properties are accessible through * the {@link java.lang.System#getProperty(java.lang.String)} * method. The string value of this property is then interpreted * as a <code>long</code> value, as per the * <code>Long.decode</code> method, and a <code>Long</code> object * representing this value is returned. * <p><ul> * <li>If the property value begins with the two ASCII characters * <code>0x</code> or the ASCII character <code>#</code>, not followed by * a minus sign, then the rest of it is parsed as a hexadecimal integer * exactly as for the method {@link #valueOf(java.lang.String, int)} * with radix 16. * <li>If the property value begins with the ASCII character * <code>0</code> followed by another character, it is parsed as * an octal integer exactly as by the method {@link * #valueOf(java.lang.String, int)} with radix 8. * <li>Otherwise the property value is parsed as a decimal * integer exactly as by the method * {@link #valueOf(java.lang.String, int)} with radix 10. * </ul> * <p> * Note that, in every case, neither <code>L</code> * (<code>'\u004C'</code>) nor <code>l</code> * (<code>'\u006C'</code>) is permitted to appear at the end * of the property value as a type indicator, as would be * permitted in Java programming language source code. * <p> * The second argument is the default value. The default value is * returned if there is no property of the specified name, if the * property does not have the correct numeric format, or if the * specified name is empty or <code>null</code>. * * @param nm property name. * @param val default value. * @return the <code>Long</code> value of the property. * @see java.lang.System#getProperty(java.lang.String) * @see java.lang.System#getProperty(java.lang.String, java.lang.String) * @see java.lang.Long#decode */ public static Long getLong(String nm, Long val) { String v = null; try { v = System.getProperty(nm); } catch (IllegalArgumentException e) { } catch (NullPointerException e) { } if (v != null) { try { return Long.decode(v); } catch (NumberFormatException e) { } } return val; } /** * Compares two <code>Long</code> objects numerically. * * @param anotherLong the <code>Long</code> to be compared. * @return the value <code>0</code> if this <code>Long</code> is * equal to the argument <code>Long</code>; a value less than * <code>0</code> if this <code>Long</code> is numerically less * than the argument <code>Long</code>; and a value greater * than <code>0</code> if this <code>Long</code> is numerically * greater than the argument <code>Long</code> (signed * comparison). * @since 1.2 */ public int compareTo(Long anotherLong) { long thisVal = this.value; long anotherVal = anotherLong.value; return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1)); } /** * Compares this <code>Long</code> object to another object. If * the object is a <code>Long</code>, this function behaves like * <code>compareTo(Long)</code>. Otherwise, it throws a * <code>ClassCastException</code> (as <code>Long</code> objects * are comparable only to other <code>Long</code> objects). * * @param o the <code>Object</code> to be compared. * @return the value <code>0</code> if the argument is a * <code>Long</code> numerically equal to this * <code>Long</code>; a value less than <code>0</code> * if the argument is a <code>Long</code> numerically * greater than this <code>Long</code>; and a value * greater than <code>0</code> if the argument is a * <code>Long</code> numerically less than this * <code>Long</code>. * @exception <code>ClassCastException</code> if the argument is not a * <code>Long</code>. * @see java.lang.Comparable * @since 1.2 */ public int compareTo(Object o) { return compareTo((Long)o); } /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = 4290774380558885855L;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -