Skip to content

Commit

Permalink
快照20
Browse files Browse the repository at this point in the history
  • Loading branch information
kangjianwei committed Dec 31, 2020
2 parents 31543e7 + 7d48471 commit 77f2cb1
Show file tree
Hide file tree
Showing 54 changed files with 29,671 additions and 19,126 deletions.
11 changes: 8 additions & 3 deletions src/java/lang/Enum.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ public final Class<E> getDeclaringClass() {
* same enum type. The natural order implemented by this
* method is the order in which the constants are declared.
*/
// 按自然顺序标胶枚举实例的值
// 比较枚举实例的值;声明靠前的枚举,其"值"较小
public final int compareTo(E o) {
Enum<?> other = (Enum<?>) o;
Enum<E> self = this;

if(self.getClass() != other.getClass() && // optimization
self.getDeclaringClass() != other.getDeclaringClass()) {
throw new ClassCastException();
Expand Down Expand Up @@ -224,10 +225,14 @@ public final int compareTo(E o) {
*/
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) {
T result = enumType.enumConstantDirectory().get(name);
if(result != null)

if(result != null) {
return result;
if(name == null)
}

if(name == null) {
throw new NullPointerException("Name is null");
}
throw new IllegalArgumentException("No enum constant " + enumType.getCanonicalName() + "." + name);
}

Expand Down
38 changes: 35 additions & 3 deletions src/java/lang/Math.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ public static long multiplyHigh(long x, long y) {
}
}

/*
* 向下取整除法:
*
* 11/ 8 = 1.375 ==> 1
* -11/ 8 = -1.375 ==> -2
* 11/-8 = -1.375 ==> -2
* -11/-8 = 1.375 ==> 1
*/

/**
* Returns the largest (closest to positive infinity)
* {@code int} value that is less than or equal to the algebraic quotient.
Expand Down Expand Up @@ -416,7 +425,7 @@ public static long multiplyHigh(long x, long y) {
* @see #floor(double)
* @since 1.8
*/
// 除法,如果两数符号不同,则向下取整
// 向下取整除法
public static int floorDiv(int x, int y) {
int r = x / y;
// if the signs are different and modulo not zero, round down
Expand Down Expand Up @@ -453,7 +462,7 @@ public static int floorDiv(int x, int y) {
* @see #floor(double)
* @since 9
*/
// 除法,如果两数符号不同,则向下取整
// 向下取整除法
public static long floorDiv(long x, int y) {
return floorDiv(x, (long) y);
}
Expand Down Expand Up @@ -485,7 +494,7 @@ public static long floorDiv(long x, int y) {
* @see #floor(double)
* @since 1.8
*/
// 除法,如果两数符号不同,则向下取整
// 向下取整除法
public static long floorDiv(long x, long y) {
long r = x / y;
// if the signs are different and modulo not zero, round down
Expand All @@ -495,6 +504,29 @@ public static long floorDiv(long x, long y) {
return r;
}

/*
* 取模运算:
*
* 11 MOD 8 => 从0开始,顺时针前进11步,得到3
* -11 MOD 8 => 从0开始,逆时针前进11步,得到5
*
* 0
* 7 1
* 6 2
* 5 3
* 4
*
*
* 11 MOD -8 => 从0开始,顺时针前进11步,得到-5
* -11 MOD -5 => 从0开始,逆时针前进11步,得到-3
*
* 0
* -1 -7
* -2 -6
* -3 -5
* -4
*/

/**
* Returns the floor modulus of the {@code int} arguments.
* <p>
Expand Down
14 changes: 8 additions & 6 deletions src/java/lang/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@
*
* @since 1.0
*/
// System工具类
// 系统工具类
public final class System {

// @see #initPhase2()
/** @see #initPhase2() */
static ModuleLayer bootLayer;

// The security manager for the system. */
/** The security manager for the system. */
// 当前使用的安全管理器,默认为null
private static volatile SecurityManager security;

Expand Down Expand Up @@ -264,10 +264,8 @@ public static void setErr(PrintStream err) {

// 为字段System.in关联(初始化)标准输入流
private static native void setIn0(InputStream in);

// 为字段System.out关联(初始化)标准输出流
private static native void setOut0(PrintStream out);

// 为字段System.err关联(初始化)标准错误流
private static native void setErr0(PrintStream err);

Expand Down Expand Up @@ -863,7 +861,11 @@ public static String getenv(String name) {
*
* @see java.util.Date
*/
// 返回以毫秒为单位的当前时间,其表现为当前时间与GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数(具体粒度由底层操作系统决定)
/*
* 返回当前时间点与新纪元时间点之间的毫秒差值(具体粒度由底层操作系统决定)
*
* 新纪元时间点:UTC/GMT时间1970年1月1号0时0分0秒
*/
@HotSpotIntrinsicCandidate
public static native long currentTimeMillis();

Expand Down
Loading

0 comments on commit 77f2cb1

Please sign in to comment.