diff --git a/group13/2931408816/.gradle/3.1/taskArtifacts/cache.properties.lock b/group13/2931408816/.gradle/3.1/taskArtifacts/cache.properties.lock
index e526851619..3c3d84d35b 100644
Binary files a/group13/2931408816/.gradle/3.1/taskArtifacts/cache.properties.lock and b/group13/2931408816/.gradle/3.1/taskArtifacts/cache.properties.lock differ
diff --git a/group13/2931408816/.gradle/3.1/taskArtifacts/fileHashes.bin b/group13/2931408816/.gradle/3.1/taskArtifacts/fileHashes.bin
index df74348046..12cab10b96 100644
Binary files a/group13/2931408816/.gradle/3.1/taskArtifacts/fileHashes.bin and b/group13/2931408816/.gradle/3.1/taskArtifacts/fileHashes.bin differ
diff --git a/group13/2931408816/.gradle/3.1/taskArtifacts/fileSnapshots.bin b/group13/2931408816/.gradle/3.1/taskArtifacts/fileSnapshots.bin
index d65e698bbc..09cd2629f8 100644
Binary files a/group13/2931408816/.gradle/3.1/taskArtifacts/fileSnapshots.bin and b/group13/2931408816/.gradle/3.1/taskArtifacts/fileSnapshots.bin differ
diff --git a/group13/2931408816/.gradle/3.1/taskArtifacts/taskArtifacts.bin b/group13/2931408816/.gradle/3.1/taskArtifacts/taskArtifacts.bin
index 69a7010d72..3c70119c9f 100644
Binary files a/group13/2931408816/.gradle/3.1/taskArtifacts/taskArtifacts.bin and b/group13/2931408816/.gradle/3.1/taskArtifacts/taskArtifacts.bin differ
diff --git a/group13/2931408816/.idea/compiler.xml b/group13/2931408816/.idea/compiler.xml
index 3d1b215f42..602f0772b0 100644
--- a/group13/2931408816/.idea/compiler.xml
+++ b/group13/2931408816/.idea/compiler.xml
@@ -10,6 +10,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/group13/2931408816/.idea/gradle.xml b/group13/2931408816/.idea/gradle.xml
index 4a7350459a..246a806334 100644
--- a/group13/2931408816/.idea/gradle.xml
+++ b/group13/2931408816/.idea/gradle.xml
@@ -13,6 +13,8 @@
+
+
diff --git a/group13/2931408816/.idea/modules.xml b/group13/2931408816/.idea/modules.xml
index b8bbae7f40..762aea64c1 100644
--- a/group13/2931408816/.idea/modules.xml
+++ b/group13/2931408816/.idea/modules.xml
@@ -3,7 +3,7 @@
-
+
@@ -12,9 +12,16 @@
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/group13/2931408816/.idea/workspace.xml b/group13/2931408816/.idea/workspace.xml
index 5491e4d0a1..38a332457d 100644
--- a/group13/2931408816/.idea/workspace.xml
+++ b/group13/2931408816/.idea/workspace.xml
@@ -11,6 +11,10 @@
+
+
+
+
@@ -39,6 +43,9 @@
+
+
+
@@ -51,69 +58,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
+
+
+
+
+
@@ -123,8 +136,8 @@
@@ -357,6 +370,116 @@
+
+
+
+
+
+
+
+
+ Displays the components produced by project ':lesson4'. [incubating]<p><i>Task group: help<i>
+ Assembles and tests this project and all projects that depend on it.<p><i>Task group: build<i>
+ Displays the sub-projects of project ':lesson4'.<p><i>Task group: help<i>
+ Generates IDEA project files (IML, IPR, IWS)<p><i>Task group: IDE<i>
+ Assembles main classes.<p><i>Task group: build<i>
+ Displays all buildscript dependencies declared in project ':lesson4'.<p><i>Task group: help<i>
+ <i>Task group: other<i>
+ Assembles test classes.<p><i>Task group: build<i>
+ Generates Javadoc API documentation for the main source code.<p><i>Task group: documentation<i>
+ Assembles a jar archive containing the main classes.<p><i>Task group: build<i>
+ Displays the configuration model of project ':lesson4'. [incubating]<p><i>Task group: help<i>
+ <i>Task group: other<i>
+ Generates IDEA module files (IML)<p><i>Task group: other<i>
+ Processes main resources.<p><i>Task group: other<i>
+ Displays the tasks runnable from project ':lesson4'.<p><i>Task group: help<i>
+ Cleans IDEA project files (IML, IPR)<p><i>Task group: IDE<i>
+ <i>Task group: other<i>
+ Runs the unit tests.<p><i>Task group: verification<i>
+ Compiles main Java source.<p><i>Task group: other<i>
+ Compiles the source set 'test'.kotlin.<p><i>Task group: other<i>
+ Displays the insight into a specific dependency in project ':lesson4'.<p><i>Task group: help<i>
+ Runs all checks.<p><i>Task group: verification<i>
+ Assembles the outputs of this project.<p><i>Task group: build<i>
+ Deletes the build directory.<p><i>Task group: build<i>
+ Compiles test Java source.<p><i>Task group: other<i>
+ Displays all dependencies declared in project ':lesson4'.<p><i>Task group: help<i>
+ Processes test resources.<p><i>Task group: other<i>
+ Displays a help message.<p><i>Task group: help<i>
+ Compiles the source set 'main'.kotlin.<p><i>Task group: other<i>
+ Assembles and tests this project.<p><i>Task group: build<i>
+ Assembles and tests this project and all projects it depends on.<p><i>Task group: build<i>
+ Displays the properties of project ':lesson4'.<p><i>Task group: help<i>
+ Configuration for archive artifacts.
+ Dependencies for source set 'main'.
+ Compile classpath for source set 'main'.
+ Compile dependencies for source set 'main'.
+ Configuration for default artifacts.
+
+
+ Runtime dependencies for source set 'main'.
+ Dependencies for source set 'test'.
+ Compile classpath for source set 'test'.
+ Compile dependencies for source set 'test'.
+ Runtime dependencies for source set 'test'.
+
+
+
+
+
+
+
+
+
+
+
+ Displays the components produced by project ':lesson5'. [incubating]<p><i>Task group: help<i>
+ Assembles and tests this project and all projects that depend on it.<p><i>Task group: build<i>
+ Displays the sub-projects of project ':lesson5'.<p><i>Task group: help<i>
+ Generates IDEA project files (IML, IPR, IWS)<p><i>Task group: IDE<i>
+ Assembles main classes.<p><i>Task group: build<i>
+ Displays all buildscript dependencies declared in project ':lesson5'.<p><i>Task group: help<i>
+ <i>Task group: other<i>
+ Assembles test classes.<p><i>Task group: build<i>
+ Generates Javadoc API documentation for the main source code.<p><i>Task group: documentation<i>
+ Assembles a jar archive containing the main classes.<p><i>Task group: build<i>
+ Displays the configuration model of project ':lesson5'. [incubating]<p><i>Task group: help<i>
+ <i>Task group: other<i>
+ Generates IDEA module files (IML)<p><i>Task group: other<i>
+ Processes main resources.<p><i>Task group: other<i>
+ Displays the tasks runnable from project ':lesson5'.<p><i>Task group: help<i>
+ Cleans IDEA project files (IML, IPR)<p><i>Task group: IDE<i>
+ <i>Task group: other<i>
+ Runs the unit tests.<p><i>Task group: verification<i>
+ Compiles main Java source.<p><i>Task group: other<i>
+ Compiles the source set 'test'.kotlin.<p><i>Task group: other<i>
+ Displays the insight into a specific dependency in project ':lesson5'.<p><i>Task group: help<i>
+ Runs all checks.<p><i>Task group: verification<i>
+ Assembles the outputs of this project.<p><i>Task group: build<i>
+ Deletes the build directory.<p><i>Task group: build<i>
+ Compiles test Java source.<p><i>Task group: other<i>
+ Displays all dependencies declared in project ':lesson5'.<p><i>Task group: help<i>
+ Processes test resources.<p><i>Task group: other<i>
+ Displays a help message.<p><i>Task group: help<i>
+ Compiles the source set 'main'.kotlin.<p><i>Task group: other<i>
+ Assembles and tests this project.<p><i>Task group: build<i>
+ Assembles and tests this project and all projects it depends on.<p><i>Task group: build<i>
+ Displays the properties of project ':lesson5'.<p><i>Task group: help<i>
+ Configuration for archive artifacts.
+ Dependencies for source set 'main'.
+ Compile classpath for source set 'main'.
+ Compile dependencies for source set 'main'.
+ Configuration for default artifacts.
+
+
+ Runtime dependencies for source set 'main'.
+ Dependencies for source set 'test'.
+ Compile classpath for source set 'test'.
+ Compile dependencies for source set 'test'.
+ Runtime dependencies for source set 'test'.
+
+
+
@@ -382,6 +505,14 @@
+
+
+
+
+
+
+
+
@@ -991,95 +1122,385 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
+
-
-
-
-
+
+
+
+
-
+
@@ -1678,23 +1994,23 @@
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
+
@@ -1704,14 +2020,14 @@
-
+
-
+
-
+
@@ -1720,10 +2036,28 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1733,7 +2067,7 @@
-
+
@@ -2150,19 +2484,19 @@
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
@@ -2185,43 +2519,52 @@
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
@@ -2234,32 +2577,31 @@
-
-
+
-
+
-
+
-
+
-
+
-
+
@@ -2289,10 +2631,32 @@
+
+ file://$PROJECT_DIR$/lesson5/src/main/java/com/coding/basic/stack/StackUtil.java
+ 131
+
+
+
+
+ file://$PROJECT_DIR$/lesson5/build/classes/main/com/coderising/jvm/clz/AccessFlag.class
+ 1
+
+
+
+
+ file://$PROJECT_DIR$/lesson5/src/main/java/com/coderising/jvm/loader/ClassFileParser.java
+ 49
+
+
+
-
+
-
+
+
+
+
+
@@ -2301,393 +2665,354 @@
-
-
-
+
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
-
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
+
+
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
-
+
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
+
+
-
-
+
-
-
-
+
+
+
+
+
-
+
-
-
+
+
-
-
+
-
-
+
+
-
+
-
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
-
+
-
+
-
-
-
-
-
-
-
-
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
-
+
+
+
+
+
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/BinaryTreeNode.java b/group13/2931408816/lesson4/src/main/java/com/coding/basic/BinaryTreeNode.java~CoderXLoong_master
similarity index 100%
rename from group13/2931408816/lesson4/src/main/java/com/coding/basic/BinaryTreeNode.java
rename to group13/2931408816/lesson4/src/main/java/com/coding/basic/BinaryTreeNode.java~CoderXLoong_master
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/BinaryTreeNode.java~HEAD b/group13/2931408816/lesson4/src/main/java/com/coding/basic/BinaryTreeNode.java~HEAD
new file mode 100644
index 0000000000..d7ac820192
--- /dev/null
+++ b/group13/2931408816/lesson4/src/main/java/com/coding/basic/BinaryTreeNode.java~HEAD
@@ -0,0 +1,32 @@
+package com.coding.basic;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public Object getData() {
+ return data;
+ }
+ public void setData(Object data) {
+ this.data = data;
+ }
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ public BinaryTreeNode insert(Object o){
+ return null;
+ }
+
+}
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/Iterator.java b/group13/2931408816/lesson4/src/main/java/com/coding/basic/Iterator.java~CoderXLoong_master
similarity index 100%
rename from group13/2931408816/lesson4/src/main/java/com/coding/basic/Iterator.java
rename to group13/2931408816/lesson4/src/main/java/com/coding/basic/Iterator.java~CoderXLoong_master
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/Iterator.java~HEAD b/group13/2931408816/lesson4/src/main/java/com/coding/basic/Iterator.java~HEAD
new file mode 100644
index 0000000000..06ef6311b2
--- /dev/null
+++ b/group13/2931408816/lesson4/src/main/java/com/coding/basic/Iterator.java~HEAD
@@ -0,0 +1,7 @@
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/List.java b/group13/2931408816/lesson4/src/main/java/com/coding/basic/List.java~CoderXLoong_master
similarity index 100%
rename from group13/2931408816/lesson4/src/main/java/com/coding/basic/List.java
rename to group13/2931408816/lesson4/src/main/java/com/coding/basic/List.java~CoderXLoong_master
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/List.java~HEAD b/group13/2931408816/lesson4/src/main/java/com/coding/basic/List.java~HEAD
new file mode 100644
index 0000000000..10d13b5832
--- /dev/null
+++ b/group13/2931408816/lesson4/src/main/java/com/coding/basic/List.java~HEAD
@@ -0,0 +1,9 @@
+package com.coding.basic;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/Stack.java b/group13/2931408816/lesson4/src/main/java/com/coding/basic/Stack.java~CoderXLoong_master
similarity index 100%
rename from group13/2931408816/lesson4/src/main/java/com/coding/basic/Stack.java
rename to group13/2931408816/lesson4/src/main/java/com/coding/basic/Stack.java~CoderXLoong_master
diff --git a/group13/2931408816/lesson4/src/main/java/com/coding/basic/Stack.java~HEAD b/group13/2931408816/lesson4/src/main/java/com/coding/basic/Stack.java~HEAD
new file mode 100644
index 0000000000..459ec560b4
--- /dev/null
+++ b/group13/2931408816/lesson4/src/main/java/com/coding/basic/Stack.java~HEAD
@@ -0,0 +1,24 @@
+package com.coding.basic;
+
+import com.coding.basic.array.ArrayList;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ }
+
+ public Object pop(){
+ return null;
+ }
+
+ public Object peek(){
+ return null;
+ }
+ public boolean isEmpty(){
+ return false;
+ }
+ public int size(){
+ return -1;
+ }
+}
diff --git a/group13/2931408816/lesson5/build.gradle b/group13/2931408816/lesson5/build.gradle
new file mode 100644
index 0000000000..3d1b2e47df
--- /dev/null
+++ b/group13/2931408816/lesson5/build.gradle
@@ -0,0 +1,31 @@
+
+buildscript {
+ ext.kotlin_version = '1.1.1'
+
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
+}
+
+apply plugin: 'java'
+apply plugin: 'kotlin'
+
+sourceCompatibility = 1.8
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
+ // https://mvnrepository.com/artifact/commons-io/commons-io
+ compile group: 'commons-io', name: 'commons-io', version: '2.5'
+
+ // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
+ compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
+
+ testCompile group: 'junit', name: 'junit', version: '4.12'
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/AccessFlag.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/AccessFlag.java
new file mode 100644
index 0000000000..faae056835
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/AccessFlag.java
@@ -0,0 +1,25 @@
+package com.coderising.jvm.clz;
+
+public class AccessFlag {
+ private int flagValue;
+
+ public AccessFlag(int value) {
+ this.flagValue = value;
+ }
+
+ public int getFlagValue() {
+ return flagValue;
+ }
+
+ public void setFlagValue(int flag) {
+ this.flagValue = flag;
+ }
+
+ public boolean isPublicClass(){
+ return (this.flagValue & 0x0001) != 0;
+ }
+ public boolean isFinalClass(){
+ return (this.flagValue & 0x0010) != 0;
+ }
+
+}
\ No newline at end of file
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/ClassFile.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/ClassFile.java
new file mode 100644
index 0000000000..650ca8375d
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/ClassFile.java
@@ -0,0 +1,75 @@
+package com.coderising.jvm.clz;
+
+import com.coderising.jvm.constant.ClassInfo;
+import com.coderising.jvm.constant.ConstantPool;
+
+public class ClassFile {
+
+ private int minorVersion;
+ private int majorVersion;
+
+ private AccessFlag accessFlag;
+ private ClassIndex clzIndex;
+ private ConstantPool pool;
+
+
+ public ClassIndex getClzIndex() {
+ return clzIndex;
+ }
+ public AccessFlag getAccessFlag() {
+ return accessFlag;
+ }
+ public void setAccessFlag(AccessFlag accessFlag) {
+ this.accessFlag = accessFlag;
+ }
+
+
+
+ public ConstantPool getConstantPool() {
+ return pool;
+ }
+ public int getMinorVersion() {
+ return minorVersion;
+ }
+ public void setMinorVersion(int minorVersion) {
+ this.minorVersion = minorVersion;
+ }
+ public int getMajorVersion() {
+ return majorVersion;
+ }
+ public void setMajorVersion(int majorVersion) {
+ this.majorVersion = majorVersion;
+ }
+ public void setConstPool(ConstantPool pool) {
+ this.pool = pool;
+
+ }
+ public void setClassIndex(ClassIndex clzIndex) {
+ this.clzIndex = clzIndex;
+ }
+
+
+
+
+ public void print(){
+
+ if(this.accessFlag.isPublicClass()){
+ System.out.println("Access flag : public ");
+ }
+ System.out.println("Class Name:"+ getClassName());
+
+ System.out.println("Super Class Name:"+ getSuperClassName());
+
+
+ }
+
+ private String getClassName(){
+ int thisClassIndex = this.clzIndex.getThisClassIndex();
+ ClassInfo thisClass = (ClassInfo)this.getConstantPool().getConstantInfo(thisClassIndex);
+ return thisClass.getClassName();
+ }
+ private String getSuperClassName(){
+ ClassInfo superClass = (ClassInfo)this.getConstantPool().getConstantInfo(this.clzIndex.getSuperClassIndex());
+ return superClass.getClassName();
+ }
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/ClassIndex.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/ClassIndex.java
new file mode 100644
index 0000000000..e424f284b3
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/clz/ClassIndex.java
@@ -0,0 +1,19 @@
+package com.coderising.jvm.clz;
+
+public class ClassIndex {
+ private int thisClassIndex;
+ private int superClassIndex;
+
+ public int getThisClassIndex() {
+ return thisClassIndex;
+ }
+ public void setThisClassIndex(int thisClassIndex) {
+ this.thisClassIndex = thisClassIndex;
+ }
+ public int getSuperClassIndex() {
+ return superClassIndex;
+ }
+ public void setSuperClassIndex(int superClassIndex) {
+ this.superClassIndex = superClassIndex;
+ }
+}
\ No newline at end of file
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ClassInfo.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ClassInfo.java
new file mode 100644
index 0000000000..aea9048ea4
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ClassInfo.java
@@ -0,0 +1,24 @@
+package com.coderising.jvm.constant;
+
+public class ClassInfo extends ConstantInfo {
+ private int type = ConstantInfo.CLASS_INFO;
+ private int utf8Index ;
+ public ClassInfo(ConstantPool pool) {
+ super(pool);
+ }
+ public int getUtf8Index() {
+ return utf8Index;
+ }
+ public void setUtf8Index(int utf8Index) {
+ this.utf8Index = utf8Index;
+ }
+ public int getType() {
+ return type;
+ }
+
+ public String getClassName() {
+ int index = getUtf8Index();
+ UTF8Info utf8Info = (UTF8Info)constantPool.getConstantInfo(index);
+ return utf8Info.getValue();
+ }
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ConstantInfo.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ConstantInfo.java
new file mode 100644
index 0000000000..466b072244
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ConstantInfo.java
@@ -0,0 +1,29 @@
+package com.coderising.jvm.constant;
+
+public abstract class ConstantInfo {
+ public static final int UTF8_INFO = 1;
+ public static final int FLOAT_INFO = 4;
+ public static final int CLASS_INFO = 7;
+ public static final int STRING_INFO = 8;
+ public static final int FIELD_INFO = 9;
+ public static final int METHOD_INFO = 10;
+ public static final int NAME_AND_TYPE_INFO = 12;
+ protected ConstantPool constantPool;
+
+ public ConstantInfo(){
+
+ }
+
+ public ConstantInfo(ConstantPool pool) {
+ this.constantPool = pool;
+ }
+ public abstract int getType();
+
+ public ConstantPool getConstantPool() {
+ return constantPool;
+ }
+ public ConstantInfo getConstantInfo(int index){
+ return this.constantPool.getConstantInfo(index);
+ }
+
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ConstantPool.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ConstantPool.java
new file mode 100644
index 0000000000..86c0445695
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/ConstantPool.java
@@ -0,0 +1,29 @@
+package com.coderising.jvm.constant;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ConstantPool {
+
+ private List constantInfos = new ArrayList();
+
+
+ public ConstantPool(){
+
+ }
+ public void addConstantInfo(ConstantInfo info){
+
+ this.constantInfos.add(info);
+
+ }
+
+ public ConstantInfo getConstantInfo(int index){
+ return this.constantInfos.get(index);
+ }
+ public String getUTF8String(int index){
+ return ((UTF8Info)this.constantInfos.get(index)).getValue();
+ }
+ public Object getSize() {
+ return this.constantInfos.size() -1;
+ }
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/FieldRefInfo.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/FieldRefInfo.java
new file mode 100644
index 0000000000..65475e194c
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/FieldRefInfo.java
@@ -0,0 +1,54 @@
+package com.coderising.jvm.constant;
+
+public class FieldRefInfo extends ConstantInfo{
+ private int type = ConstantInfo.FIELD_INFO;
+ private int classInfoIndex;
+ private int nameAndTypeIndex;
+
+ public FieldRefInfo(ConstantPool pool) {
+ super(pool);
+ }
+ public int getType() {
+ return type;
+ }
+
+ public int getClassInfoIndex() {
+ return classInfoIndex;
+ }
+ public void setClassInfoIndex(int classInfoIndex) {
+ this.classInfoIndex = classInfoIndex;
+ }
+ public int getNameAndTypeIndex() {
+ return nameAndTypeIndex;
+ }
+ public void setNameAndTypeIndex(int nameAndTypeIndex) {
+ this.nameAndTypeIndex = nameAndTypeIndex;
+ }
+
+ public String toString(){
+
+ NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex());
+
+ return getClassName() +" : "+ typeInfo.getName() + ":" + typeInfo.getTypeInfo() +"]";
+ }
+
+ public String getClassName(){
+
+ ClassInfo classInfo = (ClassInfo) this.getConstantInfo(this.getClassInfoIndex());
+
+ UTF8Info utf8Info = (UTF8Info)this.getConstantInfo(classInfo.getUtf8Index());
+
+ return utf8Info.getValue();
+
+ }
+
+ public String getFieldName(){
+ NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex());
+ return typeInfo.getName();
+ }
+
+ public String getFieldType(){
+ NameAndTypeInfo typeInfo = (NameAndTypeInfo)this.getConstantInfo(this.getNameAndTypeIndex());
+ return typeInfo.getTypeInfo();
+ }
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/MethodRefInfo.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/MethodRefInfo.java
new file mode 100644
index 0000000000..7f05870020
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/MethodRefInfo.java
@@ -0,0 +1,55 @@
+package com.coderising.jvm.constant;
+
+public class MethodRefInfo extends ConstantInfo {
+
+ private int type = ConstantInfo.METHOD_INFO;
+
+ private int classInfoIndex;
+ private int nameAndTypeIndex;
+
+ public MethodRefInfo(ConstantPool pool) {
+ super(pool);
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public int getClassInfoIndex() {
+ return classInfoIndex;
+ }
+ public void setClassInfoIndex(int classInfoIndex) {
+ this.classInfoIndex = classInfoIndex;
+ }
+ public int getNameAndTypeIndex() {
+ return nameAndTypeIndex;
+ }
+ public void setNameAndTypeIndex(int nameAndTypeIndex) {
+ this.nameAndTypeIndex = nameAndTypeIndex;
+ }
+
+ public String toString(){
+
+ return getClassName() +" : "+ this.getMethodName() + " : " + this.getParamAndReturnType() ;
+ }
+ public String getClassName(){
+ ConstantPool pool = this.getConstantPool();
+ ClassInfo clzInfo = (ClassInfo)pool.getConstantInfo(this.getClassInfoIndex());
+ return clzInfo.getClassName();
+ }
+
+ public String getMethodName(){
+ ConstantPool pool = this.getConstantPool();
+ NameAndTypeInfo typeInfo = (NameAndTypeInfo)pool.getConstantInfo(this.getNameAndTypeIndex());
+ return typeInfo.getName();
+ }
+
+ public String getParamAndReturnType(){
+ ConstantPool pool = this.getConstantPool();
+ NameAndTypeInfo typeInfo = (NameAndTypeInfo)pool.getConstantInfo(this.getNameAndTypeIndex());
+ return typeInfo.getTypeInfo();
+ }
+
+
+
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/NameAndTypeInfo.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/NameAndTypeInfo.java
new file mode 100644
index 0000000000..402f9dec86
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/NameAndTypeInfo.java
@@ -0,0 +1,45 @@
+package com.coderising.jvm.constant;
+
+public class NameAndTypeInfo extends ConstantInfo{
+ public int type = ConstantInfo.NAME_AND_TYPE_INFO;
+
+ private int index1;
+ private int index2;
+
+ public NameAndTypeInfo(ConstantPool pool) {
+ super(pool);
+ }
+
+ public int getIndex1() {
+ return index1;
+ }
+ public void setIndex1(int index1) {
+ this.index1 = index1;
+ }
+ public int getIndex2() {
+ return index2;
+ }
+ public void setIndex2(int index2) {
+ this.index2 = index2;
+ }
+ public int getType() {
+ return type;
+ }
+
+
+ public String getName(){
+ ConstantPool pool = this.getConstantPool();
+ UTF8Info utf8Info1 = (UTF8Info)pool.getConstantInfo(index1);
+ return utf8Info1.getValue();
+ }
+
+ public String getTypeInfo(){
+ ConstantPool pool = this.getConstantPool();
+ UTF8Info utf8Info2 = (UTF8Info)pool.getConstantInfo(index2);
+ return utf8Info2.getValue();
+ }
+
+ public String toString(){
+ return "(" + getName() + "," + getTypeInfo()+")";
+ }
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/NullConstantInfo.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/NullConstantInfo.java
new file mode 100644
index 0000000000..936736016f
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/NullConstantInfo.java
@@ -0,0 +1,13 @@
+package com.coderising.jvm.constant;
+
+public class NullConstantInfo extends ConstantInfo {
+
+ public NullConstantInfo(){
+
+ }
+ @Override
+ public int getType() {
+ return -1;
+ }
+
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/StringInfo.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/StringInfo.java
new file mode 100644
index 0000000000..f1f8eb4ed4
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/StringInfo.java
@@ -0,0 +1,26 @@
+package com.coderising.jvm.constant;
+
+public class StringInfo extends ConstantInfo{
+ private int type = ConstantInfo.STRING_INFO;
+ private int index;
+ public StringInfo(ConstantPool pool) {
+ super(pool);
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+
+ public String toString(){
+ return this.getConstantPool().getUTF8String(index);
+ }
+
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/UTF8Info.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/UTF8Info.java
new file mode 100644
index 0000000000..5cac9f04f7
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/constant/UTF8Info.java
@@ -0,0 +1,32 @@
+package com.coderising.jvm.constant;
+
+public class UTF8Info extends ConstantInfo{
+ private int type = ConstantInfo.UTF8_INFO;
+ private int length ;
+ private String value;
+ public UTF8Info(ConstantPool pool) {
+ super(pool);
+ }
+ public int getLength() {
+ return length;
+ }
+ public void setLength(int length) {
+ this.length = length;
+ }
+ public int getType() {
+ return type;
+ }
+ @Override
+ public String toString() {
+ return "UTF8Info [type=" + type + ", length=" + length + ", value=" + value +")]";
+ }
+ public String getValue() {
+ return value;
+ }
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+
+
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/loader/ByteCodeIterator.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/loader/ByteCodeIterator.java
new file mode 100644
index 0000000000..cb50f5fa55
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/loader/ByteCodeIterator.java
@@ -0,0 +1,37 @@
+package com.coderising.jvm.loader;
+
+import com.coderising.jvm.util.Util;
+
+public class ByteCodeIterator {
+ private int pos = 0;
+ private byte[] code;
+
+ public ByteCodeIterator(byte[] code) {
+ this.code = code;
+ }
+
+ public String nextU4ToHexString(){
+ byte[] bytes=nextByte(4);
+ return Util.byteToHexString(bytes);
+ }
+ public int nextU2ToInt(){
+ byte[] bytes = nextByte(2);
+ return Util.byteToInt(bytes);
+ }
+ public int nextU1ToInt(){
+ byte[] bytes = nextByte(1);
+ return Util.byteToInt(bytes);
+ }
+ public String nextToString(int len){
+ byte[] bytes = nextByte(len);
+ return new String(bytes);
+ }
+ private byte[] nextByte(int len){
+ byte[] bytes = new byte[len];
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i]=code[pos+i];
+ }
+ pos+=len;
+ return bytes;
+ }
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java
new file mode 100644
index 0000000000..497e88e188
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/loader/ClassFileLoader.java
@@ -0,0 +1,140 @@
+package com.coderising.jvm.loader;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import com.coderising.jvm.clz.ClassFile;
+
+
+
+
+
+public class ClassFileLoader {
+
+ private List clzPaths = new ArrayList();
+
+ public byte[] readBinaryCode(String className) {
+
+ className = className.replace('.', File.separatorChar) +".class";
+
+ for(String path : this.clzPaths){
+
+ String clzFileName = path + File.separatorChar + className;
+ byte[] codes = loadClassFile(clzFileName);
+ if(codes != null){
+ return codes;
+ }
+ }
+
+ return null;
+
+
+
+ }
+
+ private byte[] loadClassFile(String clzFileName) {
+
+ File f = new File(clzFileName);
+
+ try {
+
+ return IOUtils.toByteArray(new FileInputStream(f));
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+
+
+ public void addClassPath(String path) {
+ if(this.clzPaths.contains(path)){
+ return;
+ }
+
+ this.clzPaths.add(path);
+
+ }
+
+
+
+ public String getClassPath(){
+ return StringUtils.join(this.clzPaths,";");
+ }
+
+ public ClassFile loadClass(String className) {
+ byte[] codes = this.readBinaryCode(className);
+ ClassFileParser parser = new ClassFileParser();
+ return parser.parse(codes);
+
+ }
+
+
+
+ // ------------------------------backup------------------------
+ public String getClassPath_V1(){
+
+ StringBuffer buffer = new StringBuffer();
+ for(int i=0;i":()V
+ #2 = Class #14 // com/coderising/jvm/test/Main
+ #3 = Class #15 // java/lang/Object
+ #4 = Utf8
+ #5 = Utf8 ()V
+ #6 = Utf8 Code
+ #7 = Utf8 LineNumberTable
+ #8 = Utf8 LocalVariableTable
+ #9 = Utf8 this
+ #10 = Utf8 Lcom/coderising/jvm/test/Main;
+ #11 = Utf8 SourceFile
+ #12 = Utf8 Main.java
+ #13 = NameAndType #4:#5 // "":()V
+ #14 = Utf8 com/coderising/jvm/test/Main
+ #15 = Utf8 java/lang/Object
+{
+ public com.coderising.jvm.test.Main();
+ descriptor: ()V
+ flags: ACC_PUBLIC
+ Code:
+ stack=1, locals=1, args_size=1
+ 0: aload_0
+ 1: invokespecial #1 // Method java/lang/Object."":()V
+ 4: return
+ LineNumberTable:
+ line 6: 0
+ LocalVariableTable:
+ Start Length Slot Name Signature
+ 0 5 0 this Lcom/coderising/jvm/test/Main;
+}
+SourceFile: "Main.java"
+ */
\ No newline at end of file
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/test/EmployeeV1.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/test/EmployeeV1.java
new file mode 100644
index 0000000000..12e3d7efdd
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/test/EmployeeV1.java
@@ -0,0 +1,28 @@
+package com.coderising.jvm.test;
+
+public class EmployeeV1 {
+
+
+ private String name;
+ private int age;
+
+ public EmployeeV1(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ public void setAge(int age){
+ this.age = age;
+ }
+ public void sayHello() {
+ System.out.println("Hello , this is class Employee ");
+ }
+ public static void main(String[] args){
+ EmployeeV1 p = new EmployeeV1("Andy",29);
+ p.sayHello();
+
+ }
+}
\ No newline at end of file
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/test/Main.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/test/Main.java
new file mode 100644
index 0000000000..45601d76ff
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/test/Main.java
@@ -0,0 +1,7 @@
+package com.coderising.jvm.test;
+
+/**
+ * Created by pikachu on 2017/4/9.
+ */
+public class Main {
+}
diff --git a/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/util/Util.java b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/util/Util.java
new file mode 100644
index 0000000000..0c4cc8c57c
--- /dev/null
+++ b/group13/2931408816/lesson5/src/main/java/com/coderising/jvm/util/Util.java
@@ -0,0 +1,24 @@
+package com.coderising.jvm.util;
+
+public class Util {
+ public static int byteToInt(byte[] codes){
+ String s1 = byteToHexString(codes);
+ return Integer.valueOf(s1, 16).intValue();
+ }
+
+
+
+ public static String byteToHexString(byte[] codes ){
+ StringBuffer buffer = new StringBuffer();
+ for(int i=0;i=0){
+ if(stringLeft.indexOf(ch)>=0){
+ stack.push(Character.valueOf(ch));
+ }else {
+ Character top = (Character) stack.peek();
+ switch (top){
+ case '{':
+ if (ch == '}'){
+ stack.pop();
+ }else {
+ return false;
+ }
+ break;
+ case '[':
+ if (ch==']'){
+ stack.pop();
+ }else {
+ return false;
+ }
+ break;
+ case '(':
+ if (ch==')'){
+ stack.pop();
+ }else {
+ return false;
+ }
+ break;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ public static void main(String[] args) {
+
+ Stack stack = new Stack();
+ for (int i = 0; i < 5; i++) {
+ stack.push(i+1);
+ }
+ StackUtil.reverse(stack);
+ }
+}
diff --git a/group13/2931408816/lesson5/src/test/java/com/coderising/jvm/loader/test/ClassFileloaderTest.java b/group13/2931408816/lesson5/src/test/java/com/coderising/jvm/loader/test/ClassFileloaderTest.java
new file mode 100644
index 0000000000..1c6c111f03
--- /dev/null
+++ b/group13/2931408816/lesson5/src/test/java/com/coderising/jvm/loader/test/ClassFileloaderTest.java
@@ -0,0 +1,197 @@
+package com.coderising.jvm.loader.test;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coderising.jvm.clz.ClassFile;
+import com.coderising.jvm.clz.ClassIndex;
+import com.coderising.jvm.constant.ClassInfo;
+import com.coderising.jvm.constant.ConstantPool;
+import com.coderising.jvm.constant.MethodRefInfo;
+import com.coderising.jvm.constant.NameAndTypeInfo;
+import com.coderising.jvm.constant.UTF8Info;
+import com.coderising.jvm.loader.ClassFileLoader;
+
+
+
+
+
+public class ClassFileloaderTest {
+
+ private static final String FULL_QUALIFIED_CLASS_NAME = "com/coderising/jvm/test/EmployeeV1";
+
+ static String path1 = "D:\\src\\java\\study\\coding2017\\group13\\2931408816\\lesson5\\build\\classes\\main";
+ static String path2 = "C:\temp";
+
+ static ClassFile clzFile = null;
+ static {
+ ClassFileLoader loader = new ClassFileLoader();
+ loader.addClassPath(path1);
+ String className = "com.coderising.jvm.test.EmployeeV1";
+
+ clzFile = loader.loadClass(className);
+// clzFile.print();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testClassPath(){
+
+ ClassFileLoader loader = new ClassFileLoader();
+ loader.addClassPath(path1);
+ loader.addClassPath(path2);
+
+ String clzPath = loader.getClassPath();
+
+ Assert.assertEquals(path1+";"+path2,clzPath);
+
+ }
+
+ @Test
+ public void testClassFileLength() {
+
+ ClassFileLoader loader = new ClassFileLoader();
+ loader.addClassPath(path1);
+
+ String className = "com.coderising.jvm.test.EmployeeV1";
+
+ byte[] byteCodes = loader.readBinaryCode(className);
+
+ // 注意:这个字节数可能和你的JVM版本有关系, 你可以看看编译好的类到底有多大
+ Assert.assertEquals(1056, byteCodes.length);
+
+ }
+
+
+ @Test
+ public void testMagicNumber(){
+ ClassFileLoader loader = new ClassFileLoader();
+ loader.addClassPath(path1);
+ String className = "com.coderising.jvm.test.EmployeeV1";
+ byte[] byteCodes = loader.readBinaryCode(className);
+ byte[] codes = new byte[]{byteCodes[0],byteCodes[1],byteCodes[2],byteCodes[3]};
+
+
+ String acctualValue = this.byteToHexString(codes);
+
+ Assert.assertEquals("cafebabe", acctualValue);
+ }
+
+
+
+ private String byteToHexString(byte[] codes ){
+ StringBuffer buffer = new StringBuffer();
+ for(int i=0;i", utf8Info.getValue());
+
+ utf8Info = (UTF8Info) pool.getConstantInfo(10);
+ Assert.assertEquals("(Ljava/lang/String;I)V", utf8Info.getValue());
+
+ utf8Info = (UTF8Info) pool.getConstantInfo(11);
+ Assert.assertEquals("Code", utf8Info.getValue());
+ }
+
+ {
+ MethodRefInfo methodRef = (MethodRefInfo)pool.getConstantInfo(12);
+ Assert.assertEquals(3, methodRef.getClassInfoIndex());
+ Assert.assertEquals(13, methodRef.getNameAndTypeIndex());
+ }
+
+ {
+ NameAndTypeInfo nameAndType = (NameAndTypeInfo) pool.getConstantInfo(13);
+ Assert.assertEquals(9, nameAndType.getIndex1());
+ Assert.assertEquals(14, nameAndType.getIndex2());
+ }
+ //抽查几个吧
+ {
+ MethodRefInfo methodRef = (MethodRefInfo)pool.getConstantInfo(45);
+ Assert.assertEquals(1, methodRef.getClassInfoIndex());
+ Assert.assertEquals(46, methodRef.getNameAndTypeIndex());
+ }
+
+ {
+ UTF8Info utf8Info = (UTF8Info) pool.getConstantInfo(53);
+ Assert.assertEquals("EmployeeV1.java", utf8Info.getValue());
+ }
+ }
+ @Test
+ public void testClassIndex(){
+
+ ClassIndex clzIndex = clzFile.getClzIndex();
+ ClassInfo thisClassInfo = (ClassInfo)clzFile.getConstantPool().getConstantInfo(clzIndex.getThisClassIndex());
+ ClassInfo superClassInfo = (ClassInfo)clzFile.getConstantPool().getConstantInfo(clzIndex.getSuperClassIndex());
+
+
+ Assert.assertEquals(FULL_QUALIFIED_CLASS_NAME, thisClassInfo.getClassName());
+ Assert.assertEquals("java/lang/Object", superClassInfo.getClassName());
+ }
+}
diff --git a/group13/2931408816/lesson5/src/test/java/com/coding/basic/stack/StackUtilTest.java b/group13/2931408816/lesson5/src/test/java/com/coding/basic/stack/StackUtilTest.java
new file mode 100644
index 0000000000..b39281b245
--- /dev/null
+++ b/group13/2931408816/lesson5/src/test/java/com/coding/basic/stack/StackUtilTest.java
@@ -0,0 +1,61 @@
+package com.coding.basic.stack;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+
+/**
+ * Created by pikachu on 2017/4/7.
+ */
+public class StackUtilTest {
+ // public static void reverse(Stack s)
+ @Test
+ public void testReverse(){
+ Stack stack = new Stack();
+ for (int i = 0; i < 5; i++) {
+ stack.push(i+1);
+ }
+ Assert.assertEquals("[1, 2, 3, 4, 5]",stack.toString());
+ StackUtil.reverse(stack);
+ Assert.assertEquals("[5, 4, 3, 2, 1]",stack.toString());
+ }
+ // public static void remove(Stack s,Object o)
+ @Test
+ public void testRemove(){
+ Stack stack = new Stack();
+ for (int i = 0; i < 6; i++) {
+ stack.push(i);
+ }
+ StackUtil.remove(stack,0);
+ Assert.assertEquals("[1, 2, 3, 4, 5]", stack.toString());
+
+ StackUtil.remove(stack,3);
+ Assert.assertEquals("[1, 2, 4, 5]", stack.toString());
+
+ StackUtil.remove(stack,5);
+ Assert.assertEquals("[1, 2, 4]", stack.toString());
+ }
+ // public static Object[] getTop(Stack s,int len)
+ @Test
+ public void testGetTop(){
+ Stack stack = new Stack();
+ for (int i = 0; i < 10; i++) {
+ stack.push(i);
+ }
+ Object[] objects = StackUtil.getTop(stack,2);
+ Assert.assertArrayEquals(new Object[]{9,8},objects);
+ }
+ // public static boolean isValidPairs(String s)
+
+ /**
+ *
+ * 例如s = "([e{d}f])" , 则该字符串中的括号是成对出现, 该方法返回true
+ * 如果 s = "([b{x]y})", 则该字符串中的括号不是成对出现的, 该方法返回false;
+ */
+ @Test
+ public void testIsValidPairs(){
+ Assert.assertTrue( StackUtil.isValidPairs("([e{d}f])"));
+ Assert.assertFalse(StackUtil.isValidPairs("([b{x]y})"));
+ }
+}
diff --git a/group13/2931408816/settings.gradle b/group13/2931408816/settings.gradle
index e28c5f17d9..639272767b 100644
--- a/group13/2931408816/settings.gradle
+++ b/group13/2931408816/settings.gradle
@@ -20,4 +20,5 @@ include 'lesson1'
include 'lesson2'
include 'lesson3'
include 'lesson4'
+include 'lesson5'
diff --git a/group13/2931408816/src/main/kotlin/main.kt b/group13/2931408816/src/main/kotlin/main.kt
new file mode 100644
index 0000000000..c3df289e2d
--- /dev/null
+++ b/group13/2931408816/src/main/kotlin/main.kt
@@ -0,0 +1,13 @@
+/**
+ * Created by pikachu on 2017/4/10.
+ */
+
+fun main(args: Array) {
+ (1..25).forEach {
+ if(it<10)
+ println("group0${it}/")
+ else{
+ println("group${it}/")
+ }
+ }
+}
\ No newline at end of file