Adding libraries to lang.
svn: r3218
This commit is contained in:
parent
d489e3e0b3
commit
cff35de4c9
357
collects/profj/libs/java/lang/Byte.java
Normal file
357
collects/profj/libs/java/lang/Byte.java
Normal file
|
@ -0,0 +1,357 @@
|
|||
/* Byte.java -- object wrapper for byte
|
||||
Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang;
|
||||
|
||||
/**
|
||||
* Instances of class <code>Byte</code> represent primitive <code>byte</code>
|
||||
* values.
|
||||
*
|
||||
* Additionally, this class provides various helper functions and variables
|
||||
* useful to bytes.
|
||||
*
|
||||
* @author Paul Fisher
|
||||
* @author John Keiser
|
||||
* @author Per Bothner
|
||||
* @author Eric Blake <ebb9@email.byu.edu>
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class Byte extends Number implements Comparable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.1+.
|
||||
*/
|
||||
private static final long serialVersionUID = -7183698231559129828L;
|
||||
|
||||
/**
|
||||
* The minimum value a <code>byte</code> can represent is -128 (or
|
||||
* -2<sup>7</sup>).
|
||||
*/
|
||||
public static final byte MIN_VALUE = -128;
|
||||
|
||||
/**
|
||||
* The maximum value a <code>byte</code> can represent is 127 (or
|
||||
* 2<sup>7</sup> - 1).
|
||||
*/
|
||||
public static final byte MAX_VALUE = 127;
|
||||
|
||||
/**
|
||||
* The primitive type <code>byte</code> is represented by this
|
||||
* <code>Class</code> object.
|
||||
*/
|
||||
//public static final Class TYPE = VMClassLoader.getPrimitiveClass('B');
|
||||
|
||||
/**
|
||||
* The immutable value of this Byte.
|
||||
*
|
||||
* @serial the wrapped byte
|
||||
*/
|
||||
private final byte value;
|
||||
|
||||
/**
|
||||
* Create a <code>Byte</code> object representing the value of the
|
||||
* <code>byte</code> argument.
|
||||
*
|
||||
* @param value the value to use
|
||||
*/
|
||||
public Byte(byte value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>Byte</code> object representing the value specified
|
||||
* by the <code>String</code> argument
|
||||
*
|
||||
* @param s the string to convert
|
||||
* @throws NumberFormatException if the String does not contain a byte
|
||||
* @see #valueOf(String)
|
||||
*/
|
||||
public Byte(String s)
|
||||
{
|
||||
value = parseByte(s, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>byte</code> to a <code>String</code> and assumes
|
||||
* a radix of 10.
|
||||
*
|
||||
* @param b the <code>byte</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toString(byte b)
|
||||
{
|
||||
return String.valueOf((int)b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into a <code>byte</code>.
|
||||
* This function assumes a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the <code>byte</code> value of <code>s</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>byte</code>
|
||||
* @see #parseByte(String)
|
||||
*/
|
||||
public static byte parseByte(String s)
|
||||
{
|
||||
return parseByte(s, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into an <code>int</code>
|
||||
* using the specified radix (base). The string must not be <code>null</code>
|
||||
* or empty. It may begin with an optional '-', which will negate the answer,
|
||||
* provided that there are also valid digits. Each digit is parsed as if by
|
||||
* <code>Character.digit(d, radix)</code>, and must be in the range
|
||||
* <code>0</code> to <code>radix - 1</code>. Finally, the result must be
|
||||
* within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive.
|
||||
* Unlike Double.parseDouble, you may not have a leading '+'.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @param radix the radix (base) to use in the conversion
|
||||
* @return the <code>String</code> argument converted to <code>byte</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>byte</code>
|
||||
*/
|
||||
public static byte parseByte(String s, int radix)
|
||||
{
|
||||
int i = Integer.parseInt(s, radix, false);
|
||||
if ((byte) i != i)
|
||||
throw new NumberFormatException();
|
||||
return (byte) i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Byte</code> object using the <code>String</code>
|
||||
* and specified radix (base).
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @param radix the radix (base) to convert with
|
||||
* @return the new <code>Byte</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>byte</code>
|
||||
* @see #parseByte(String, int)
|
||||
*/
|
||||
public static Byte valueOf(String s, int radix)
|
||||
{
|
||||
return new Byte(parseByte(s, radix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Byte</code> object using the <code>String</code>,
|
||||
* assuming a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the new <code>Byte</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>byte</code>
|
||||
* @see #Byte(String)
|
||||
* @see #parseByte(String)
|
||||
*/
|
||||
public static Byte valueOf(String s)
|
||||
{
|
||||
return new Byte(parseByte(s, 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified <code>String</code> into a <code>Byte</code>.
|
||||
* The <code>String</code> may represent decimal, hexadecimal, or
|
||||
* octal numbers.
|
||||
*
|
||||
* <p>The extended BNF grammar is as follows:<br>
|
||||
* <pre>
|
||||
* <em>DecodableString</em>:
|
||||
* ( [ <code>-</code> ] <em>DecimalNumber</em> )
|
||||
* | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code>
|
||||
* | <code>#</code> ) { <em>HexDigit</em> }+ )
|
||||
* | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } )
|
||||
* <em>DecimalNumber</em>:
|
||||
* <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> }
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 10) has value 0 to 9</em>
|
||||
* <em>OctalDigit</em>:
|
||||
* <em>Character.digit(d, 8) has value 0 to 7</em>
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 16) has value 0 to 15</em>
|
||||
* </pre>
|
||||
* Finally, the value must be in the range <code>MIN_VALUE</code> to
|
||||
* <code>MAX_VALUE</code>, or an exception is thrown.
|
||||
*
|
||||
* @param s the <code>String</code> to interpret
|
||||
* @return the value of the String as a <code>Byte</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>byte</code>
|
||||
* @throws NullPointerException if <code>s</code> is null
|
||||
* @see Integer#decode(String)
|
||||
*/
|
||||
public static Byte decode(String s)
|
||||
{
|
||||
int i = Integer.parseInt(s, 10, true);
|
||||
if ((byte) i != i)
|
||||
throw new NumberFormatException();
|
||||
return new Byte((byte) i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Byte</code>.
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Byte</code> as a <code>short</code>.
|
||||
*
|
||||
* @return the short value
|
||||
*/
|
||||
public short shortValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Byte</code> as an <code>int</code>.
|
||||
*
|
||||
* @return the int value
|
||||
*/
|
||||
public int intValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Byte</code> as a <code>long</code>.
|
||||
*
|
||||
* @return the long value
|
||||
*/
|
||||
public long longValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Byte</code> as a <code>float</code>.
|
||||
*
|
||||
* @return the float value
|
||||
*/
|
||||
public float floatValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Byte</code> as a <code>double</code>.
|
||||
*
|
||||
* @return the double value
|
||||
*/
|
||||
public double doubleValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>Byte</code> value to a <code>String</code> and
|
||||
* assumes a radix of 10.
|
||||
*
|
||||
* @return the <code>String</code> representation of this <code>Byte</code>
|
||||
* @see Integer#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf((int)value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hashcode representing this Object. <code>Byte</code>'s hash
|
||||
* code is simply its value.
|
||||
*
|
||||
* @return this Object's hash code
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if <code>obj</code> is an instance of
|
||||
* <code>Byte</code> and represents the same byte value.
|
||||
*
|
||||
* @param obj the object to compare
|
||||
* @return whether these Objects are semantically equal
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Byte && value == ((Byte) obj).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two Bytes numerically by comparing their <code>byte</code> values.
|
||||
* The result is positive if the first is greater, negative if the second
|
||||
* is greater, and 0 if the two are equal.
|
||||
*
|
||||
* @param b the Byte to compare
|
||||
* @return the comparison
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Byte b)
|
||||
{
|
||||
return value - b.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaves like <code>compareTo(Byte)</code> unless the Object
|
||||
* is not a <code>Byte</code>.
|
||||
*
|
||||
* @param o the object to compare
|
||||
* @return the comparison
|
||||
* @throws ClassCastException if the argument is not a <code>Byte</code>
|
||||
* @see #compareTo(Byte)
|
||||
* @see Comparable
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Object o)
|
||||
{
|
||||
return compareTo((Byte) o);
|
||||
}
|
||||
}
|
2282
collects/profj/libs/java/lang/Character.djava
Normal file
2282
collects/profj/libs/java/lang/Character.djava
Normal file
File diff suppressed because it is too large
Load Diff
608
collects/profj/libs/java/lang/Integer.java
Normal file
608
collects/profj/libs/java/lang/Integer.java
Normal file
|
@ -0,0 +1,608 @@
|
|||
/* Integer.java -- object wrapper for int
|
||||
Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang;
|
||||
|
||||
/**
|
||||
* Instances of class <code>Integer</code> represent primitive
|
||||
* <code>int</code> values.
|
||||
*
|
||||
* Additionally, this class provides various helper functions and variables
|
||||
* related to ints.
|
||||
*
|
||||
* @author Paul Fisher
|
||||
* @author John Keiser
|
||||
* @author Warren Levy
|
||||
* @author Eric Blake <ebb9@email.byu.edu>
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class Integer extends Number implements Comparable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0.2+.
|
||||
*/
|
||||
private static final long serialVersionUID = 1360826667806852920L;
|
||||
|
||||
/**
|
||||
* The minimum value an <code>int</code> can represent is -2147483648 (or
|
||||
* -2<sup>31</sup>).
|
||||
*/
|
||||
public static final int MIN_VALUE = 0x80000000;
|
||||
|
||||
/**
|
||||
* The maximum value an <code>int</code> can represent is 2147483647 (or
|
||||
* 2<sup>31</sup> - 1).
|
||||
*/
|
||||
public static final int MAX_VALUE = 0x7fffffff;
|
||||
|
||||
/**
|
||||
* The primitive type <code>int</code> is represented by this
|
||||
* <code>Class</code> object.
|
||||
* @since 1.1
|
||||
*/
|
||||
//public static final Class TYPE = VMClassLoader.getPrimitiveClass('I');
|
||||
|
||||
/**
|
||||
* The immutable value of this Integer.
|
||||
*
|
||||
* @serial the wrapped int
|
||||
*/
|
||||
private final int value;
|
||||
|
||||
/**
|
||||
* Create an <code>Integer</code> object representing the value of the
|
||||
* <code>int</code> argument.
|
||||
*
|
||||
* @param value the value to use
|
||||
*/
|
||||
public Integer(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an <code>Integer</code> object representing the value of the
|
||||
* argument after conversion to an <code>int</code>.
|
||||
*
|
||||
* @param s the string to convert
|
||||
* @throws NumberFormatException if the String does not contain an int
|
||||
* @see #valueOf(String)
|
||||
*/
|
||||
public Integer(String s)
|
||||
{
|
||||
value = parseInt(s, 10, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>int</code> to a <code>String</code> using
|
||||
* the specified radix (base). If the radix exceeds
|
||||
* <code>Character.MIN_RADIX</code> or <code>Character.MAX_RADIX</code>, 10
|
||||
* is used instead. If the result is negative, the leading character is
|
||||
* '-' ('\\u002D'). The remaining characters come from
|
||||
* <code>Character.forDigit(digit, radix)</code> ('0'-'9','a'-'z').
|
||||
*
|
||||
* @param num the <code>int</code> to convert to <code>String</code>
|
||||
* @param radix the radix (base) to use in the conversion
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toString(int num, int radix)
|
||||
{
|
||||
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
|
||||
radix = 10;
|
||||
|
||||
// For negative numbers, print out the absolute value w/ a leading '-'.
|
||||
// Use an array large enough for a binary number.
|
||||
char[] buffer = new char[33];
|
||||
int i = 33;
|
||||
boolean isNeg = false;
|
||||
if (num < 0)
|
||||
{
|
||||
isNeg = true;
|
||||
num = -num;
|
||||
|
||||
// When the value is MIN_VALUE, it overflows when made positive
|
||||
if (num < 0)
|
||||
{
|
||||
buffer[--i] = digits[(int) (-(num + radix) % radix)];
|
||||
num = -(num / radix);
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
buffer[--i] = digits[num % radix];
|
||||
num /= radix;
|
||||
}
|
||||
while (num > 0);
|
||||
|
||||
if (isNeg)
|
||||
buffer[--i] = '-';
|
||||
|
||||
// Package constructor avoids an array copy.
|
||||
return new String(buffer, i, 33 - i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>int</code> to a <code>String</code> assuming it is
|
||||
* unsigned in base 16.
|
||||
*
|
||||
* @param i the <code>int</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toHexString(int i)
|
||||
{
|
||||
return toUnsignedString(i, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>int</code> to a <code>String</code> assuming it is
|
||||
* unsigned in base 8.
|
||||
*
|
||||
* @param i the <code>int</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toOctalString(int i)
|
||||
{
|
||||
return toUnsignedString(i, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>int</code> to a <code>String</code> assuming it is
|
||||
* unsigned in base 2.
|
||||
*
|
||||
* @param i the <code>int</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toBinaryString(int i)
|
||||
{
|
||||
return toUnsignedString(i, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>int</code> to a <code>String</code> and assumes
|
||||
* a radix of 10.
|
||||
*
|
||||
* @param i the <code>int</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
* @see #toString(int, int)
|
||||
*/
|
||||
public static String toString(int i)
|
||||
{
|
||||
// This is tricky: in libgcj, String.valueOf(int) is a fast native
|
||||
// implementation. In Classpath it just calls back to
|
||||
// Integer.toString(int, int).
|
||||
return String.valueOf(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into an <code>int</code>
|
||||
* using the specified radix (base). The string must not be <code>null</code>
|
||||
* or empty. It may begin with an optional '-', which will negate the answer,
|
||||
* provided that there are also valid digits. Each digit is parsed as if by
|
||||
* <code>Character.digit(d, radix)</code>, and must be in the range
|
||||
* <code>0</code> to <code>radix - 1</code>. Finally, the result must be
|
||||
* within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive.
|
||||
* Unlike Double.parseDouble, you may not have a leading '+'.
|
||||
*
|
||||
* @param str the <code>String</code> to convert
|
||||
* @param radix the radix (base) to use in the conversion
|
||||
* @return the <code>String</code> argument converted to <code>int</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as an
|
||||
* <code>int</code>
|
||||
*/
|
||||
public static int parseInt(String str, int radix)
|
||||
{
|
||||
return parseInt(str, radix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into an <code>int</code>.
|
||||
* This function assumes a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the <code>int</code> value of <code>s</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as an
|
||||
* <code>int</code>
|
||||
* @see #parseInt(String, int)
|
||||
*/
|
||||
public static int parseInt(String s)
|
||||
{
|
||||
return parseInt(s, 10, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Integer</code> object using the <code>String</code>
|
||||
* and specified radix (base).
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @param radix the radix (base) to convert with
|
||||
* @return the new <code>Integer</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as an
|
||||
* <code>int</code>
|
||||
* @see #parseInt(String, int)
|
||||
*/
|
||||
public static Integer valueOf(String s, int radix)
|
||||
{
|
||||
return new Integer(parseInt(s, radix, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Integer</code> object using the <code>String</code>,
|
||||
* assuming a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the new <code>Integer</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as an
|
||||
* <code>int</code>
|
||||
* @see #Integer(String)
|
||||
* @see #parseInt(String)
|
||||
*/
|
||||
public static Integer valueOf(String s)
|
||||
{
|
||||
return new Integer(parseInt(s, 10, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Integer</code> as a <code>byte</code>.
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue()
|
||||
{
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Integer</code> as a <code>short</code>.
|
||||
*
|
||||
* @return the short value
|
||||
*/
|
||||
public short shortValue()
|
||||
{
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Integer</code>.
|
||||
* @return the int value
|
||||
*/
|
||||
public int intValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Integer</code> as a <code>long</code>.
|
||||
*
|
||||
* @return the long value
|
||||
*/
|
||||
public long longValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Integer</code> as a <code>float</code>.
|
||||
*
|
||||
* @return the float value
|
||||
*/
|
||||
public float floatValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Integer</code> as a <code>double</code>.
|
||||
*
|
||||
* @return the double value
|
||||
*/
|
||||
public double doubleValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>Integer</code> value to a <code>String</code> and
|
||||
* assumes a radix of 10.
|
||||
*
|
||||
* @return the <code>String</code> representation
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hashcode representing this Object. <code>Integer</code>'s hash
|
||||
* code is simply its value.
|
||||
*
|
||||
* @return this Object's hash code
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if <code>obj</code> is an instance of
|
||||
* <code>Integer</code> and represents the same int value.
|
||||
*
|
||||
* @param obj the object to compare
|
||||
* @return whether these Objects are semantically equal
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Integer && value == ((Integer) obj).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified system property as an <code>Integer</code>. The
|
||||
* <code>decode()</code> method will be used to interpret the value of
|
||||
* the property.
|
||||
*
|
||||
* @param nm the name of the system property
|
||||
* @return the system property as an <code>Integer</code>, or null if the
|
||||
* property is not found or cannot be decoded
|
||||
* @throws SecurityException if accessing the system property is forbidden
|
||||
* @see System#getProperty(String)
|
||||
* @see #decode(String)
|
||||
*/
|
||||
public static Integer getInteger(String nm)
|
||||
{
|
||||
return getInteger(nm, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified system property as an <code>Integer</code>, or use a
|
||||
* default <code>int</code> value if the property is not found or is not
|
||||
* decodable. The <code>decode()</code> method will be used to interpret
|
||||
* the value of the property.
|
||||
*
|
||||
* @param nm the name of the system property
|
||||
* @param val the default value
|
||||
* @return the value of the system property, or the default
|
||||
* @throws SecurityException if accessing the system property is forbidden
|
||||
* @see System#getProperty(String)
|
||||
* @see #decode(String)
|
||||
*/
|
||||
public static Integer getInteger(String nm, int val)
|
||||
{
|
||||
Integer result = getInteger(nm, null);
|
||||
return result == null ? new Integer(val) : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified system property as an <code>Integer</code>, or use a
|
||||
* default <code>Integer</code> value if the property is not found or is
|
||||
* not decodable. The <code>decode()</code> method will be used to
|
||||
* interpret the value of the property.
|
||||
*
|
||||
* @param nm the name of the system property
|
||||
* @param def the default value
|
||||
* @return the value of the system property, or the default
|
||||
* @throws SecurityException if accessing the system property is forbidden
|
||||
* @see System#getProperty(String)
|
||||
* @see #decode(String)
|
||||
*/
|
||||
public static Integer getInteger(String nm, Integer def)
|
||||
{
|
||||
if (nm == null || "".equals(nm))
|
||||
return def;
|
||||
else
|
||||
return def;
|
||||
/*nm = System.getProperty(nm);
|
||||
if (nm == null)
|
||||
return def;
|
||||
try
|
||||
{
|
||||
return decode(nm);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return def;
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified <code>String</code> into an <code>Integer</code>.
|
||||
* The <code>String</code> may represent decimal, hexadecimal, or
|
||||
* octal numbers.
|
||||
*
|
||||
* <p>The extended BNF grammar is as follows:<br>
|
||||
* <pre>
|
||||
* <em>DecodableString</em>:
|
||||
* ( [ <code>-</code> ] <em>DecimalNumber</em> )
|
||||
* | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code>
|
||||
* | <code>#</code> ) <em>HexDigit</em> { <em>HexDigit</em> } )
|
||||
* | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } )
|
||||
* <em>DecimalNumber</em>:
|
||||
* <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> }
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 10) has value 0 to 9</em>
|
||||
* <em>OctalDigit</em>:
|
||||
* <em>Character.digit(d, 8) has value 0 to 7</em>
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 16) has value 0 to 15</em>
|
||||
* </pre>
|
||||
* Finally, the value must be in the range <code>MIN_VALUE</code> to
|
||||
* <code>MAX_VALUE</code>, or an exception is thrown.
|
||||
*
|
||||
* @param str the <code>String</code> to interpret
|
||||
* @return the value of the String as an <code>Integer</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>int</code>
|
||||
* @throws NullPointerException if <code>s</code> is null
|
||||
* @since 1.2
|
||||
*/
|
||||
public static Integer decode(String str)
|
||||
{
|
||||
return new Integer(parseInt(str, 10, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two Integers numerically by comparing their <code>int</code>
|
||||
* values. The result is positive if the first is greater, negative if the
|
||||
* second is greater, and 0 if the two are equal.
|
||||
*
|
||||
* @param i the Integer to compare
|
||||
* @return the comparison
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Integer i)
|
||||
{
|
||||
if (value == i.value)
|
||||
return 0;
|
||||
// Returns just -1 or 1 on inequality; doing math might overflow.
|
||||
return value > i.value ? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaves like <code>compareTo(Integer)</code> unless the Object
|
||||
* is not an <code>Integer</code>.
|
||||
*
|
||||
* @param o the object to compare
|
||||
* @return the comparison
|
||||
* @throws ClassCastException if the argument is not an <code>Integer</code>
|
||||
* @see #compareTo(Integer)
|
||||
* @see Comparable
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Object o)
|
||||
{
|
||||
return compareTo((Integer) o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for converting unsigned numbers to String.
|
||||
*
|
||||
* @param num the number
|
||||
* @param exp log2(digit) (ie. 1, 3, or 4 for binary, oct, hex)
|
||||
*/
|
||||
// Package visible for use by Long.
|
||||
static String toUnsignedString(int num, int exp)
|
||||
{
|
||||
// Use an array large enough for a binary number.
|
||||
int mask = (1 << exp) - 1;
|
||||
char[] buffer = new char[32];
|
||||
int i = 32;
|
||||
do
|
||||
{
|
||||
buffer[--i] = digits[num & mask];
|
||||
num >>>= exp;
|
||||
}
|
||||
while (num != 0);
|
||||
|
||||
// Package constructor avoids an array copy.
|
||||
return new String(buffer, i, 32 - i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for parsing ints, used by Integer, Short, and Byte.
|
||||
*
|
||||
* @param str the string to parse
|
||||
* @param radix the radix to use, must be 10 if decode is true
|
||||
* @param decode if called from decode
|
||||
* @return the parsed int value
|
||||
* @throws NumberFormatException if there is an error
|
||||
* @throws NullPointerException if decode is true and str if null
|
||||
* @see #parseInt(String, int)
|
||||
* @see #decode(String)
|
||||
* @see Byte#parseInt(String, int)
|
||||
* @see Short#parseInt(String, int)
|
||||
*/
|
||||
static int parseInt(String str, int radix, boolean decode)
|
||||
{
|
||||
if (! decode && str == null)
|
||||
throw new NumberFormatException("parseInt cannot convert an empty String into an int");
|
||||
int index = 0;
|
||||
int len = str.length();
|
||||
boolean isNeg = false;
|
||||
if (len == 0)
|
||||
throw new NumberFormatException("parseInt cannot convert and empty String into an int");
|
||||
int ch = (int) str.charAt(index);
|
||||
if (ch == '-')
|
||||
{
|
||||
if (len == 1)
|
||||
throw new NumberFormatException("parseInt cannot convert - into an int");
|
||||
isNeg = true;
|
||||
ch = str.charAt(++index);
|
||||
}
|
||||
if (decode)
|
||||
{
|
||||
if (ch == '0')
|
||||
{
|
||||
if (++index == len)
|
||||
return 0;
|
||||
if ((str.charAt(index) & ~('x' ^ 'X')) == 'X')
|
||||
{
|
||||
radix = 16;
|
||||
index++;
|
||||
}
|
||||
else
|
||||
radix = 8;
|
||||
}
|
||||
else if (ch == '#')
|
||||
{
|
||||
radix = 16;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
if (index == len)
|
||||
throw new NumberFormatException("parseInt cannot convert " + str + " into an int");
|
||||
|
||||
int max = MAX_VALUE / radix;
|
||||
// We can't directly write `max = (MAX_VALUE + 1) / radix'.
|
||||
// So instead we fake it.
|
||||
if (isNeg && MAX_VALUE % radix == radix - 1)
|
||||
++max;
|
||||
|
||||
int val = 0;
|
||||
while (index < len)
|
||||
{
|
||||
if (val < 0 || val > max)
|
||||
throw new NumberFormatException("Number given to parseInt exceeded allowed size.");
|
||||
|
||||
ch = Character.digit(str.charAt(index++), radix);
|
||||
val = val * radix + ch;
|
||||
if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE)))
|
||||
throw new NumberFormatException("Input given to parseInt contains non-numeric character");
|
||||
}
|
||||
return isNeg ? -val : val;
|
||||
}
|
||||
}
|
616
collects/profj/libs/java/lang/Long.java
Normal file
616
collects/profj/libs/java/lang/Long.java
Normal file
|
@ -0,0 +1,616 @@
|
|||
/* Long.java -- object wrapper for long
|
||||
Copyright (C) 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang;
|
||||
|
||||
/**
|
||||
* Instances of class <code>Long</code> represent primitive
|
||||
* <code>long</code> values.
|
||||
*
|
||||
* Additionally, this class provides various helper functions and variables
|
||||
* related to longs.
|
||||
*
|
||||
* @author Paul Fisher
|
||||
* @author John Keiser
|
||||
* @author Warren Levy
|
||||
* @author Eric Blake <ebb9@email.byu.edu>
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class Long extends Number implements Comparable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0.2+.
|
||||
*/
|
||||
private static final long serialVersionUID = 4290774380558885855L;
|
||||
|
||||
/**
|
||||
* The minimum value a <code>long</code> can represent is
|
||||
* -9223372036854775808L (or -2<sup>63</sup>).
|
||||
*/
|
||||
public static final long MIN_VALUE = 0x8000000000000000L;
|
||||
|
||||
/**
|
||||
* The maximum value a <code>long</code> can represent is
|
||||
* 9223372036854775807 (or 2<sup>63</sup> - 1).
|
||||
*/
|
||||
public static final long MAX_VALUE = 0x7fffffffffffffffL;
|
||||
|
||||
/**
|
||||
* The primitive type <code>long</code> is represented by this
|
||||
* <code>Class</code> object.
|
||||
* @since 1.1
|
||||
*/
|
||||
//public static final Class TYPE = VMClassLoader.getPrimitiveClass ('J');
|
||||
|
||||
/**
|
||||
* The immutable value of this Long.
|
||||
*
|
||||
* @serial the wrapped long
|
||||
*/
|
||||
private final long value;
|
||||
|
||||
/**
|
||||
* Create a <code>Long</code> object representing the value of the
|
||||
* <code>long</code> argument.
|
||||
*
|
||||
* @param value the value to use
|
||||
*/
|
||||
public Long(long value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>Long</code> object representing the value of the
|
||||
* argument after conversion to a <code>long</code>.
|
||||
*
|
||||
* @param s the string to convert
|
||||
* @throws NumberFormatException if the String does not contain a long
|
||||
* @see #valueOf(String)
|
||||
*/
|
||||
public Long(String s)
|
||||
{
|
||||
value = parseLong(s, 10, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>long</code> to a <code>String</code> using
|
||||
* the specified radix (base). If the radix exceeds
|
||||
* <code>Character.MIN_RADIX</code> or <code>Character.MAX_RADIX</code>, 10
|
||||
* is used instead. If the result is negative, the leading character is
|
||||
* '-' ('\\u002D'). The remaining characters come from
|
||||
* <code>Character.forDigit(digit, radix)</code> ('0'-'9','a'-'z').
|
||||
*
|
||||
* @param num the <code>long</code> to convert to <code>String</code>
|
||||
* @param radix the radix (base) to use in the conversion
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toString(long num, int radix)
|
||||
{
|
||||
// Use the Integer toString for efficiency if possible.
|
||||
if ((int) num == num)
|
||||
return Integer.toString((int) num, radix);
|
||||
|
||||
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
|
||||
radix = 10;
|
||||
|
||||
// For negative numbers, print out the absolute value w/ a leading '-'.
|
||||
// Use an array large enough for a binary number.
|
||||
char[] buffer = new char[65];
|
||||
int i = 65;
|
||||
boolean isNeg = false;
|
||||
if (num < 0)
|
||||
{
|
||||
isNeg = true;
|
||||
num = -num;
|
||||
|
||||
// When the value is MIN_VALUE, it overflows when made positive
|
||||
if (num < 0)
|
||||
{
|
||||
buffer[--i] = digits[(int) (-(num + radix) % radix)];
|
||||
num = -(num / radix);
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
buffer[--i] = digits[(int) (num % radix)];
|
||||
num /= radix;
|
||||
}
|
||||
while (num > 0);
|
||||
|
||||
if (isNeg)
|
||||
buffer[--i] = '-';
|
||||
|
||||
// Package constructor avoids an array copy.
|
||||
return new String(buffer, i, 65 - i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>long</code> to a <code>String</code> assuming it is
|
||||
* unsigned in base 16.
|
||||
*
|
||||
* @param l the <code>long</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toHexString(long l)
|
||||
{
|
||||
return toUnsignedString(l, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>long</code> to a <code>String</code> assuming it is
|
||||
* unsigned in base 8.
|
||||
*
|
||||
* @param l the <code>long</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toOctalString(long l)
|
||||
{
|
||||
return toUnsignedString(l, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>long</code> to a <code>String</code> assuming it is
|
||||
* unsigned in base 2.
|
||||
*
|
||||
* @param l the <code>long</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toBinaryString(long l)
|
||||
{
|
||||
return toUnsignedString(l, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>long</code> to a <code>String</code> and assumes
|
||||
* a radix of 10.
|
||||
*
|
||||
* @param num the <code>long</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
* @see #toString(long, int)
|
||||
*/
|
||||
public static String toString(long num)
|
||||
{
|
||||
return toString(num, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into an <code>int</code>
|
||||
* using the specified radix (base). The string must not be <code>null</code>
|
||||
* or empty. It may begin with an optional '-', which will negate the answer,
|
||||
* provided that there are also valid digits. Each digit is parsed as if by
|
||||
* <code>Character.digit(d, radix)</code>, and must be in the range
|
||||
* <code>0</code> to <code>radix - 1</code>. Finally, the result must be
|
||||
* within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive.
|
||||
* Unlike Double.parseDouble, you may not have a leading '+'; and 'l' or
|
||||
* 'L' as the last character is only valid in radices 22 or greater, where
|
||||
* it is a digit and not a type indicator.
|
||||
*
|
||||
* @param str the <code>String</code> to convert
|
||||
* @param radix the radix (base) to use in the conversion
|
||||
* @return the <code>String</code> argument converted to <code>long</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>long</code>
|
||||
*/
|
||||
public static long parseLong(String str, int radix)
|
||||
{
|
||||
return parseLong(str, radix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into a <code>long</code>.
|
||||
* This function assumes a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the <code>int</code> value of <code>s</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>long</code>
|
||||
* @see #parseLong(String, int)
|
||||
*/
|
||||
public static long parseLong(String s)
|
||||
{
|
||||
return parseLong(s, 10, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Long</code> object using the <code>String</code>
|
||||
* and specified radix (base).
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @param radix the radix (base) to convert with
|
||||
* @return the new <code>Long</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>long</code>
|
||||
* @see #parseLong(String, int)
|
||||
*/
|
||||
public static Long valueOf(String s, int radix)
|
||||
{
|
||||
return new Long(parseLong(s, radix, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Long</code> object using the <code>String</code>,
|
||||
* assuming a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the new <code>Long</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>long</code>
|
||||
* @see #Long(String)
|
||||
* @see #parseLong(String)
|
||||
*/
|
||||
public static Long valueOf(String s)
|
||||
{
|
||||
return new Long(parseLong(s, 10, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified <code>String</code> into a <code>Long</code>.
|
||||
* The <code>String</code> may represent decimal, hexadecimal, or
|
||||
* octal numbers.
|
||||
*
|
||||
* <p>The extended BNF grammar is as follows:<br>
|
||||
* <pre>
|
||||
* <em>DecodableString</em>:
|
||||
* ( [ <code>-</code> ] <em>DecimalNumber</em> )
|
||||
* | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code>
|
||||
* | <code>#</code> ) <em>HexDigit</em> { <em>HexDigit</em> } )
|
||||
* | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } )
|
||||
* <em>DecimalNumber</em>:
|
||||
* <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> }
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 10) has value 0 to 9</em>
|
||||
* <em>OctalDigit</em>:
|
||||
* <em>Character.digit(d, 8) has value 0 to 7</em>
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 16) has value 0 to 15</em>
|
||||
* </pre>
|
||||
* Finally, the value must be in the range <code>MIN_VALUE</code> to
|
||||
* <code>MAX_VALUE</code>, or an exception is thrown. Note that you cannot
|
||||
* use a trailing 'l' or 'L', unlike in Java source code.
|
||||
*
|
||||
* @param str the <code>String</code> to interpret
|
||||
* @return the value of the String as a <code>Long</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>long</code>
|
||||
* @throws NullPointerException if <code>s</code> is null
|
||||
* @since 1.2
|
||||
*/
|
||||
public static Long decode(String str)
|
||||
{
|
||||
return new Long(parseLong(str, 10, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Long</code> as a <code>byte</code>.
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue()
|
||||
{
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Long</code> as a <code>short</code>.
|
||||
*
|
||||
* @return the short value
|
||||
*/
|
||||
public short shortValue()
|
||||
{
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Long</code> as an <code>int</code>.
|
||||
*
|
||||
* @return the int value
|
||||
*/
|
||||
public int intValue()
|
||||
{
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Long</code>.
|
||||
*
|
||||
* @return the long value
|
||||
*/
|
||||
public long longValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Long</code> as a <code>float</code>.
|
||||
*
|
||||
* @return the float value
|
||||
*/
|
||||
public float floatValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Long</code> as a <code>double</code>.
|
||||
*
|
||||
* @return the double value
|
||||
*/
|
||||
public double doubleValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>Long</code> value to a <code>String</code> and
|
||||
* assumes a radix of 10.
|
||||
*
|
||||
* @return the <code>String</code> representation
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return toString(value, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hashcode representing this Object. <code>Long</code>'s hash
|
||||
* code is calculated by <code>(int) (value ^ (value >> 32))</code>.
|
||||
*
|
||||
* @return this Object's hash code
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return (int) (value ^ (value >>> 32));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if <code>obj</code> is an instance of
|
||||
* <code>Long</code> and represents the same long value.
|
||||
*
|
||||
* @param obj the object to compare
|
||||
* @return whether these Objects are semantically equal
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Long && value == ((Long) obj).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified system property as a <code>Long</code>. The
|
||||
* <code>decode()</code> method will be used to interpret the value of
|
||||
* the property.
|
||||
*
|
||||
* @param nm the name of the system property
|
||||
* @return the system property as a <code>Long</code>, or null if the
|
||||
* property is not found or cannot be decoded
|
||||
* @throws SecurityException if accessing the system property is forbidden
|
||||
* @see System#getProperty(String)
|
||||
* @see #decode(String)
|
||||
*/
|
||||
public static Long getLong(String nm)
|
||||
{
|
||||
return getLong(nm, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified system property as a <code>Long</code>, or use a
|
||||
* default <code>long</code> value if the property is not found or is not
|
||||
* decodable. The <code>decode()</code> method will be used to interpret
|
||||
* the value of the property.
|
||||
*
|
||||
* @param nm the name of the system property
|
||||
* @param val the default value
|
||||
* @return the value of the system property, or the default
|
||||
* @throws SecurityException if accessing the system property is forbidden
|
||||
* @see System#getProperty(String)
|
||||
* @see #decode(String)
|
||||
*/
|
||||
public static Long getLong(String nm, long val)
|
||||
{
|
||||
Long result = getLong(nm, null);
|
||||
return result == null ? new Long(val) : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specified system property as a <code>Long</code>, or use a
|
||||
* default <code>Long</code> value if the property is not found or is
|
||||
* not decodable. The <code>decode()</code> method will be used to
|
||||
* interpret the value of the property.
|
||||
*
|
||||
* @param nm the name of the system property
|
||||
* @param def the default value
|
||||
* @return the value of the system property, or the default
|
||||
* @throws SecurityException if accessing the system property is forbidden
|
||||
* @see System#getProperty(String)
|
||||
* @see #decode(String)
|
||||
*/
|
||||
public static Long getLong(String nm, Long def)
|
||||
{
|
||||
if (nm == null || "".equals(nm))
|
||||
return def;
|
||||
else
|
||||
return def;
|
||||
/*nm = System.getProperty(nm);
|
||||
if (nm == null)
|
||||
return def;
|
||||
try
|
||||
{
|
||||
return decode(nm);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
return def;
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two Longs numerically by comparing their <code>long</code>
|
||||
* values. The result is positive if the first is greater, negative if the
|
||||
* second is greater, and 0 if the two are equal.
|
||||
*
|
||||
* @param l the Long to compare
|
||||
* @return the comparison
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Long l)
|
||||
{
|
||||
if (value == l.value)
|
||||
return 0;
|
||||
// Returns just -1 or 1 on inequality; doing math might overflow the long.
|
||||
return value > l.value ? 1 : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaves like <code>compareTo(Long)</code> unless the Object
|
||||
* is not a <code>Long</code>.
|
||||
*
|
||||
* @param o the object to compare
|
||||
* @return the comparison
|
||||
* @throws ClassCastException if the argument is not a <code>Long</code>
|
||||
* @see #compareTo(Long)
|
||||
* @see Comparable
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Object o)
|
||||
{
|
||||
return compareTo((Long) o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for converting unsigned numbers to String.
|
||||
*
|
||||
* @param num the number
|
||||
* @param exp log2(digit) (ie. 1, 3, or 4 for binary, oct, hex)
|
||||
*/
|
||||
private static String toUnsignedString(long num, int exp)
|
||||
{
|
||||
// Use the Integer toUnsignedString for efficiency if possible.
|
||||
// If NUM<0 then this particular optimization doesn't work
|
||||
// properly.
|
||||
if (num >= 0 && (int) num == num)
|
||||
return Integer.toUnsignedString((int) num, exp);
|
||||
|
||||
// Use an array large enough for a binary number.
|
||||
int mask = (1 << exp) - 1;
|
||||
char[] buffer = new char[64];
|
||||
int i = 64;
|
||||
do
|
||||
{
|
||||
buffer[--i] = digits[(int) num & mask];
|
||||
num >>>= exp;
|
||||
}
|
||||
while (num != 0);
|
||||
|
||||
// Package constructor avoids an array copy.
|
||||
return new String(buffer, i, 64 - i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for parsing longs.
|
||||
*
|
||||
* @param str the string to parse
|
||||
* @param radix the radix to use, must be 10 if decode is true
|
||||
* @param decode if called from decode
|
||||
* @return the parsed long value
|
||||
* @throws NumberFormatException if there is an error
|
||||
* @throws NullPointerException if decode is true and str is null
|
||||
* @see #parseLong(String, int)
|
||||
* @see #decode(String)
|
||||
*/
|
||||
private static long parseLong(String str, int radix, boolean decode)
|
||||
{
|
||||
if (! decode && str == null)
|
||||
throw new NumberFormatException();
|
||||
int index = 0;
|
||||
int len = str.length();
|
||||
boolean isNeg = false;
|
||||
if (len == 0)
|
||||
throw new NumberFormatException();
|
||||
int ch = str.charAt(index);
|
||||
if (ch == '-')
|
||||
{
|
||||
if (len == 1)
|
||||
throw new NumberFormatException();
|
||||
isNeg = true;
|
||||
ch = str.charAt(++index);
|
||||
}
|
||||
if (decode)
|
||||
{
|
||||
if (ch == '0')
|
||||
{
|
||||
if (++index == len)
|
||||
return 0;
|
||||
if ((str.charAt(index) & ~('x' ^ 'X')) == 'X')
|
||||
{
|
||||
radix = 16;
|
||||
index++;
|
||||
}
|
||||
else
|
||||
radix = 8;
|
||||
}
|
||||
else if (ch == '#')
|
||||
{
|
||||
radix = 16;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
if (index == len)
|
||||
throw new NumberFormatException();
|
||||
|
||||
long max = MAX_VALUE / radix;
|
||||
// We can't directly write `max = (MAX_VALUE + 1) / radix'.
|
||||
// So instead we fake it.
|
||||
if (isNeg && MAX_VALUE % radix == radix - 1)
|
||||
++max;
|
||||
|
||||
long val = 0;
|
||||
while (index < len)
|
||||
{
|
||||
if (val < 0 || val > max)
|
||||
throw new NumberFormatException();
|
||||
|
||||
ch = Character.digit(str.charAt(index++), radix);
|
||||
val = val * radix + ch;
|
||||
if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE)))
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
return isNeg ? -val : val;
|
||||
}
|
||||
}
|
353
collects/profj/libs/java/lang/Short.java
Normal file
353
collects/profj/libs/java/lang/Short.java
Normal file
|
@ -0,0 +1,353 @@
|
|||
/* Short.java -- object wrapper for short
|
||||
Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.lang;
|
||||
|
||||
/**
|
||||
* Instances of class <code>Short</code> represent primitive
|
||||
* <code>short</code> values.
|
||||
*
|
||||
* Additionally, this class provides various helper functions and variables
|
||||
* related to shorts.
|
||||
*
|
||||
* @author Paul Fisher
|
||||
* @author John Keiser
|
||||
* @author Eric Blake <ebb9@email.byu.edu>
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class Short extends Number implements Comparable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.1+.
|
||||
*/
|
||||
private static final long serialVersionUID = 7515723908773894738L;
|
||||
|
||||
/**
|
||||
* The minimum value a <code>short</code> can represent is -32768 (or
|
||||
* -2<sup>15</sup>).
|
||||
*/
|
||||
public static final short MIN_VALUE = (short) -32768;
|
||||
|
||||
/**
|
||||
* The minimum value a <code>short</code> can represent is 32767 (or
|
||||
* 2<sup>15</sup>).
|
||||
*/
|
||||
public static final short MAX_VALUE = (short) 32767;
|
||||
|
||||
/**
|
||||
* The primitive type <code>short</code> is represented by this
|
||||
* <code>Class</code> object.
|
||||
*/
|
||||
//public static final Class TYPE = VMClassLoader.getPrimitiveClass('S');
|
||||
|
||||
/**
|
||||
* The immutable value of this Short.
|
||||
*
|
||||
* @serial the wrapped short
|
||||
*/
|
||||
private final short value;
|
||||
|
||||
/**
|
||||
* Create a <code>Short</code> object representing the value of the
|
||||
* <code>short</code> argument.
|
||||
*
|
||||
* @param value the value to use
|
||||
*/
|
||||
public Short(short value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>Short</code> object representing the value of the
|
||||
* argument after conversion to a <code>short</code>.
|
||||
*
|
||||
* @param s the string to convert
|
||||
* @throws NumberFormatException if the String cannot be parsed
|
||||
*/
|
||||
public Short(String s)
|
||||
{
|
||||
value = parseShort(s, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>short</code> to a <code>String</code> and assumes
|
||||
* a radix of 10.
|
||||
*
|
||||
* @param s the <code>short</code> to convert to <code>String</code>
|
||||
* @return the <code>String</code> representation of the argument
|
||||
*/
|
||||
public static String toString(short s)
|
||||
{
|
||||
return String.valueOf((int) s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into a <code>short</code>.
|
||||
* This function assumes a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the <code>short</code> value of <code>s</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>short</code>
|
||||
*/
|
||||
public static short parseShort(String s)
|
||||
{
|
||||
return parseShort(s, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the specified <code>String</code> into a <code>short</code>
|
||||
* using the specified radix (base). The string must not be <code>null</code>
|
||||
* or empty. It may begin with an optional '-', which will negate the answer,
|
||||
* provided that there are also valid digits. Each digit is parsed as if by
|
||||
* <code>Character.digit(d, radix)</code>, and must be in the range
|
||||
* <code>0</code> to <code>radix - 1</code>. Finally, the result must be
|
||||
* within <code>MIN_VALUE</code> to <code>MAX_VALUE</code>, inclusive.
|
||||
* Unlike Double.parseDouble, you may not have a leading '+'.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @param radix the radix (base) to use in the conversion
|
||||
* @return the <code>String</code> argument converted to <code>short</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>short</code>
|
||||
*/
|
||||
public static short parseShort(String s, int radix)
|
||||
{
|
||||
int i = Integer.parseInt(s, radix, false);
|
||||
if ((short) i != i)
|
||||
throw new NumberFormatException();
|
||||
return (short) i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Short</code> object using the <code>String</code>
|
||||
* and specified radix (base).
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @param radix the radix (base) to convert with
|
||||
* @return the new <code>Short</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>short</code>
|
||||
* @see #parseShort(String, int)
|
||||
*/
|
||||
public static Short valueOf(String s, int radix)
|
||||
{
|
||||
return new Short(parseShort(s, radix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Short</code> object using the <code>String</code>,
|
||||
* assuming a radix of 10.
|
||||
*
|
||||
* @param s the <code>String</code> to convert
|
||||
* @return the new <code>Short</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>short</code>
|
||||
* @see #Short(String)
|
||||
* @see #parseShort(String)
|
||||
*/
|
||||
public static Short valueOf(String s)
|
||||
{
|
||||
return new Short(parseShort(s, 10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the specified <code>String</code> into a <code>Short</code>.
|
||||
* The <code>String</code> may represent decimal, hexadecimal, or
|
||||
* octal numbers.
|
||||
*
|
||||
* <p>The extended BNF grammar is as follows:<br>
|
||||
* <pre>
|
||||
* <em>DecodableString</em>:
|
||||
* ( [ <code>-</code> ] <em>DecimalNumber</em> )
|
||||
* | ( [ <code>-</code> ] ( <code>0x</code> | <code>0X</code>
|
||||
* | <code>#</code> ) <em>HexDigit</em> { <em>HexDigit</em> } )
|
||||
* | ( [ <code>-</code> ] <code>0</code> { <em>OctalDigit</em> } )
|
||||
* <em>DecimalNumber</em>:
|
||||
* <em>DecimalDigit except '0'</em> { <em>DecimalDigit</em> }
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 10) has value 0 to 9</em>
|
||||
* <em>OctalDigit</em>:
|
||||
* <em>Character.digit(d, 8) has value 0 to 7</em>
|
||||
* <em>DecimalDigit</em>:
|
||||
* <em>Character.digit(d, 16) has value 0 to 15</em>
|
||||
* </pre>
|
||||
* Finally, the value must be in the range <code>MIN_VALUE</code> to
|
||||
* <code>MAX_VALUE</code>, or an exception is thrown.
|
||||
*
|
||||
* @param s the <code>String</code> to interpret
|
||||
* @return the value of the String as a <code>Short</code>
|
||||
* @throws NumberFormatException if <code>s</code> cannot be parsed as a
|
||||
* <code>short</code>
|
||||
* @throws NullPointerException if <code>s</code> is null
|
||||
* @see Integer#decode(String)
|
||||
*/
|
||||
public static Short decode(String s)
|
||||
{
|
||||
int i = Integer.parseInt(s, 10, true);
|
||||
if ((short) i != i)
|
||||
throw new NumberFormatException();
|
||||
return new Short((short) i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Short</code> as a <code>byte</code>.
|
||||
*
|
||||
* @return the byte value
|
||||
*/
|
||||
public byte byteValue()
|
||||
{
|
||||
return (byte) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Short</code>.
|
||||
*
|
||||
* @return the short value
|
||||
*/
|
||||
public short shortValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Short</code> as an <code>int</code>.
|
||||
*
|
||||
* @return the int value
|
||||
*/
|
||||
public int intValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Short</code> as a <code>long</code>.
|
||||
*
|
||||
* @return the long value
|
||||
*/
|
||||
public long longValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Short</code> as a <code>float</code>.
|
||||
*
|
||||
* @return the float value
|
||||
*/
|
||||
public float floatValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of this <code>Short</code> as a <code>double</code>.
|
||||
*
|
||||
* @return the double value
|
||||
*/
|
||||
public double doubleValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the <code>Short</code> value to a <code>String</code> and
|
||||
* assumes a radix of 10.
|
||||
*
|
||||
* @return the <code>String</code> representation of this <code>Short</code>
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf((int) value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hashcode representing this Object. <code>Short</code>'s hash
|
||||
* code is simply its value.
|
||||
*
|
||||
* @return this Object's hash code
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if <code>obj</code> is an instance of
|
||||
* <code>Short</code> and represents the same short value.
|
||||
*
|
||||
* @param obj the object to compare
|
||||
* @return whether these Objects are semantically equal
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return obj instanceof Short && value == ((Short) obj).value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two Shorts numerically by comparing their <code>short</code>
|
||||
* values. The result is positive if the first is greater, negative if the
|
||||
* second is greater, and 0 if the two are equal.
|
||||
*
|
||||
* @param s the Short to compare
|
||||
* @return the comparison
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Short s)
|
||||
{
|
||||
return value - s.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaves like <code>compareTo(Short)</code> unless the Object
|
||||
* is not a <code>Short</code>.
|
||||
*
|
||||
* @param o the object to compare
|
||||
* @return the comparison
|
||||
* @throws ClassCastException if the argument is not a <code>Short</code>
|
||||
* @see #compareTo(Short)
|
||||
* @see Comparable
|
||||
* @since 1.2
|
||||
*/
|
||||
public int compareTo(Object o)
|
||||
{
|
||||
return compareTo((Short)o);
|
||||
}
|
||||
}
|
|
@ -17,10 +17,22 @@
|
|||
#f
|
||||
#f)))])
|
||||
(javac "Util.djava")
|
||||
;(printf "util~n")
|
||||
(javac "Math.java")
|
||||
;(printf "math~n")
|
||||
(javac "System.java")
|
||||
;(printf "sys~n")
|
||||
(javac "Number.java")
|
||||
;(printf "num~n")
|
||||
(javac "Boolean.java")
|
||||
;(printf "boolean ~n")
|
||||
(javac "Character.djava")
|
||||
;(printf "character ~n")
|
||||
(javac "Integer.java")
|
||||
;(printf "integer~n")
|
||||
(javac "Short.java")
|
||||
(javac "Byte.java")
|
||||
(javac "Long.java")
|
||||
(javac "Double.java")
|
||||
(javac "Float.java")
|
||||
(javac "Boolean.java")
|
||||
(javac "CharSequence.java")))))
|
||||
|
|
17
collects/profj/libs/java/lang/mz.ss
Normal file
17
collects/profj/libs/java/lang/mz.ss
Normal file
|
@ -0,0 +1,17 @@
|
|||
(module mz mzscheme
|
||||
(provide (all-defined))
|
||||
|
||||
(define downcase char-downcase)
|
||||
(define lower-case? char-lower-case?)
|
||||
(define upcase char-upcase)
|
||||
(define upper-case? char-upper-case?)
|
||||
(define title-case? char-title-case?)
|
||||
(define numeric? char-numeric?)
|
||||
(define alphabetic? char-alphabetic?)
|
||||
(define titlecase char-titlecase)
|
||||
(define whitespace? char-whitespace?)
|
||||
(define blank? char-blank?)
|
||||
(define iso-control? char-iso-control?)
|
||||
(define get-num string->number)
|
||||
(define bool? boolean?)
|
||||
)
|
|
@ -179,14 +179,16 @@
|
|||
(send current-tab current-test-editor content)
|
||||
(unless curr-win
|
||||
(send current-tab current-test-window window)
|
||||
(send drscheme-frame register-test-window window))
|
||||
(send window update-switch
|
||||
(lambda () (send drscheme-frame dock-tests)))
|
||||
(send window update-closer
|
||||
(lambda()
|
||||
(send drscheme-frame deregister-test-window window)
|
||||
(send current-tab current-test-window #f)
|
||||
(send current-tab current-test-editor #f)))
|
||||
(send drscheme-frame register-test-window window)
|
||||
(send window update-switch
|
||||
(lambda () (send drscheme-frame dock-tests)))
|
||||
(send window update-disable
|
||||
(lambda () (send current-tab update-test-preference #f)))
|
||||
(send window update-closer
|
||||
(lambda()
|
||||
(send drscheme-frame deregister-test-window window)
|
||||
(send current-tab current-test-window #f)
|
||||
(send current-tab current-test-editor #f))))
|
||||
(if (get-preference 'profj:test-window:docked?
|
||||
(lambda () (put-preferences '(profj:test-window:docked?) '(#f)) #f))
|
||||
(send drscheme-frame display-test-panel content)
|
||||
|
@ -281,6 +283,7 @@
|
|||
|
||||
(define editor #f)
|
||||
(define switch-func void)
|
||||
(define disable-func void)
|
||||
(define close-cleanup void)
|
||||
|
||||
(define content
|
||||
|
@ -302,7 +305,7 @@
|
|||
button-panel
|
||||
(lambda (b c)
|
||||
(when (eq? 'button (send c get-event-type))
|
||||
(put-preferences '(profj:test-enable) '(#f))
|
||||
(disable-func)
|
||||
(close-cleanup)
|
||||
(send this show #f))))
|
||||
(make-object button%
|
||||
|
@ -324,6 +327,8 @@
|
|||
(set! switch-func thunk))
|
||||
(define/public (update-closer thunk)
|
||||
(set! close-cleanup thunk))
|
||||
(define/public (update-disable thunk)
|
||||
(set! disable-func thunk))
|
||||
))
|
||||
|
||||
(define test-panel%
|
||||
|
@ -356,7 +361,7 @@
|
|||
(lambda (b c)
|
||||
(when (eq? 'button (send c get-event-type))
|
||||
(hide)
|
||||
(put-preferences '(profj:test-enable) '(#f)))))
|
||||
(send (send frame get-current-tab) update-test-preference #f))))
|
||||
(make-object button%
|
||||
(string-constant undock)
|
||||
button-panel
|
||||
|
@ -563,7 +568,7 @@
|
|||
(class % ()
|
||||
|
||||
(inherit get-current-tab)
|
||||
|
||||
|
||||
(define/public (display-test-panel editor)
|
||||
(send test-panel update-editor editor)
|
||||
(unless (send test-panel is-shown?)
|
||||
|
@ -618,7 +623,7 @@
|
|||
(define (test-tab%-mixin %)
|
||||
(class % ()
|
||||
|
||||
(inherit get-frame)
|
||||
(inherit get-frame get-defs)
|
||||
|
||||
(define test-editor #f)
|
||||
(define/public (get-test-editor) test-editor)
|
||||
|
@ -630,6 +635,25 @@
|
|||
(define/public (current-test-window w)
|
||||
(set! test-window w))
|
||||
|
||||
(define/public (update-test-preference test?)
|
||||
(let* ([language-settings
|
||||
(preferences:get
|
||||
(drscheme:language-configuration:get-settings-preferences-symbol))]
|
||||
[language
|
||||
(drscheme:language-configuration:language-settings-language
|
||||
language-settings)]
|
||||
[settings
|
||||
(drscheme:language-configuration:language-settings-settings
|
||||
language-settings)])
|
||||
(when (object-method-arity-includes? language 'update-test-setting 2)
|
||||
(let ((next-setting (drscheme:language-configuration:make-language-settings
|
||||
language
|
||||
(send language update-test-setting settings test?))))
|
||||
(preferences:set
|
||||
(drscheme:language-configuration:get-settings-preferences-symbol)
|
||||
next-setting)
|
||||
(send (get-defs) set-next-settings next-setting)))))
|
||||
|
||||
(define/augment (on-close)
|
||||
(when test-window
|
||||
(when (send test-window is-shown?)
|
||||
|
|
|
@ -179,9 +179,17 @@
|
|||
(define/public (default-settings)
|
||||
(if (memq level `(beginner intermediate advanced))
|
||||
(make-profj-settings 'field #f #t #t #t null)
|
||||
(make-profj-settings 'type #f #t #f #t null)))
|
||||
(make-profj-settings 'type #f #t #f #f null)))
|
||||
;default-settings? any -> bool
|
||||
(define/public (default-settings? s) (equal? s (default-settings)))
|
||||
|
||||
(define/public (update-test-setting s test?)
|
||||
(make-profj-settings (profj-settings-print-style s)
|
||||
(profj-settings-print-full? s)
|
||||
(profj-settings-allow-check? s)
|
||||
test?
|
||||
(profj-settings-coverage? s)
|
||||
(profj-settings-classpath s)))
|
||||
|
||||
;marshall-settings: profj-settings -> (list (list symbol) (list bool) (list string))
|
||||
(define/public (marshall-settings s)
|
||||
|
@ -200,8 +208,7 @@
|
|||
(pair? (cadddr s)) (= (length (cadddr s)) 1)
|
||||
(pair? (list-ref s 4)) (= (length (list-ref s 4)) 1))
|
||||
(make-profj-settings (caar s) (caadr s) (caaddr s)
|
||||
(get-preference 'profj:test-enable
|
||||
(lambda () (car (cadddr s))))
|
||||
(car (cadddr s))
|
||||
(car (list-ref s 4)) null)
|
||||
#f))
|
||||
|
||||
|
@ -248,8 +255,6 @@
|
|||
[update-at (lambda () (void))]
|
||||
[update-dt (lambda (box event)
|
||||
(when (eq? 'check-box (send event get-event-type))
|
||||
(put-preferences '(profj:test-enable)
|
||||
`(,(send box get-value)))
|
||||
(send collect-coverage enable (send box get-value))))]
|
||||
[update-cc (lambda () (void))]
|
||||
|
||||
|
@ -414,8 +419,7 @@
|
|||
(send print-full set-value (profj-settings-print-full? settings)))
|
||||
(when (eq? level 'full)
|
||||
(send allow-testing set-value (profj-settings-allow-check? settings)))
|
||||
(send display-testing set-value
|
||||
(get-preference 'profj:test-enable (lambda () (profj-settings-run-tests? settings))))
|
||||
(send display-testing set-value (profj-settings-run-tests? settings))
|
||||
(if (send display-testing get-value)
|
||||
(send collect-coverage set-value (profj-settings-coverage? settings))
|
||||
(send collect-coverage enable #f))
|
||||
|
@ -590,17 +594,13 @@
|
|||
[n (current-namespace)]
|
||||
[e (current-eventspace)])
|
||||
(test-ext? (profj-settings-allow-check? settings))
|
||||
(tests? (get-preference 'profj:test-enable
|
||||
(lambda () (profj-settings-run-tests? settings))))
|
||||
(coverage? (profj-settings-coverage? settings))
|
||||
(let ((execute-types (create-type-record)))
|
||||
(read-case-sensitive #t)
|
||||
(run-in-user-thread
|
||||
(lambda ()
|
||||
(test-ext? (profj-settings-allow-check? settings))
|
||||
(tests? (get-preference 'profj:test-enable
|
||||
(lambda () (profj-settings-run-tests? settings))))
|
||||
(coverage? (profj-settings-coverage? settings))
|
||||
(tests? (profj-settings-run-tests? settings))
|
||||
(coverage? (and (tests?) (profj-settings-coverage? settings)))
|
||||
(error-display-handler
|
||||
(drscheme:debug:make-debug-error-display-handler (error-display-handler)))
|
||||
(let ((old-current-eval (drscheme:debug:make-debug-eval-handler (current-eval))))
|
||||
|
|
|
@ -6,6 +6,17 @@
|
|||
|
||||
;;Execution tests without errors
|
||||
|
||||
(execute-test
|
||||
"class OneC { }
|
||||
class TwoC extends OneC { }
|
||||
class ThreeC extends TwoC { }
|
||||
class Overload {
|
||||
int num(OneC o) { return 1; }
|
||||
int num(TwoC o) { return 2; }
|
||||
int t() { return num(new ThreeC()); }
|
||||
}
|
||||
" 'advanced #f "Overloading resolution")
|
||||
|
||||
(execute-test
|
||||
"class Checkclass { }
|
||||
class ExampleCheck {
|
||||
|
@ -294,8 +305,12 @@ class WeeklyPlanner{
|
|||
|
||||
;;Interaction tests, mix of right and error
|
||||
|
||||
(interact-test 'advanced '("int a = 1;" "++a") '((void) 2) "Test of ++")
|
||||
(interact-test
|
||||
'advanced
|
||||
'("int a = 'a';" "a" "int b;" "b = 'a';")
|
||||
'((void) 97 (void) 97) "Conversion of char to int")
|
||||
|
||||
(interact-test 'advanced '("int a = 1;" "++a") '((void) 2) "Test of ++")
|
||||
|
||||
(interact-test
|
||||
'advanced
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
|
||||
(prepare-for-tests "Full")
|
||||
|
||||
(execute-test
|
||||
"class hasCharArray {
|
||||
char[] b = new char[]{'a'};
|
||||
}" 'full #f "Test of array alloc init")
|
||||
|
||||
(execute-test
|
||||
"class Aextendee {
|
||||
int f (Aextendee x) { return 4; }
|
||||
|
|
|
@ -21,6 +21,15 @@
|
|||
'intermediate
|
||||
#f "class implementing abstract class's unimplmenented interface")
|
||||
|
||||
(execute-test
|
||||
"interface ToImplement { int a(); }
|
||||
abstract class ToExtend implements ToImplement { int a() { return 2; } }
|
||||
class ToBe extends ToExtend implements ToImplement {
|
||||
}"
|
||||
'intermediate
|
||||
#f "Repetition of fully satisfied interface in class hierarchy")
|
||||
|
||||
|
||||
(execute-test
|
||||
"abstract class Foo {
|
||||
abstract int f();
|
||||
|
|
Loading…
Reference in New Issue
Block a user