From 24b1076e7ad80d6921ddc6d64256caadbbb6ec95 Mon Sep 17 00:00:00 2001 From: somersames Date: Sun, 13 May 2018 23:59:47 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Leetcode=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E9=81=93=E9=A2=98=E7=9B=AE=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=E6=9B=B4=E6=96=B0pom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 72 +++++++++++++++++++ .../ch2/echo/EchoClientHandle.java | 6 +- .../java/Thread/Bank/system/BankSystem.java | 2 +- .../java/Thread/Bank/system/InitBank.java | 2 +- src/main/java/operation/XORTest.java | 25 +++++++ src/main/java/reflec/aop/Before.java | 1 - 6 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/main/java/operation/XORTest.java diff --git a/pom.xml b/pom.xml index ecdcd4c..2dca08a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,78 @@ Javabasis Javabasis 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + io.netty + netty-all + 5.0.0.Alpha2 + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + RELEASE + + + + cglib + cglib + 3.2.5 + + + + org.springframework + spring-jdbc + 5.0.3.RELEASE + + + + com.alibaba + fastjson + 1.2.47 + + + + com.fasterxml.jackson.core + jackson-core + 2.9.4 + + + + com.fasterxml.jackson.core + jackson-databind + 2.9.4 + + + + org.javassist + javassist + 3.22.0-GA + + \ No newline at end of file diff --git a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java index 8eaf1f1..b751939 100644 --- a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java +++ b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java @@ -15,7 +15,6 @@ public class EchoClientHandle extends SimpleChannelInboundHandler{ public String Message; public static List list =new ArrayList<>(); - @Override protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); } @@ -36,4 +35,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception ByteBuf buf = (ByteBuf) msg; System.out.println("客端接受到的数据是" + buf.toString(CharsetUtil.UTF_8)); } + + @Override + protected void messageReceived(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { + + } } diff --git a/src/main/java/Thread/Bank/system/BankSystem.java b/src/main/java/Thread/Bank/system/BankSystem.java index b9345e7..4c31942 100644 --- a/src/main/java/Thread/Bank/system/BankSystem.java +++ b/src/main/java/Thread/Bank/system/BankSystem.java @@ -13,7 +13,7 @@ public void doSpend() { if (Store.queue.isEmpty()) { executor.shutdownNow(); } else { - executor.execute(new ServiceWindows(Store.queue.poll())); // 执行操作任务 +// executor.execute(new ServiceWindows(Store.queue.poll())); // 执行操作任务 } } } diff --git a/src/main/java/Thread/Bank/system/InitBank.java b/src/main/java/Thread/Bank/system/InitBank.java index 3ee7dc7..14a2e0b 100644 --- a/src/main/java/Thread/Bank/system/InitBank.java +++ b/src/main/java/Thread/Bank/system/InitBank.java @@ -30,7 +30,7 @@ private void init(){ while (!Store.queue.isEmpty()){ // System.out.println("队列是否为空+!"+!Store.queue.isEmpty()); // bankSystem.doSpend(); - this.executorService.execute(new ServiceWindows(Store.queue.poll())); +// this.executorService.execute(new ServiceWindows(Store.queue.poll())); } // System.out.println("已经执行到这里了"); diff --git a/src/main/java/operation/XORTest.java b/src/main/java/operation/XORTest.java new file mode 100644 index 0000000..5857ee1 --- /dev/null +++ b/src/main/java/operation/XORTest.java @@ -0,0 +1,25 @@ +package operation; + +import org.junit.Test; + +public class XORTest { + @Test + public void main1() { + char c1 ='a'; + char c2='b'; + System.out.println(c1 ^ c2); + } + public int numJewelsInStones(String J, String S) { + char[] c1= J.toCharArray(); + char[] c2 =S.toCharArray(); + int total=0; + for(int i =0 ;i Date: Thu, 24 May 2018 00:10:50 +0800 Subject: [PATCH 02/10] backup --- .../Maven__io_netty_netty_all_5_0_0_Alpha2.xml | 13 +++++++++++++ .idea/libraries/Maven__junit_junit_4_12.xml | 13 +++++++++++++ ...Maven__org_apiguardian_apiguardian_api_1_0_0.xml | 13 +++++++++++++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 +++++++++++++ src/main/java/reflec/aop/Before.java | 1 - 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .idea/libraries/Maven__io_netty_netty_all_5_0_0_Alpha2.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_12.xml create mode 100644 .idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml diff --git a/.idea/libraries/Maven__io_netty_netty_all_5_0_0_Alpha2.xml b/.idea/libraries/Maven__io_netty_netty_all_5_0_0_Alpha2.xml new file mode 100644 index 0000000..c7b9c5c --- /dev/null +++ b/.idea/libraries/Maven__io_netty_netty_all_5_0_0_Alpha2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml new file mode 100644 index 0000000..a82457d --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/reflec/aop/Before.java b/src/main/java/reflec/aop/Before.java index ee23659..fcf7e99 100644 --- a/src/main/java/reflec/aop/Before.java +++ b/src/main/java/reflec/aop/Before.java @@ -1,6 +1,5 @@ package reflec.aop; -import jodd.madvoc.meta.RenderWith; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; From d2107cca97acaaa7618b6a2249cd3063bb57a72e Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Thu, 24 May 2018 00:18:04 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=86=B2=E7=AA=81=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + .idea/compiler.xml | 24 +--- .idea/misc.xml | 31 +---- .idea/modules.xml | 2 +- pom.xml | 72 ++++++++++ src/main/java/Loop/Hello.asm | Bin 0 -> 164 bytes src/main/java/Loop/LoopTest.asm | Bin 0 -> 164 bytes src/main/java/Loop/LoopTest.class | Bin 0 -> 602 bytes src/main/java/Loop/LoopTest.java | 28 ++++ .../ch2/echo/EchoClientHandle.java | 13 +- src/main/java/T/T2.java | 112 +++++++++++++++ src/main/java/T/TestT.java | 47 +++++++ .../java/Thread/Bank/system/BankSystem.java | 3 +- .../java/Thread/Bank/system/InitBank.java | 3 +- .../java/Thread/elevator/EevatorControll.java | 2 - src/main/java/coracle/Data/AssertUtil.java | 72 ++++++++++ src/main/java/coracle/Data/CryptoSDK.java | 29 ++++ src/main/java/coracle/Data/CryptoType.java | 51 +++++++ src/main/java/coracle/Data/JunitData.java | 88 ++++++++++++ src/main/java/coracle/Data/JwtSDK.java | 89 ++++++++++++ src/main/java/coracle/Data/Md5Utils.java | 44 ++++++ src/main/java/coracle/Data/MgmConstant.java | 128 ++++++++++++++++++ src/main/java/httpgrab/Grab.java | 100 -------------- .../reflec/aop/Javasist/JavaisitSing.java | 13 ++ .../reflec/aop/Javasist/JavasistTest.java | 29 ++++ .../java/reflec/aop/Javasist/javasist.puml | 3 + .../java/reflec/aop/cglibtest/AOPSEQ.puml | 11 ++ .../java/reflec/aop/cglibtest/CGLIBProxy.java | 23 ---- .../java/reflec/aop/cglibtest/CglibTest.java | 2 +- .../java/reflec/aop/cglibtest/ProxyUtil.java | 21 +-- .../java/reflec/aop/cglibtest/Reflect.java | 11 -- src/main/java/reflec/aop/test/BeforeEat.java | 4 +- src/main/java/reflec/aop/test/Eat.java | 1 - 33 files changed, 845 insertions(+), 214 deletions(-) create mode 100644 .gitignore create mode 100644 src/main/java/Loop/Hello.asm create mode 100644 src/main/java/Loop/LoopTest.asm create mode 100644 src/main/java/Loop/LoopTest.class create mode 100644 src/main/java/Loop/LoopTest.java create mode 100644 src/main/java/T/T2.java create mode 100644 src/main/java/T/TestT.java create mode 100644 src/main/java/coracle/Data/AssertUtil.java create mode 100644 src/main/java/coracle/Data/CryptoSDK.java create mode 100644 src/main/java/coracle/Data/CryptoType.java create mode 100644 src/main/java/coracle/Data/JunitData.java create mode 100644 src/main/java/coracle/Data/JwtSDK.java create mode 100644 src/main/java/coracle/Data/Md5Utils.java create mode 100644 src/main/java/coracle/Data/MgmConstant.java create mode 100644 src/main/java/reflec/aop/Javasist/JavaisitSing.java create mode 100644 src/main/java/reflec/aop/Javasist/JavasistTest.java create mode 100644 src/main/java/reflec/aop/Javasist/javasist.puml create mode 100644 src/main/java/reflec/aop/cglibtest/AOPSEQ.puml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3425b85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/* +target/* +*.iml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fa609d6..1401148 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,32 +1,16 @@ - - - - - - - - - - - - - - - - + - - + - - + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index dfca8c4..5755a99 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + - - - - - 1.8 - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index fdedb92..452c3f5 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index ecdcd4c..3b43aed 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,78 @@ Javabasis Javabasis 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + io.netty + netty-all + 5.0.0.Alpha2 + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + RELEASE + + + + cglib + cglib + 3.2.5 + + + + org.springframework + spring-jdbc + 5.0.3.RELEASE + + + + com.alibaba + fastjson + 1.2.47 + + + + com.fasterxml.jackson.core + jackson-core + 2.9.4 + + + + com.fasterxml.jackson.core + jackson-databind + 2.9.4 + + + + org.javassist + javassist + 3.22.0-GA + + \ No newline at end of file diff --git a/src/main/java/Loop/Hello.asm b/src/main/java/Loop/Hello.asm new file mode 100644 index 0000000000000000000000000000000000000000..73feaf0a69bb84ada3f533284b1b7c925c8d80f9 GIT binary patch literal 164 zcmZvV%?dz36otRF@(%L?tYl*)FW?o3GBqf}!pq~##7?*Fxt*VT?yF(tz%gK0bnikZ z>>@Mag;qNgGwUuX$c0W*MX#l2le%&K{OF`Q#^`P3v1-|=_0fx+qZ)Fd!@ONzW*{Zu E0gEUeyZ`_I literal 0 HcmV?d00001 diff --git a/src/main/java/Loop/LoopTest.asm b/src/main/java/Loop/LoopTest.asm new file mode 100644 index 0000000000000000000000000000000000000000..73feaf0a69bb84ada3f533284b1b7c925c8d80f9 GIT binary patch literal 164 zcmZvV%?dz36otRF@(%L?tYl*)FW?o3GBqf}!pq~##7?*Fxt*VT?yF(tz%gK0bnikZ z>>@Mag;qNgGwUuX$c0W*MX#l2le%&K{OF`Q#^`P3v1-|=_0fx+qZ)Fd!@ONzW*{Zu E0gEUeyZ`_I literal 0 HcmV?d00001 diff --git a/src/main/java/Loop/LoopTest.class b/src/main/java/Loop/LoopTest.class new file mode 100644 index 0000000000000000000000000000000000000000..9c85b02cb136aebcf8306dad917e6f1524def805 GIT binary patch literal 602 zcmZ{h%TB^j5QhKL77kVru!tADCMF^#uyN;QV`5@NSzz3_u|PwLPzV;|1NbCtT)Wa3 zj|W@ z2gQbcVi%gWS1*+PuItrTl)G7O_qtVQ(^ZbKV!PehbB_JI(nb-6jKWkQ2Km`8d}#y{ z-;Sk9!>JNQJJ`Y;9~0sW!AufJ#t2VS%z`f^{Gtcv! zL!1?0!FYv~h>90P#51htK+b3WN1z7J5+ES?N$~hLK~nu*Zq6b>iUbx3hDk8`i$Ibf mr3eNH9RDO(Af{TEyn=QG{d-|U!D_}CC%C)}MG49@BtHO6bz-;x literal 0 HcmV?d00001 diff --git a/src/main/java/Loop/LoopTest.java b/src/main/java/Loop/LoopTest.java new file mode 100644 index 0000000..46d5f94 --- /dev/null +++ b/src/main/java/Loop/LoopTest.java @@ -0,0 +1,28 @@ +package Loop; + +/** + * @author szh + * @create 2018-05-21 20:31 + **/ +public class LoopTest { + private static void maxOut(){ + int[] a =new int[100]; + for(int i = 0; i<200 ;i++){ + for(int j=0;j<10;j++){ + a[i]=a[j]+1; + } + } + } + private static void minOut(){ + int[] a =new int[100]; + for(int i = 0; i<10 ;i++){ + for(int j=0;j<200;j++){ + a[i]=a[j]+1; + } + } + } + public static void main(String[] args){ + maxOut(); + minOut(); + } +} diff --git a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java index 8eaf1f1..7222931 100644 --- a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java +++ b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java @@ -15,10 +15,10 @@ public class EchoClientHandle extends SimpleChannelInboundHandler{ public String Message; public static List list =new ArrayList<>(); - @Override - protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { - System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); - } +// @Override +// protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { +// System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); +// } @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { // 这和方法是当连接成功之后的一个方法调用 @@ -36,4 +36,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception ByteBuf buf = (ByteBuf) msg; System.out.println("客端接受到的数据是" + buf.toString(CharsetUtil.UTF_8)); } + + @Override + protected void messageReceived(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { + System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); + } } diff --git a/src/main/java/T/T2.java b/src/main/java/T/T2.java new file mode 100644 index 0000000..b052a78 --- /dev/null +++ b/src/main/java/T/T2.java @@ -0,0 +1,112 @@ +package T; + +import org.junit.Test; + +import java.util.HashSet; +import java.util.Random; +import java.util.Set; +import java.util.UUID; + +/** + * c + * + * @author szh + * @create 2018-04-09 0:57 + **/ +public class T2 { +// @Test +// public void uniqueMorseRepresentations() { +// String[] words=new String[]{"gin", "zen", "gig", "msg"}; +// String[] s1 =new String[]{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; +// Set set =new HashSet<>(); +// for(int i =0 ;i=0 ;j--) +// if(array[j] > array[j+1]){ +// int temp =array[j+1]; +// array[j+1]=array[j]; +// array[j]=temp; +// } +// } +// for( int i :array){ +// System.out.println(i); +// } +// } +// @Test +// public void maopaoSortTest(){ +// int[] array =new int[]{2,4,5,7,1,3,6,8,9,0}; +// for(int i =0 ;iarray[j]){ +// int temp =array[j]; +// array[j]=array[i]; +// array[i]=temp; +// } +// } +// } +// for(int i : array){ +// System.out.println(i); +// } +// } +// +// @Test + public void quickSortTest(int[] array , int head ,int end ){ +// int[] array =new int[]{2,4,5,7,1,3,6,8,9,0}; + if(head >= end || array == null || array.length <1){ + return; + } + int i=head; + int j=end; + int mid =array[(head + end) /2]; + while(i <= j){ + while (array[i] < mid){ + i++; + } + while (array[j] > mid){ + j--; + } + if(i <= j){ + int temp =array[i]; + array[i] =array[j]; + array[j]=temp; + ++i; + --j; +// }else if(i == j){ +// ++i; + } + } + quickSortTest(array,head,j); + quickSortTest(array,i,end); + } + + public static void main(String[] args) { + int[] array =new int[]{2,4,5,7,1,3,6,8,9,0}; + new T2().quickSortTest(array,0,array.length-1); + for(int i :array){ + System.out.println(i); + } + } + @Test + public void te(){ + UUID uuid = UUID.randomUUID(); + System.out.println(uuid); + } + +} diff --git a/src/main/java/T/TestT.java b/src/main/java/T/TestT.java new file mode 100644 index 0000000..aea3352 --- /dev/null +++ b/src/main/java/T/TestT.java @@ -0,0 +1,47 @@ +package T; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * 测试泛型的一些例子 + * + * @author szh + * @create 2018-04-07 21:14 + **/ +public class TestT { + public static void main(String[] args) { + new TestT().selfDividingNumbers(1, 22); + } + + public List selfDividingNumbers(int left, int right) { + List list = new ArrayList<>(); + for (; left <= right; left++) { + int[] temp = StirngToIntaray(String.valueOf(left)); + boolean flag = true; + for (int i = 0; i < temp.length; i++) { + if (temp[i] == 0){ + continue; + } + if (left % temp[i] != 0) { + flag = false; + } + } + if (flag) { + list.add(left); + } + } + return list; + } + + public int[] StirngToIntaray(String s) { + int[] result = new int[s.length()]; + char[] c = s.toCharArray(); + for (int i = 0; i < s.length(); i++) { + result[i] = Integer.parseInt(Character.toString(c[i])); + } + return result; + } +} diff --git a/src/main/java/Thread/Bank/system/BankSystem.java b/src/main/java/Thread/Bank/system/BankSystem.java index b9345e7..acf44e4 100644 --- a/src/main/java/Thread/Bank/system/BankSystem.java +++ b/src/main/java/Thread/Bank/system/BankSystem.java @@ -13,7 +13,8 @@ public void doSpend() { if (Store.queue.isEmpty()) { executor.shutdownNow(); } else { - executor.execute(new ServiceWindows(Store.queue.poll())); // 执行操作任务 +// executor.execute(new ServiceWindows(Store.queue.poll())); // 执行操作任务 + executor.execute(new PopWindows()); // 执行操作任务 } } } diff --git a/src/main/java/Thread/Bank/system/InitBank.java b/src/main/java/Thread/Bank/system/InitBank.java index 3ee7dc7..a288e02 100644 --- a/src/main/java/Thread/Bank/system/InitBank.java +++ b/src/main/java/Thread/Bank/system/InitBank.java @@ -30,7 +30,8 @@ private void init(){ while (!Store.queue.isEmpty()){ // System.out.println("队列是否为空+!"+!Store.queue.isEmpty()); // bankSystem.doSpend(); - this.executorService.execute(new ServiceWindows(Store.queue.poll())); +// this.executorService.execute(new ServiceWindows(Store.queue.poll())); + this.executorService.execute(new PopWindows()); } // System.out.println("已经执行到这里了"); diff --git a/src/main/java/Thread/elevator/EevatorControll.java b/src/main/java/Thread/elevator/EevatorControll.java index 26ce6e9..fc8e4a7 100644 --- a/src/main/java/Thread/elevator/EevatorControll.java +++ b/src/main/java/Thread/elevator/EevatorControll.java @@ -1,7 +1,5 @@ package Thread.elevator; -import org.junit.Test; - import java.util.ArrayList; import java.util.List; import java.util.Scanner; diff --git a/src/main/java/coracle/Data/AssertUtil.java b/src/main/java/coracle/Data/AssertUtil.java new file mode 100644 index 0000000..4819113 --- /dev/null +++ b/src/main/java/coracle/Data/AssertUtil.java @@ -0,0 +1,72 @@ +package coracle.Data; + +/** + * 断言工具类,不符合断言时抛出IllegalArgumentException + * + * @author Tung + * @version 1.0 + * @date 2017/6/24. + * @update + */ + +public class AssertUtil { + + public static void hasLength(String text, String message) { + + if (!hasLength(text)) { + throw new IllegalArgumentException(message); + } + } + + public static boolean hasLength(String str) { + + return hasLength((CharSequence) str); + } + + public static boolean hasLength(CharSequence str) { + + return (str != null && str.length() > 0); + } + + /** + * 当传入字符串为null, empty或者blank时,抛出IllegalArgumentException。 + * + * @param str + * @param msg + */ + public static void hasText(String str, String msg) { + + hasText((CharSequence) str, msg); + } + + /** + * 当传入字符序列为null, empty或者blank时,抛出IllegalArgumentException。 + * + * @param str + * @param msg + */ + public static void hasText(CharSequence str, String msg) { + + if ((str != null && str.length() > 0)) { + int strLen = str.length(); + for (int i = 0; i < strLen; i++) { + if (!Character.isWhitespace(str.charAt(i))) { + return; + } + } + } + throw new IllegalArgumentException(msg); + } + + /** + * 当传入的对象为null时,抛出IllegalArgumentException。 + * @param obj + * @param msg + */ + public static void notNull(Object obj, String msg) { + + if (obj == null) { + throw new IllegalArgumentException(msg); + } + } +} diff --git a/src/main/java/coracle/Data/CryptoSDK.java b/src/main/java/coracle/Data/CryptoSDK.java new file mode 100644 index 0000000..eedbe14 --- /dev/null +++ b/src/main/java/coracle/Data/CryptoSDK.java @@ -0,0 +1,29 @@ +package coracle.Data; + +import coracle.Data.CryptoType; +import org.coracle.xsimple.common.codec.CoracleCoder; + +/** + * TODO Fill The Description! + * + * @author Tung + * @version 1.0 + * @date 2017/7/5. + * @update + */ +public class CryptoSDK { + + public static String withAaemEncrypt(String src) { + + return CoracleCoder.enc(src, CryptoType.AEM.name()); + } + + public static String withAemDecrypt(String src) { + return CoracleCoder.dec(src, CryptoType.AEM.name()); + } + + public static void main(String[] args) { + System.out.println(withAaemEncrypt("false")); +// System.out.println(withAemDecrypt("70IcNz9zTl+3rSGw6LCdrw==")); + } +} diff --git a/src/main/java/coracle/Data/CryptoType.java b/src/main/java/coracle/Data/CryptoType.java new file mode 100644 index 0000000..7744104 --- /dev/null +++ b/src/main/java/coracle/Data/CryptoType.java @@ -0,0 +1,51 @@ +package coracle.Data; + +import java.util.HashMap; +import java.util.Map; + +/** + * TODO Fill The Description! + * + * @author Tung + * @version 1.0 + * @date 2017/7/5. + * @update + */ + +public enum CryptoType { + /** + * 不加密 + */ + NONE("NONE"), + + + AEM("AEM"); + // , REM("REM"), DEM("DEM"), RSA("RSA"); //暂不支持 + + + private static final Map mappings = new HashMap<>(4); + + static { + for (CryptoType cryptoType : values()) { + mappings.put(cryptoType.name(), cryptoType); + } + } + + private String mode; + CryptoType(String mode) { + this.mode = mode; + } + + public static CryptoType resolve(String mode) { + return (mode != null ? mappings.get(mode) : NONE); + } + + public boolean matches(String mode) { + return (this == resolve(mode)); + } + + @Override + public String toString() { + return this.name(); + } +} diff --git a/src/main/java/coracle/Data/JunitData.java b/src/main/java/coracle/Data/JunitData.java new file mode 100644 index 0000000..5eeeb25 --- /dev/null +++ b/src/main/java/coracle/Data/JunitData.java @@ -0,0 +1,88 @@ +package coracle.Data; + +import com.alibaba.fastjson.JSON; +import okhttp3.*; +import org.junit.Test; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; + +/** + * 对Coracle的api进行测试 + * + * @author szh + * @create 2018-03-27 15:17 + **/ +public class JunitData { + public static final MediaType JSONMe = MediaType.parse("application/json; charset=utf-8"); + + @Test + public void uu(){ + Date now = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式 + java.util.Calendar Cal=java.util.Calendar.getInstance(); + Cal.setTime(now); + Cal.add(Calendar.MINUTE,30); + System.out.println("date:"+dateFormat.format(Cal.getTime())); + } + + + + @Test + public void sendData() throws IOException { + OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build(); + Map map = new HashMap(); + map.put("user", "zhouhaoxiang"); + map.put("password", "8GTxy9iTj49asNhe0Gqamw=="); + map.put("remember", "true"); + String url = "http://172.16.23.169:8080/mchl/v3/agent/public/api/login"; + String json = JSON.toJSONString(map); + RequestBody body = RequestBody.create(JSONMe, json); + + Request request = new Request.Builder() + .url(url) + .header("X-xSimple-appKey", "8b73e4ee-696c-4c8c-aabd-0c893ba82e73") + .post(body) + .build(); + Response response = okHttpClient.newCall(request).execute(); + System.out.println(response.body().string()); + } + + @Test + public void getData() throws IOException { + + OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build(); + Map map = new HashMap(); + String url = "http://172.16.23.169:8080/mchl/v3/agent/bu"; + + RequestBody body = RequestBody.create(JSONMe, ""); + + String agent ="x_apiKey=serverInfo&x_buKey=mxm&x_method=POST&x_EM=AEM&x_isSign=true"; + String appkey=JwtSDK.calSecretKey("8b73e4ee-696c-4c8c-aabd-0c893ba82e73"); + System.out.println(appkey); + String result=JwtSDK.createJWT(appkey,agent); + System.out.println(result); + + Request request = new Request.Builder() + .url(url) + .header("X-Authorization", "eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoie1widXNlcm5hbWVcIjpcInpob3VoYW94aWFuZ1wifSJ9.9qnhk1ioN2z4BBDe1l5dpsyy594KGq0j8hBHHEnNn0w") + .header("X-xSimple-debug", "false") //加密需要转成false + .header("X-xSimple-appKey", "8b73e4ee-696c-4c8c-aabd-0c893ba82e73") +// .header("X-xSimple-agent", "x_apiKey=serverInfo&x_buKey=mxm&x_method=POST&x_EM=NONE&x_isSign=false")// jwt签名 + .header("X-xSimple-agent", result)// jwt签名 AEM + +// .header("X-xSimple-agent", "x_apiKey=serverInfo&x_buKey=mxm&x_method=POST")// 未加密 + .header("X-xSimple-IMEI","5498313987f90080d23805082da531ec1b11f895") + .post(body) // AEM + .build(); + + Response response = okHttpClient.newCall(request).execute(); +// System.out.println(response.body().string()); + System.out.println(CryptoSDK.withAemDecrypt(response.body().string())); + } +} diff --git a/src/main/java/coracle/Data/JwtSDK.java b/src/main/java/coracle/Data/JwtSDK.java new file mode 100644 index 0000000..13d55de --- /dev/null +++ b/src/main/java/coracle/Data/JwtSDK.java @@ -0,0 +1,89 @@ +package coracle.Data; + +import coracle.Data.Md5Utils; +import coracle.Data.AssertUtil; +import io.jsonwebtoken.*; +import io.jsonwebtoken.impl.Base64UrlCodec; + +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Date; + +/** + * 平台jwt 生成解密sdk。 + * + * @author Tung + * @version 1.0 + * @date 2017/6/29. + * @update + */ +public class JwtSDK { + private static final String DATA_PARAM_KEY = "data"; + + public JwtSDK() { + + } + + /** + * 根据appkey计算secretKey + * @param appkey + * @return + */ + public static String calSecretKey(String appkey) { + return Md5Utils.getMd5Code(appkey); + } + + private static void checkSecretKey(String secretKey) { + AssertUtil.hasText((CharSequence) secretKey, "JWT所使用的Secret Key为null或者blank, 请设置AppKey"); + } + + /** + * 构造JWT,将数据放入约定好的payload的data属性中。 + * @param secretKey 签名时使用的密文 + * @return + */ + public static String createJWT(String secretKey,String data) { + return createJWT(secretKey, data, 0L); + } + + /** + * 构造JWT,将数据放入约定好的payload的data属性中,并设置有效时效,单位秒
+ * 有效时间不是绝对准确的,因为各个节点之间的系统时间不一定完全同步。 + * @param secretKey 签名时使用的密文 + * @param data 要传入payload的参数, + * @param expired 时效,单位秒 + * @return + */ + public static String createJWT(String secretKey, String data, long expired) { + checkSecretKey(secretKey); + JwtBuilder builder = Jwts.builder() + .claim(DATA_PARAM_KEY, data) +// .signWith(SignatureAlgorithm.HS256, Base64UrlCodec.BASE64URL.encode(secretKey)); + .signWith(SignatureAlgorithm.HS256, secretKey.getBytes(Charset.forName("UTF-8"))); + if (expired > 0L) { + builder.setExpiration(new Date(System.currentTimeMillis() + 1000*expired)); + } + return builder.compact(); + } + + /** + * 根据所给的JWT字符串,获取其中约定好的数据。
+ * 若JWT中没有所约定的data属性时,返回null + * @param src + * @param secretKey + * @return + * @throws SignatureException JWT签名不匹配时抛出 + * @throws ExpiredJwtException JWT过期时抛出 + */ + public static String fetchData(String src, String secretKey) throws SignatureException, ExpiredJwtException { + checkSecretKey(secretKey); + Claims jws = Jwts.parser() +// .setSigningKey(Base64UrlCodec.BASE64URL.encode(secretKey)) + .setSigningKey(secretKey.getBytes(Charset.forName("UTF-8"))) + .parseClaimsJws(src).getBody(); + + return (String) jws.get(DATA_PARAM_KEY); + } +} diff --git a/src/main/java/coracle/Data/Md5Utils.java b/src/main/java/coracle/Data/Md5Utils.java new file mode 100644 index 0000000..ebe187b --- /dev/null +++ b/src/main/java/coracle/Data/Md5Utils.java @@ -0,0 +1,44 @@ +package coracle.Data; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * MD5加密不可逆 + * + * @author zoubaoqi + * + */ +public abstract class Md5Utils { + + public static String getMd5Code(String inString) { + + // 要加密的字符串字节型数组 + byte defaultBytes[] = inString.getBytes(); + // 加密后的字符串 + StringBuffer hexString; + // 得到MessageDigest加密对象 + MessageDigest algorithm = null; + try { + algorithm = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + // 重置上面字节数 + algorithm.reset(); + // 使用指定的字节数组更新 + algorithm.update(defaultBytes); + + byte messageDigest[] = algorithm.digest(); + hexString = new StringBuffer(); + for (int i = 0; i < messageDigest.length; i++) { + String hex = Integer.toHexString(0xff & messageDigest[i]); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + return hexString.toString(); + + } +} diff --git a/src/main/java/coracle/Data/MgmConstant.java b/src/main/java/coracle/Data/MgmConstant.java new file mode 100644 index 0000000..7a67b6e --- /dev/null +++ b/src/main/java/coracle/Data/MgmConstant.java @@ -0,0 +1,128 @@ +package coracle.Data; + + +/** + * 添加key的规则 + * 前缀指定类型HEADER PARAM 或者其他。。 + * PARAM系的值全小写,下划线分隔单词 + * HEADER系的分隔使用横杠分隔单词 + * + * @author Tung + * @version 1.0 + * @date 2017/6/30. + * @update + */ + +public interface MgmConstant { + + String HEADER_AUTH = "X-Authorization"; + + String ATTR_PUBLIC_API_PATH_PREFIX = "/v3/agent/public"; + + + String HEADER_MGM_CONSOLE_TOKEN = "X-xSimple-MgmConsole-token"; + + String HEADER_AGENT = "X-xSimple-agent"; + + String PARAM_DEBUG = "x_debug"; + + String HEADER_DEBUG = "X-xSimple-debug"; + + String HEADER_APPKEY = "X-xSimple-appKey"; + + String PARAM_APPKEY = "x_appkey"; + + String HEADER_REWRITE_URL = "X-xSimple-rewrite"; + + String PARAM_REWRITE_URL = "x_rewrite"; + + + String PARAM_BU_KEY = "x_buKey"; + + + String PARAM_API_KEY = "x_apiKey"; + + + String PARAM_API_URI = "x_apiUri"; + + String HEADER_REAL_METHOD = "X-xSimple-method"; + + String PARAM_REAL_METHOD = "x_method"; + + + /* 客户端指定当前接口是否需要应用验证。 【没用,验不验证由库决定】 + * */ + String HEADER_IS_APP_AUTH = "X-xSimple-isAppAuth"; + + /* 客户端指定当前接口是否进行身份验证, 【没用,也是由库决定】 + * */ + String HEADER_IS_AUTH = "X-xSimple-isAuth"; + + + + /* 客户端指定当前接口客户端是否参数签名 【库配置不签名,而客户端配置签名---通过并校验; 库配置签名,客户端就必需签名;】 + * */ + String HEADER_IS_SIGN = "X-xSimple-isSign"; + String PARAM_IS_SIGN = "x_isSign"; + + /** + * 客户端指定当前接口是否 需要令牌机制 【库配置不需令牌,而客户端配置令牌-通过并校验;库配置需令牌,则必需令牌】 + */ + String HEADER_SCY_TOKEN = "X-xSimple-SCY-token"; + String PARAM_SCY_TOKEN = "x_SCY_token"; + + /* 客户端指定当前接口客户端是否做了加密, 【库配置不加密,而客户端配置加密---通过并校验; 库配置加密,客户端就必需加密;】 + * */ +// String HEADER_IS_CRYPTO = "X-xSimple-isCrypto"; +// String PARAM_IS_CRYPTO = "x_cryptoType"; + String HEADER_CRYPTO_TYPE = "X-xSimple-EM"; + String PARAM_CRYPTO_TYPE = "x_EM"; + + String PARAM_MGM_TOKEN_EXPIRE = "expire"; + + public final String USER_TYPE_ADMIN ="ADMIN"; + + public final String USER_TYPE_DEVELOPER ="DEVELOPER"; + /** + * 访问者黑名单,访问者token + */ + String HEADER_ACCESS_TOKEN = "X-xSimple-accessToken"; + + public final static String ADD_TYPE_PARENT ="parent"; + + public final static String ADD_TYPE_CHILD ="child"; + + public final static String COMMON_AGENT = "2-1"; + + public final static String CONFIG_AGENT = "2-2"; + + public final static String SCRIPT_AGENT = "2-3"; + + public final static String PORT_LIST = "2-4"; + + public final static String APP_LIST = "3-1"; + + public final static String ACCOUNT_LIST = "4-1"; + + public final static String ACCESS_LIST = "4-2"; + + public final static String GLOBAL_CONFIG = "5-1"; + + public final static String LOGIN_SCRIPT = "5-2"; + + public final static String MONITOR_URL = "MONITOR_URL"; + + public final static String APP_QUERY_URL = "api/v1/appstore/getAppList"; + + public final static Integer PORT_TYPE_BLACKLIST = 1; + + public final static Integer PORT_TYPE_WHITELIST = 0; + + public final static Integer ACCESS_STATUS_VALID = 0; + + public final static Integer ACCESS_STATUS_INVALID = 1; + + public final static Integer ACCESS_TYPE_BLACK = 1; + + public final static Integer ACCESS_TYPE_WHITE = 0; +} diff --git a/src/main/java/httpgrab/Grab.java b/src/main/java/httpgrab/Grab.java index 883603e..cdc1517 100644 --- a/src/main/java/httpgrab/Grab.java +++ b/src/main/java/httpgrab/Grab.java @@ -50,19 +50,6 @@ public void sengRe() { InputStream inputStream = httpEntity.getContent(); readFormServer(inputStream); } - //lastact - //oldtopics - //sid -// for(int i=0;i iterator =set.iterator(); -// while(iterator.hasNext()){ -// System.out.println(iterator.next()); -// } } public void RequestPhoto(String tid) { @@ -184,7 +118,6 @@ public void RequestPhoto(String tid) { CloseableHttpClient httpClient = HttpClients.createDefault(); try { str = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8)); -// System.out.println(url + "---------------downloadPhotoRequest"); HttpGet httpGet = new HttpGet("http://bbs.zhiyoo.com/forum.php" + "?" + str); httpGet.setHeader("Cookie", readCookie("D:\\JavaBasis\\cookies\\downloadcookies.txt")); httpGet.setHeader("Refer", "http://bbs.zhiyoo.com/tforum-98-1192-1.html"); @@ -216,20 +149,11 @@ public void RequestPhoto(String tid) { } } - /* - 获取点击分类后的页面 - */ - public void sortTidGet() { - - } - /* 请求图片地址获取图片然后保存 */ public void SavePhoto(InputStream inputStream) throws IOException { -// File file =new File(fileName); DataInputStream dataInputStream = new DataInputStream(inputStream); -// FileOutputStream fileOutputStream= new FileOutputStream(file); byte[] bytes = new byte[1024]; int len = 0; Pattern pattern = null; @@ -250,9 +174,6 @@ public void SavePhoto(InputStream inputStream) throws IOException { if (!set.contains(newSteing)) set.add(newSteing); } -// fileOutputStream.write(bytes,0,len); -// fileOutputStream.flush(); - } showSet(); } @@ -261,11 +182,6 @@ public void SavePhoto(InputStream inputStream) throws IOException { 测试Set */ public void showSet() { -// Iterator iterator =set.iterator(); -// while (iterator.hasNext()) -// { -// System.out.println(iterator.next()+"--------set"); -// } Iterator iterator = set.iterator(); while (iterator.hasNext()) { String s = iterator.next(); @@ -277,15 +193,8 @@ public void showSet() { } public void downloadPhotoRequest(String url, String fileName) { -// List params = new ArrayList(); -// params.add(new BasicNameValuePair("mod", "")); -// params.add(new BasicNameValuePair("tid", "")); -// params.add(new BasicNameValuePair("extra", "")); -// String str = null; CloseableHttpClient httpClient = HttpClients.createDefault(); try { -// str = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8)); -// System.out.println(url + "---------------downloadPhotoRequest"); HttpGet httpGet = new HttpGet(url); httpGet.setHeader("Cookie", readCookie("D:\\JavaBasis\\cookies\\downloadcookies.txt")); httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"); @@ -320,16 +229,7 @@ public void download(String fileName, InputStream inputStream) throws IOExceptio while ((len = dataInputStream.read(bytes)) != -1) { fileOutputStream.write(bytes, 0, len); fileOutputStream.flush(); -// showSet(); } } -// @Test -// public void Stringte() -// { -// String s ="http://attach.zhiyoo.com/forum/201607/08/201044yr9d7earyjdafm48.jpg file=http://attach.zhiyoo.com/forum/201607/08/201044yr9d7earyjdafm48.jpg"; -// System.out.println(s.indexOf(".jpg", 0)); -// System.out.println(s.substring(0, s.indexOf(".jpg", 0)+4)); -// System.out.println(s); -// } } diff --git a/src/main/java/reflec/aop/Javasist/JavaisitSing.java b/src/main/java/reflec/aop/Javasist/JavaisitSing.java new file mode 100644 index 0000000..66cd83d --- /dev/null +++ b/src/main/java/reflec/aop/Javasist/JavaisitSing.java @@ -0,0 +1,13 @@ +package reflec.aop.Javasist; + +/** + * JavaSist实现AOP + * + * @author szh + * @create 2018-03-30 20:16 + **/ +public class JavaisitSing { + public void Sing(){ + System.out.println("开始唱歌"); + } +} diff --git a/src/main/java/reflec/aop/Javasist/JavasistTest.java b/src/main/java/reflec/aop/Javasist/JavasistTest.java new file mode 100644 index 0000000..5bd3f1d --- /dev/null +++ b/src/main/java/reflec/aop/Javasist/JavasistTest.java @@ -0,0 +1,29 @@ +package reflec.aop.Javasist; + +import javassist.*; + +/** + * javasistMain方法 + * + * @author szh + * @create 2018-03-30 20:17 + **/ +public class JavasistTest { + public static void main(String[] args) throws NotFoundException, CannotCompileException, IllegalAccessException, InstantiationException { + CtClass ctClass= ClassPool.getDefault().get("reflec.aop.Javasist.JavaisitSing"); + String procyName="Sing"; + CtMethod ctMethod=ctClass.getDeclaredMethod(procyName); + String newName=procyName+"$NewImpl"; + ctMethod.setName(newName); + CtMethod newMethod= CtNewMethod.copy(ctMethod, "Sing", ctClass, null); + StringBuffer sb=new StringBuffer(); + + sb.append("{System.out.println(\"开始唱歌前的准备\");\n") + .append(newName+"($$);\n") + .append("System.out.println(\"唱歌结束\");\n}"); + newMethod.setBody(sb.toString()); + ctClass.addMethod(newMethod); + JavaisitSing a=(JavaisitSing)ctClass.toClass().newInstance(); + a.Sing(); + } +} diff --git a/src/main/java/reflec/aop/Javasist/javasist.puml b/src/main/java/reflec/aop/Javasist/javasist.puml new file mode 100644 index 0000000..a7abac1 --- /dev/null +++ b/src/main/java/reflec/aop/Javasist/javasist.puml @@ -0,0 +1,3 @@ +@startuml +JavasistTest -> JavasistTest: main() +@enduml \ No newline at end of file diff --git a/src/main/java/reflec/aop/cglibtest/AOPSEQ.puml b/src/main/java/reflec/aop/cglibtest/AOPSEQ.puml new file mode 100644 index 0000000..c5c1eb1 --- /dev/null +++ b/src/main/java/reflec/aop/cglibtest/AOPSEQ.puml @@ -0,0 +1,11 @@ +@startuml +CGLIBProxy -> ProxyUtil: new() +ProxyUtil --> Reflect: new() +Reflect --> Reflect: getAnnotationClass() +Reflect --> ProxyUtil: return reflect +ProxyUtil --> CGLIBProxy: return proxyutil +CGLIBProxy --> Enhancer : getProxy() +Enhancer --> CGLIBProxy : return enhancer +CGLIBProxy --> ProxyUtil : generateEntity(ProxyEntity proxyEntity) +CGLIBProxy --> ProxyUtil : doAfter(ProxyEntity proxyEntity,Map map) +@enduml \ No newline at end of file diff --git a/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java b/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java index d286573..b3a9416 100644 --- a/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java +++ b/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java @@ -19,38 +19,15 @@ public CGLIBProxy(Object target) throws ClassNotFoundException { } public T getProxy(){ -// Enhancer enhancer =new Enhancer(); -// enhancer.setSuperclass(this.target.getClass()); -// enhancer.setCallback(this); -// return (T) enhancer.create(); return (T) new Enhancer().create(this.target.getClass(),this); } public T getProxy(Class clazz){ -// Enhancer enhancer =new Enhancer(); -// enhancer.setSuperclass(this.target.getClass()); -// enhancer.setCallback(this); -// return (T) enhancer.create(); return (T) new Enhancer().create(this.target.getClass(),this); } @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { -// System.out.println("---------before"); -// Object result =proxy.invokeSuper(obj, args); -//// System.out.println(obj.toString()); -//// System.out.println(args.toString()); -// System.out.println("------------after"); -// return result; - ProxyEntity proxyEntity =new ProxyEntity(proxy,this.target.getClass(),obj,method,args); return proxyUtil.generateEntity(proxyEntity); - } - //反射调用 - public void before(){ - - } - //反射调用 - public void after(){ - } } diff --git a/src/main/java/reflec/aop/cglibtest/CglibTest.java b/src/main/java/reflec/aop/cglibtest/CglibTest.java index afae31f..9a1d9a9 100644 --- a/src/main/java/reflec/aop/cglibtest/CglibTest.java +++ b/src/main/java/reflec/aop/cglibtest/CglibTest.java @@ -8,6 +8,6 @@ public class CglibTest { public static void main(String args[]) throws ClassNotFoundException { Music music = new Music(); CGLIBProxy cglibProxy = new CGLIBProxy(music); - ((Music)cglibProxy.getProxy()).sing("ceshi de "); + ((Music)cglibProxy.getProxy()).sing("正在唱歌"); } } diff --git a/src/main/java/reflec/aop/cglibtest/ProxyUtil.java b/src/main/java/reflec/aop/cglibtest/ProxyUtil.java index 7910f84..4d8a720 100644 --- a/src/main/java/reflec/aop/cglibtest/ProxyUtil.java +++ b/src/main/java/reflec/aop/cglibtest/ProxyUtil.java @@ -11,11 +11,6 @@ * Created by szh on 2017/4/22. */ public class ProxyUtil { - // ProxyEntity proxyEntity; -// -// public ProxyUtil(ProxyEntity proxyEntity) { -// this.proxyEntity = proxyEntity; -// } /* 加载出所有的before注解 生成invokesuper方法 @@ -34,27 +29,20 @@ public void getMethod(String name) { //该方法负责代理 public Object generateEntity(ProxyEntity proxyEntity) throws Throwable { -// System.out.println("测试before注解的方法"); // -// Map methodMap =reflect.getMap(); -// for(Map.Entry map :methodMap.entrySet() ){ -// if(map.getValue().equals(proxyEntity.getClazz().toString().substring())) -// } -// System.out.println(proxyEntity.getMethodProxy().toString()); String proxyMethodValue = proxyEntity.getMethod().toString().substring(proxyEntity.getMethod().toString().lastIndexOf(" ") + 1, proxyEntity.getMethod().toString().indexOf("(")); -// System.out.println(proxyMethodValue); //reflec.aop.cglibtest.Music.sing Map methodMap = reflect.getMap(); for (Map.Entry map : methodMap.entrySet()) { if (map.getValue().equals(proxyMethodValue)) { String[] str = mapKeyDivision(map.getKey()); if (str[2].equals("before")) { - Class clazz = Class.forName(str[1], false, Thread.currentThread().getContextClassLoader()); // 加载该类 + /* 加载该类 */ + Class clazz = Class.forName(str[1], false, Thread.currentThread().getContextClassLoader()); Method method = clazz.getDeclaredMethod(str[0]); - method.invoke(clazz.newInstance(), null); // 这一步需要原始的类 + /* 这一步需要原始的类 */ + method.invoke(clazz.newInstance(), null); } } } -// System.out.println(proxyEntity.getClazz().toString().subSequence(6,proxyEntity.getClazz().toString().length())); - //在这里是因为无法很好解决后置通知 return doAfter(proxyEntity,methodMap); } private Object doAfter(ProxyEntity proxyEntity,Map map) throws Throwable { @@ -74,7 +62,6 @@ private Object doAfter(ProxyEntity proxyEntity,Map map) throws T } private String[] mapKeyDivision(String value) { -// String value="beforeSing-reflec.aop.cglibtest.Player-before"; String[] str = new String[10]; str[0] = value.substring(0, value.indexOf("-")); str[1] = value.substring(value.indexOf("-") + 1, value.lastIndexOf("-")); diff --git a/src/main/java/reflec/aop/cglibtest/Reflect.java b/src/main/java/reflec/aop/cglibtest/Reflect.java index 39d7c68..51d4dc8 100644 --- a/src/main/java/reflec/aop/cglibtest/Reflect.java +++ b/src/main/java/reflec/aop/cglibtest/Reflect.java @@ -35,24 +35,13 @@ public void getAnnotationClass() throws ClassNotFoundException { Before before =method.getAnnotation(Before.class); // 获取注解 ,在这里如果是clazz.getAnnotation()获取的是类注解 String beforeValue=before.value(); map.put(method.getName()+ "-"+clazzName+"-"+"before",beforeValue.substring(0,beforeValue.length()-2)); // 存入的是方法名和注解名 -// System.out.println(method.getName()+ "-"+clazzName+"-"+"before"); //输出结果 beforeSing-reflec.aop.cglibtest.Player -// System.out.println(beforeValue.substring(0,beforeValue.length()-2)+"------------------beforeValue"); } if (method.isAnnotationPresent(After.class)) { After after =method.getAnnotation(After.class); // 获取注解 ,在这里如果是clazz.getAnnotation()获取的是类注解 String afterValue=after.value(); map.put(method.getName()+ "-"+clazzName+"-"+"after",afterValue.substring(0,afterValue.length()-2)); -// System.out.println(afterValue); } } } } -// public static void main(String args[]) throws ClassNotFoundException { -//// getAnnotationClass(); -// } -// private void divisionValue(String name) throws ClassNotFoundException { -// String headStr=name.substring(0,name.lastIndexOf(".")); -// String endStr=name.substring(name.lastIndexOf(".")+1,name.length()); -//// map.put(headStr,endStr); // 存入以防止 -// } } diff --git a/src/main/java/reflec/aop/test/BeforeEat.java b/src/main/java/reflec/aop/test/BeforeEat.java index fe29a30..1a3b8d7 100644 --- a/src/main/java/reflec/aop/test/BeforeEat.java +++ b/src/main/java/reflec/aop/test/BeforeEat.java @@ -11,11 +11,11 @@ public class BeforeEat { @Before("reflec.aop.test.Eat.startEat()") public void beforeStart() { - System.out.println("开始吃饭前的准备"); + System.out.println("吃饭前的准备"); } @After("reflec.aop.test.Eat.startEat()") public void afterEat() { - System.out.println("吃饭完毕以后"); + System.out.println("吃完之后的离场"); } } diff --git a/src/main/java/reflec/aop/test/Eat.java b/src/main/java/reflec/aop/test/Eat.java index f34e862..5850839 100644 --- a/src/main/java/reflec/aop/test/Eat.java +++ b/src/main/java/reflec/aop/test/Eat.java @@ -8,5 +8,4 @@ public class Eat { public void startEat(){ System.out.println("开始吃饭"); } - } From 3fb72ea875b87a2c543e0253c407ae966b25d1d0 Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Thu, 24 May 2018 23:55:16 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0TreeSet=E5=BE=97?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E7=9F=A5=E8=AF=86=E5=B9=B6=E4=B8=94=E6=B5=8B?= =?UTF-8?q?=E8=AF=95Protected=E5=BE=97=E4=BF=AE=E9=A5=B0=E7=AC=A6=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SFVideoDowland/CssVideo/CssVideo.java | 109 +++++++++++++++ .../SFVideoDowland/CssVideo/ProtectTest.java | 15 ++ .../SetAndMap/TreeSetAndTreeMap/PojoTest.java | 35 +++++ .../SetAndMap/TreeSetAndTreeMap/ProT.java | 14 ++ .../TreeSetAndTreeMap/TestTreeSet.java | 130 ++++++++++++++++++ src/main/java/coracle/Data/AssertUtil.java | 72 ---------- src/main/java/coracle/Data/CryptoSDK.java | 29 ---- src/main/java/coracle/Data/CryptoType.java | 51 ------- src/main/java/coracle/Data/JunitData.java | 88 ------------ src/main/java/coracle/Data/JwtSDK.java | 89 ------------ src/main/java/coracle/Data/Md5Utils.java | 44 ------ src/main/java/coracle/Data/MgmConstant.java | 128 ----------------- 12 files changed, 303 insertions(+), 501 deletions(-) create mode 100644 src/main/java/SFVideoDowland/CssVideo/CssVideo.java create mode 100644 src/main/java/SFVideoDowland/CssVideo/ProtectTest.java create mode 100644 src/main/java/SetAndMap/TreeSetAndTreeMap/PojoTest.java create mode 100644 src/main/java/SetAndMap/TreeSetAndTreeMap/ProT.java create mode 100644 src/main/java/SetAndMap/TreeSetAndTreeMap/TestTreeSet.java delete mode 100644 src/main/java/coracle/Data/AssertUtil.java delete mode 100644 src/main/java/coracle/Data/CryptoSDK.java delete mode 100644 src/main/java/coracle/Data/CryptoType.java delete mode 100644 src/main/java/coracle/Data/JunitData.java delete mode 100644 src/main/java/coracle/Data/JwtSDK.java delete mode 100644 src/main/java/coracle/Data/Md5Utils.java delete mode 100644 src/main/java/coracle/Data/MgmConstant.java diff --git a/src/main/java/SFVideoDowland/CssVideo/CssVideo.java b/src/main/java/SFVideoDowland/CssVideo/CssVideo.java new file mode 100644 index 0000000..ea115a9 --- /dev/null +++ b/src/main/java/SFVideoDowland/CssVideo/CssVideo.java @@ -0,0 +1,109 @@ +package SFVideoDowland.CssVideo; + +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * @author szh + * @create 2018-05-24 19:21 + **/ +public class CssVideo { + protected static void main(String[] args) { + start(); + } + private static void start(){ + CloseableHttpClient httpClient = HttpClients.createDefault(); + int i=18; +// while (i<290){ + + + try { + HttpGet httpGet=null; + if(i<10){ + httpGet = new HttpGet("https://media.video.segmentfault.com/eab963VTCl4LPZ4y8phbYaCjKqg=/lgOR6NwUEuGWs5MuNnHEW67PeDzu/00000"+String.valueOf(i)+".ts"); + }else if(i<100){ + httpGet = new HttpGet("https://media.video.segmentfault.com/eab963VTCl4LPZ4y8phbYaCjKqg=/lgOR6NwUEuGWs5MuNnHEW67PeDzu/0000"+String.valueOf(i)+".ts"); + }else{ + httpGet = new HttpGet("https://media.video.segmentfault.com/eab963VTCl4LPZ4y8phbYaCjKqg=/lgOR6NwUEuGWs5MuNnHEW67PeDzu/000"+String.valueOf(i)+".ts"); + } + +// httpGet.setHeader("accept-ranges", "bytes6"); +// httpGet.setHeader("access-control-allow-origin", "*"); +// httpGet.setHeader("access-control-expose-headers", "X-Log, X-Reqid"); +// httpGet.setHeader("access-control-max-age", "2592000"); +// httpGet.setHeader("age", "0"); +// httpGet.setHeader("cache-control", "max-age=2592000"); +// httpGet.setHeader("content-disposition", "inline; filename=\"000001.ts\"; filename*=utf-8' '000001.ts"); //TODO +// httpGet.setHeader("content-length", "558172"); +// httpGet.setHeader("content-transfer-encoding", "tbinary"); +// httpGet.setHeader("date", "video/mp2t"); +// httpGet.setHeader("content-type", "Thu, 24 May 2018 11:05:04 GMT"); +// httpGet.setHeader("etag", "FunorSPF5uS7h3Tn4lxYCLZu0zGv"); +// httpGet.setHeader("expires", "Sat, 23 Jun 2018 11:05:04 GMT"); +// httpGet.setHeader("expires", "Sat, 23 Jun 2018 11:05:04 GMT"); +// httpGet.setHeader("last-modified", "Tue, 02 Jan 2018 06:50:51 GMT"); +// httpGet.setHeader("server", "marco/2.2"); +// httpGet.setHeader("status", "200"); +// httpGet.setHeader("via", "T.11.-, V.mix-gd-can-005, T.69.N, M.cun-hb-wuh-069"); +// httpGet.setHeader("x-log", "mc.g/404;rs12_12.sel/not found;rs11_12.sel;rwro.get:1;RS.dbs:1;RS:1;mc.s;mc.g;IO:33"); +// httpGet.setHeader("x-m-log", "QNM:xs446;QNM3:23"); +// httpGet.setHeader("x-m-reqid", "1RkAACcY3UsWOygV"); +// httpGet.setHeader("x-qiniu-zone", "1"); +// httpGet.setHeader("x-qnm-cache", "Hit"); +// httpGet.setHeader("x-reqid", "q1QAAK99xfjqEiYV"); +// httpGet.setHeader("x-request-id", "36e9b5c2525194a6147b248e0cf2be26"); +// httpGet.setHeader("x-slice-complete-length", "558172"); +// httpGet.setHeader("x-slice-etag", "T.11.-, V.mix-gd-can-005, T.69.N, M.cun-hb-wuh-069"); +// httpGet.setHeader("x-slice-size", "FunorSPF5uS7h3Tn4lxYCLZu0zGv"); +// httpGet.setHeader("x-source", "C/200"); +// httpGet.setHeader("x-svr", "IO"); + httpGet.setHeader("Origin", "https://segmentfault.com"); + httpGet.setHeader("Referer", "https://segmentfault.com/l/1500000012666812/play"); + httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"); + CloseableHttpResponse response = httpClient.execute(httpGet); + try { + HttpEntity httpEntity = response.getEntity(); + if (httpClient != null) { + InputStream inputStream = httpEntity.getContent(); + File file = new File("D:\\JavaBasis\\cookies\\0000"+String.valueOf(i)+".ts"); + FileOutputStream fileout = new FileOutputStream(file); + byte[] bytes = new byte[1024]; + int len; + while ((len = inputStream.read(bytes)) != -1) { +// String s = new String(bytes, 0, len); + fileout.write(bytes, 0, len); + fileout.flush(); + } + fileout.close(); + inputStream.close(); + } + +// int len =0; +// while ((len=inputStream.read()) !=-1){ +// +// + } catch (Exception e) { + e.printStackTrace(); + } + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } +// i++; +// } + } + public void te(){ + + } +} diff --git a/src/main/java/SFVideoDowland/CssVideo/ProtectTest.java b/src/main/java/SFVideoDowland/CssVideo/ProtectTest.java new file mode 100644 index 0000000..4466387 --- /dev/null +++ b/src/main/java/SFVideoDowland/CssVideo/ProtectTest.java @@ -0,0 +1,15 @@ +package SFVideoDowland.CssVideo; + +/** + * @author szh + * @create 2018-05-24 23:31 + **/ +public class ProtectTest { + protected int i; + protected void protectMethod(){ + + } + public void publicMethod(){ + + } +} diff --git a/src/main/java/SetAndMap/TreeSetAndTreeMap/PojoTest.java b/src/main/java/SetAndMap/TreeSetAndTreeMap/PojoTest.java new file mode 100644 index 0000000..dcd53f3 --- /dev/null +++ b/src/main/java/SetAndMap/TreeSetAndTreeMap/PojoTest.java @@ -0,0 +1,35 @@ +package SetAndMap.TreeSetAndTreeMap; + + +/** + * @author szh + * @create 2018-05-24 17:03 + **/ +public class PojoTest { + private int id; + private String name; + + public PojoTest() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public PojoTest(int id, String name) { + this.id = id; + this.name = name; + } +} diff --git a/src/main/java/SetAndMap/TreeSetAndTreeMap/ProT.java b/src/main/java/SetAndMap/TreeSetAndTreeMap/ProT.java new file mode 100644 index 0000000..6786a0f --- /dev/null +++ b/src/main/java/SetAndMap/TreeSetAndTreeMap/ProT.java @@ -0,0 +1,14 @@ +package SetAndMap.TreeSetAndTreeMap; + +import SFVideoDowland.CssVideo.ProtectTest; + +/** + * @author szh + * @create 2018-05-24 23:32 + **/ +public class ProT extends ProtectTest{ + public static void main(String[] args) { + ProtectTest protectTest =new ProtectTest(); + protectTest.publicMethod(); + } +} diff --git a/src/main/java/SetAndMap/TreeSetAndTreeMap/TestTreeSet.java b/src/main/java/SetAndMap/TreeSetAndTreeMap/TestTreeSet.java new file mode 100644 index 0000000..d59f57a --- /dev/null +++ b/src/main/java/SetAndMap/TreeSetAndTreeMap/TestTreeSet.java @@ -0,0 +1,130 @@ +package SetAndMap.TreeSetAndTreeMap; + +import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream; +import org.junit.Test; +import sun.reflect.generics.tree.Tree; + +import java.util.*; + +/** + * TreeSet的测试类 + * + * @author szh + * @create 2018-05-24 15:53 + **/ +public class TestTreeSet{ + + + private static void construct(){ + Comparator comparator =new Comparator() { + @Override + public int compare(String o1, String o2) { + if(o1.toCharArray()[0] >o2.toCharArray()[0]){ + return -1; + }else if(o1.toCharArray()[0] == o2.toCharArray()[0]){ + return 0; + }else{ + return 1; + } + } + }; + TreeSet treeSet =new TreeSet<>(comparator); + List list =new ArrayList<>(); + list.add("a"); + list.add("d"); + list.add("b"); + treeSet.addAll(list); + Iterator iterator =treeSet.iterator(); + while (iterator.hasNext()){ + System.out.println(iterator.next()); + } + Comparator comparator1 = (Comparator) treeSet.comparator(); + TreeSet treeSet1 =new TreeSet<>(comparator1); + treeSet1.add("c"); + treeSet1.add("g"); + treeSet1.add("a"); + Iterator iterator1 =treeSet1.iterator(); + while (iterator1.hasNext()){ + System.out.println(iterator1.next()); + } +// TreeSet treeSet1 =treeSet.comparator(); +// Iterator iterator2=treeSet1.iterator(); +// while (iterator2.hasNext()){ +// System.out.println(iterator.next()); +// } + } + + private static void compareWithCpmparator(){ + Stack stack =new Stack<>(); + TreeSet treeSet =new TreeSet<>(); + List list =new ArrayList<>(); + list.add("a"); + list.add("d"); + list.add("b"); + treeSet.addAll(list); + Iterator iterator =treeSet.iterator(); + while (iterator.hasNext()){ + System.out.println(iterator.next()); + } + Comparator comparator1 = (Comparator) treeSet.comparator(); + if (comparator1 == null){ + System.out.println("comparator1是空"); + }else { + System.out.println("comparator1不是空"); + } + } + + private static void com(){ + TreeSet treeSet =new TreeSet<>(); + treeSet.add(new PojoTest(1,"a")); + treeSet.add(new PojoTest(2,"b")); + treeSet.add(new PojoTest(3,"c")); + Iterator iterator =treeSet.iterator(); + while (iterator.hasNext()){ + System.out.println(iterator.next().getName()); + } + } + public static void main(String[] args) { +// construct(); +// compareWithCpmparator(); + com(); + } + + @Test + public void calPoints() { + String[] ops=new String[]{"5","-2","4","C","D","9","+","+"}; + Stack stack =new Stack<>(); + int total=0; + for(String s : ops ){ + if(s.equals("C")){ + total = total-stack.peek(); + stack.pop(); +// stack.push(total); + }else if(s.equals("D")){ + int num =stack.peek(); + num =num *2; + total+=num; + stack.push(num); + }else if(s.equals("+")){ + int str1=stack.pop(); + int str2 =stack.pop(); + int num =str1+str2; + stack.push(str2); + stack.push(str1); + total =total+str1+str2; + stack.push(num); + }else{ + total+=Integer.valueOf(s); + stack.push(Integer.valueOf(s)); + } + + } + if(stack.size() <=1){ +// return Integer.valueOf(stack.pop()); + System.out.println(stack.pop()); + } + System.out.println(total); + // return Integer.valueOf(stack.pop())+Integer.valueOf(stack.pop()); + } + +} diff --git a/src/main/java/coracle/Data/AssertUtil.java b/src/main/java/coracle/Data/AssertUtil.java deleted file mode 100644 index 4819113..0000000 --- a/src/main/java/coracle/Data/AssertUtil.java +++ /dev/null @@ -1,72 +0,0 @@ -package coracle.Data; - -/** - * 断言工具类,不符合断言时抛出IllegalArgumentException - * - * @author Tung - * @version 1.0 - * @date 2017/6/24. - * @update - */ - -public class AssertUtil { - - public static void hasLength(String text, String message) { - - if (!hasLength(text)) { - throw new IllegalArgumentException(message); - } - } - - public static boolean hasLength(String str) { - - return hasLength((CharSequence) str); - } - - public static boolean hasLength(CharSequence str) { - - return (str != null && str.length() > 0); - } - - /** - * 当传入字符串为null, empty或者blank时,抛出IllegalArgumentException。 - * - * @param str - * @param msg - */ - public static void hasText(String str, String msg) { - - hasText((CharSequence) str, msg); - } - - /** - * 当传入字符序列为null, empty或者blank时,抛出IllegalArgumentException。 - * - * @param str - * @param msg - */ - public static void hasText(CharSequence str, String msg) { - - if ((str != null && str.length() > 0)) { - int strLen = str.length(); - for (int i = 0; i < strLen; i++) { - if (!Character.isWhitespace(str.charAt(i))) { - return; - } - } - } - throw new IllegalArgumentException(msg); - } - - /** - * 当传入的对象为null时,抛出IllegalArgumentException。 - * @param obj - * @param msg - */ - public static void notNull(Object obj, String msg) { - - if (obj == null) { - throw new IllegalArgumentException(msg); - } - } -} diff --git a/src/main/java/coracle/Data/CryptoSDK.java b/src/main/java/coracle/Data/CryptoSDK.java deleted file mode 100644 index eedbe14..0000000 --- a/src/main/java/coracle/Data/CryptoSDK.java +++ /dev/null @@ -1,29 +0,0 @@ -package coracle.Data; - -import coracle.Data.CryptoType; -import org.coracle.xsimple.common.codec.CoracleCoder; - -/** - * TODO Fill The Description! - * - * @author Tung - * @version 1.0 - * @date 2017/7/5. - * @update - */ -public class CryptoSDK { - - public static String withAaemEncrypt(String src) { - - return CoracleCoder.enc(src, CryptoType.AEM.name()); - } - - public static String withAemDecrypt(String src) { - return CoracleCoder.dec(src, CryptoType.AEM.name()); - } - - public static void main(String[] args) { - System.out.println(withAaemEncrypt("false")); -// System.out.println(withAemDecrypt("70IcNz9zTl+3rSGw6LCdrw==")); - } -} diff --git a/src/main/java/coracle/Data/CryptoType.java b/src/main/java/coracle/Data/CryptoType.java deleted file mode 100644 index 7744104..0000000 --- a/src/main/java/coracle/Data/CryptoType.java +++ /dev/null @@ -1,51 +0,0 @@ -package coracle.Data; - -import java.util.HashMap; -import java.util.Map; - -/** - * TODO Fill The Description! - * - * @author Tung - * @version 1.0 - * @date 2017/7/5. - * @update - */ - -public enum CryptoType { - /** - * 不加密 - */ - NONE("NONE"), - - - AEM("AEM"); - // , REM("REM"), DEM("DEM"), RSA("RSA"); //暂不支持 - - - private static final Map mappings = new HashMap<>(4); - - static { - for (CryptoType cryptoType : values()) { - mappings.put(cryptoType.name(), cryptoType); - } - } - - private String mode; - CryptoType(String mode) { - this.mode = mode; - } - - public static CryptoType resolve(String mode) { - return (mode != null ? mappings.get(mode) : NONE); - } - - public boolean matches(String mode) { - return (this == resolve(mode)); - } - - @Override - public String toString() { - return this.name(); - } -} diff --git a/src/main/java/coracle/Data/JunitData.java b/src/main/java/coracle/Data/JunitData.java deleted file mode 100644 index 5eeeb25..0000000 --- a/src/main/java/coracle/Data/JunitData.java +++ /dev/null @@ -1,88 +0,0 @@ -package coracle.Data; - -import com.alibaba.fastjson.JSON; -import okhttp3.*; -import org.junit.Test; - -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; - -/** - * 对Coracle的api进行测试 - * - * @author szh - * @create 2018-03-27 15:17 - **/ -public class JunitData { - public static final MediaType JSONMe = MediaType.parse("application/json; charset=utf-8"); - - @Test - public void uu(){ - Date now = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式 - java.util.Calendar Cal=java.util.Calendar.getInstance(); - Cal.setTime(now); - Cal.add(Calendar.MINUTE,30); - System.out.println("date:"+dateFormat.format(Cal.getTime())); - } - - - - @Test - public void sendData() throws IOException { - OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build(); - Map map = new HashMap(); - map.put("user", "zhouhaoxiang"); - map.put("password", "8GTxy9iTj49asNhe0Gqamw=="); - map.put("remember", "true"); - String url = "http://172.16.23.169:8080/mchl/v3/agent/public/api/login"; - String json = JSON.toJSONString(map); - RequestBody body = RequestBody.create(JSONMe, json); - - Request request = new Request.Builder() - .url(url) - .header("X-xSimple-appKey", "8b73e4ee-696c-4c8c-aabd-0c893ba82e73") - .post(body) - .build(); - Response response = okHttpClient.newCall(request).execute(); - System.out.println(response.body().string()); - } - - @Test - public void getData() throws IOException { - - OkHttpClient okHttpClient = new OkHttpClient().newBuilder().build(); - Map map = new HashMap(); - String url = "http://172.16.23.169:8080/mchl/v3/agent/bu"; - - RequestBody body = RequestBody.create(JSONMe, ""); - - String agent ="x_apiKey=serverInfo&x_buKey=mxm&x_method=POST&x_EM=AEM&x_isSign=true"; - String appkey=JwtSDK.calSecretKey("8b73e4ee-696c-4c8c-aabd-0c893ba82e73"); - System.out.println(appkey); - String result=JwtSDK.createJWT(appkey,agent); - System.out.println(result); - - Request request = new Request.Builder() - .url(url) - .header("X-Authorization", "eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjoie1widXNlcm5hbWVcIjpcInpob3VoYW94aWFuZ1wifSJ9.9qnhk1ioN2z4BBDe1l5dpsyy594KGq0j8hBHHEnNn0w") - .header("X-xSimple-debug", "false") //加密需要转成false - .header("X-xSimple-appKey", "8b73e4ee-696c-4c8c-aabd-0c893ba82e73") -// .header("X-xSimple-agent", "x_apiKey=serverInfo&x_buKey=mxm&x_method=POST&x_EM=NONE&x_isSign=false")// jwt签名 - .header("X-xSimple-agent", result)// jwt签名 AEM - -// .header("X-xSimple-agent", "x_apiKey=serverInfo&x_buKey=mxm&x_method=POST")// 未加密 - .header("X-xSimple-IMEI","5498313987f90080d23805082da531ec1b11f895") - .post(body) // AEM - .build(); - - Response response = okHttpClient.newCall(request).execute(); -// System.out.println(response.body().string()); - System.out.println(CryptoSDK.withAemDecrypt(response.body().string())); - } -} diff --git a/src/main/java/coracle/Data/JwtSDK.java b/src/main/java/coracle/Data/JwtSDK.java deleted file mode 100644 index 13d55de..0000000 --- a/src/main/java/coracle/Data/JwtSDK.java +++ /dev/null @@ -1,89 +0,0 @@ -package coracle.Data; - -import coracle.Data.Md5Utils; -import coracle.Data.AssertUtil; -import io.jsonwebtoken.*; -import io.jsonwebtoken.impl.Base64UrlCodec; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Date; - -/** - * 平台jwt 生成解密sdk。 - * - * @author Tung - * @version 1.0 - * @date 2017/6/29. - * @update - */ -public class JwtSDK { - private static final String DATA_PARAM_KEY = "data"; - - public JwtSDK() { - - } - - /** - * 根据appkey计算secretKey - * @param appkey - * @return - */ - public static String calSecretKey(String appkey) { - return Md5Utils.getMd5Code(appkey); - } - - private static void checkSecretKey(String secretKey) { - AssertUtil.hasText((CharSequence) secretKey, "JWT所使用的Secret Key为null或者blank, 请设置AppKey"); - } - - /** - * 构造JWT,将数据放入约定好的payload的data属性中。 - * @param secretKey 签名时使用的密文 - * @return - */ - public static String createJWT(String secretKey,String data) { - return createJWT(secretKey, data, 0L); - } - - /** - * 构造JWT,将数据放入约定好的payload的data属性中,并设置有效时效,单位秒
- * 有效时间不是绝对准确的,因为各个节点之间的系统时间不一定完全同步。 - * @param secretKey 签名时使用的密文 - * @param data 要传入payload的参数, - * @param expired 时效,单位秒 - * @return - */ - public static String createJWT(String secretKey, String data, long expired) { - checkSecretKey(secretKey); - JwtBuilder builder = Jwts.builder() - .claim(DATA_PARAM_KEY, data) -// .signWith(SignatureAlgorithm.HS256, Base64UrlCodec.BASE64URL.encode(secretKey)); - .signWith(SignatureAlgorithm.HS256, secretKey.getBytes(Charset.forName("UTF-8"))); - if (expired > 0L) { - builder.setExpiration(new Date(System.currentTimeMillis() + 1000*expired)); - } - return builder.compact(); - } - - /** - * 根据所给的JWT字符串,获取其中约定好的数据。
- * 若JWT中没有所约定的data属性时,返回null - * @param src - * @param secretKey - * @return - * @throws SignatureException JWT签名不匹配时抛出 - * @throws ExpiredJwtException JWT过期时抛出 - */ - public static String fetchData(String src, String secretKey) throws SignatureException, ExpiredJwtException { - checkSecretKey(secretKey); - Claims jws = Jwts.parser() -// .setSigningKey(Base64UrlCodec.BASE64URL.encode(secretKey)) - .setSigningKey(secretKey.getBytes(Charset.forName("UTF-8"))) - .parseClaimsJws(src).getBody(); - - return (String) jws.get(DATA_PARAM_KEY); - } -} diff --git a/src/main/java/coracle/Data/Md5Utils.java b/src/main/java/coracle/Data/Md5Utils.java deleted file mode 100644 index ebe187b..0000000 --- a/src/main/java/coracle/Data/Md5Utils.java +++ /dev/null @@ -1,44 +0,0 @@ -package coracle.Data; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * MD5加密不可逆 - * - * @author zoubaoqi - * - */ -public abstract class Md5Utils { - - public static String getMd5Code(String inString) { - - // 要加密的字符串字节型数组 - byte defaultBytes[] = inString.getBytes(); - // 加密后的字符串 - StringBuffer hexString; - // 得到MessageDigest加密对象 - MessageDigest algorithm = null; - try { - algorithm = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } - // 重置上面字节数 - algorithm.reset(); - // 使用指定的字节数组更新 - algorithm.update(defaultBytes); - - byte messageDigest[] = algorithm.digest(); - hexString = new StringBuffer(); - for (int i = 0; i < messageDigest.length; i++) { - String hex = Integer.toHexString(0xff & messageDigest[i]); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); - } - return hexString.toString(); - - } -} diff --git a/src/main/java/coracle/Data/MgmConstant.java b/src/main/java/coracle/Data/MgmConstant.java deleted file mode 100644 index 7a67b6e..0000000 --- a/src/main/java/coracle/Data/MgmConstant.java +++ /dev/null @@ -1,128 +0,0 @@ -package coracle.Data; - - -/** - * 添加key的规则 - * 前缀指定类型HEADER PARAM 或者其他。。 - * PARAM系的值全小写,下划线分隔单词 - * HEADER系的分隔使用横杠分隔单词 - * - * @author Tung - * @version 1.0 - * @date 2017/6/30. - * @update - */ - -public interface MgmConstant { - - String HEADER_AUTH = "X-Authorization"; - - String ATTR_PUBLIC_API_PATH_PREFIX = "/v3/agent/public"; - - - String HEADER_MGM_CONSOLE_TOKEN = "X-xSimple-MgmConsole-token"; - - String HEADER_AGENT = "X-xSimple-agent"; - - String PARAM_DEBUG = "x_debug"; - - String HEADER_DEBUG = "X-xSimple-debug"; - - String HEADER_APPKEY = "X-xSimple-appKey"; - - String PARAM_APPKEY = "x_appkey"; - - String HEADER_REWRITE_URL = "X-xSimple-rewrite"; - - String PARAM_REWRITE_URL = "x_rewrite"; - - - String PARAM_BU_KEY = "x_buKey"; - - - String PARAM_API_KEY = "x_apiKey"; - - - String PARAM_API_URI = "x_apiUri"; - - String HEADER_REAL_METHOD = "X-xSimple-method"; - - String PARAM_REAL_METHOD = "x_method"; - - - /* 客户端指定当前接口是否需要应用验证。 【没用,验不验证由库决定】 - * */ - String HEADER_IS_APP_AUTH = "X-xSimple-isAppAuth"; - - /* 客户端指定当前接口是否进行身份验证, 【没用,也是由库决定】 - * */ - String HEADER_IS_AUTH = "X-xSimple-isAuth"; - - - - /* 客户端指定当前接口客户端是否参数签名 【库配置不签名,而客户端配置签名---通过并校验; 库配置签名,客户端就必需签名;】 - * */ - String HEADER_IS_SIGN = "X-xSimple-isSign"; - String PARAM_IS_SIGN = "x_isSign"; - - /** - * 客户端指定当前接口是否 需要令牌机制 【库配置不需令牌,而客户端配置令牌-通过并校验;库配置需令牌,则必需令牌】 - */ - String HEADER_SCY_TOKEN = "X-xSimple-SCY-token"; - String PARAM_SCY_TOKEN = "x_SCY_token"; - - /* 客户端指定当前接口客户端是否做了加密, 【库配置不加密,而客户端配置加密---通过并校验; 库配置加密,客户端就必需加密;】 - * */ -// String HEADER_IS_CRYPTO = "X-xSimple-isCrypto"; -// String PARAM_IS_CRYPTO = "x_cryptoType"; - String HEADER_CRYPTO_TYPE = "X-xSimple-EM"; - String PARAM_CRYPTO_TYPE = "x_EM"; - - String PARAM_MGM_TOKEN_EXPIRE = "expire"; - - public final String USER_TYPE_ADMIN ="ADMIN"; - - public final String USER_TYPE_DEVELOPER ="DEVELOPER"; - /** - * 访问者黑名单,访问者token - */ - String HEADER_ACCESS_TOKEN = "X-xSimple-accessToken"; - - public final static String ADD_TYPE_PARENT ="parent"; - - public final static String ADD_TYPE_CHILD ="child"; - - public final static String COMMON_AGENT = "2-1"; - - public final static String CONFIG_AGENT = "2-2"; - - public final static String SCRIPT_AGENT = "2-3"; - - public final static String PORT_LIST = "2-4"; - - public final static String APP_LIST = "3-1"; - - public final static String ACCOUNT_LIST = "4-1"; - - public final static String ACCESS_LIST = "4-2"; - - public final static String GLOBAL_CONFIG = "5-1"; - - public final static String LOGIN_SCRIPT = "5-2"; - - public final static String MONITOR_URL = "MONITOR_URL"; - - public final static String APP_QUERY_URL = "api/v1/appstore/getAppList"; - - public final static Integer PORT_TYPE_BLACKLIST = 1; - - public final static Integer PORT_TYPE_WHITELIST = 0; - - public final static Integer ACCESS_STATUS_VALID = 0; - - public final static Integer ACCESS_STATUS_INVALID = 1; - - public final static Integer ACCESS_TYPE_BLACK = 1; - - public final static Integer ACCESS_TYPE_WHITE = 0; -} From 0410be2013e5d3a73fe93a09cbcfaada2865ebd4 Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Wed, 6 Jun 2018 00:45:11 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BF=AE=E9=A5=B0?= =?UTF-8?q?=E7=AC=A6=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ExceptionAndError/TestErroe.java | 33 ++++++++++++ .../NettyInAction/ch2/echo/EchoClient.java | 18 ++++--- .../ch2/echo/EchoClientHandle.java | 8 +-- src/main/java/PECS/PECSTest.java | 25 +++++++++ src/main/java/StringTest/SplitTest.java | 17 ++++++ src/main/java/T/AbstractTest.java | 49 ++++++++++++++++++ src/main/java/T/ExceptionTest.java | 15 ++++++ src/main/java/T/InaAnTest.class | Bin 0 -> 361 bytes src/main/java/T/InaAnTest.java | 13 +++++ src/main/java/T/IntTest.class | Bin 0 -> 406 bytes src/main/java/T/IntTest.java | 20 +++++++ src/main/java/T/InterfaceTest.java | 16 ++++++ src/main/java/T/T2.java | 1 + src/main/java/operation/ScaleTest.java | 28 ++++++++++ 14 files changed, 234 insertions(+), 9 deletions(-) create mode 100644 src/main/java/ExceptionAndError/TestErroe.java create mode 100644 src/main/java/PECS/PECSTest.java create mode 100644 src/main/java/StringTest/SplitTest.java create mode 100644 src/main/java/T/AbstractTest.java create mode 100644 src/main/java/T/ExceptionTest.java create mode 100644 src/main/java/T/InaAnTest.class create mode 100644 src/main/java/T/InaAnTest.java create mode 100644 src/main/java/T/IntTest.class create mode 100644 src/main/java/T/IntTest.java create mode 100644 src/main/java/T/InterfaceTest.java create mode 100644 src/main/java/operation/ScaleTest.java diff --git a/src/main/java/ExceptionAndError/TestErroe.java b/src/main/java/ExceptionAndError/TestErroe.java new file mode 100644 index 0000000..4b49c20 --- /dev/null +++ b/src/main/java/ExceptionAndError/TestErroe.java @@ -0,0 +1,33 @@ +package ExceptionAndError; + +/** + * @author szh + * @create 2018-05-25 16:08 + **/ +public class TestErroe { + Runnable runnable =new Runnable() { + @Override + public void run() { + for(int i =0 ;i< 100000 ;i++){ +// if(i>50){ +// try { +// Thread.currentThread().sleep(1000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } + } + } + }; + private void startThread(){ + Thread thread =new Thread(runnable); + thread.start(); + thread.stop(); + } + + public static void main(String[] args) { + TestErroe testErroe =new TestErroe(); + testErroe.startThread(); + Thread.currentThread(); + } +} diff --git a/src/main/java/NettyInAction/ch2/echo/EchoClient.java b/src/main/java/NettyInAction/ch2/echo/EchoClient.java index bce4639..4481285 100644 --- a/src/main/java/NettyInAction/ch2/echo/EchoClient.java +++ b/src/main/java/NettyInAction/ch2/echo/EchoClient.java @@ -3,10 +3,7 @@ import io.netty.bootstrap.Bootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.EventLoopGroup; +import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -40,20 +37,29 @@ protected void initChannel(SocketChannel socketChannel) throws Exception { } }); ChannelFuture f= b.connect().sync(); + f.addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture channelFuture) throws Exception { + if(f.isSuccess()){ + System.out.println("有客户端链接"); + } + } + }); Channel channel =f.channel(); Scanner scanner =new Scanner(System.in); // ByteBuf byteBuf=null; while (true){ String Message =scanner.nextLine(); if(Message.length() != 0){ + if(Message.equals("exit")){ + break; + } // byteBuf.writeBytes(Message.getBytes()); System.out.println(Message); // f.channel().writeAndFlush(Unpooled.copiedBuffer(Message,CharsetUtil.UTF_8)); // f.channel().flush(); System.out.println(f.channel().isActive()); e.list.get(0).writeAndFlush(Unpooled.copiedBuffer(Message,CharsetUtil.UTF_8)); - }if(Message =="exit"){ - break; } } f.channel().closeFuture().sync(); diff --git a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java index f0acb4a..70f94e3 100644 --- a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java +++ b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java @@ -2,6 +2,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.util.CharsetUtil; @@ -12,6 +13,7 @@ /** * Created by szh on 2017/5/22. */ +@ChannelHandler.Sharable public class EchoClientHandle extends SimpleChannelInboundHandler{ public String Message; public static List list =new ArrayList<>(); @@ -20,7 +22,7 @@ public class EchoClientHandle extends SimpleChannelInboundHandler{ // System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); // } protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { - System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); + System.out.println("客端接受到的数据是channelRead0" + byteBuf.toString(CharsetUtil.UTF_8)); } @Override @@ -37,12 +39,12 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; - System.out.println("客端接受到的数据是" + buf.toString(CharsetUtil.UTF_8)); + System.out.println("客端接受到的数据是channelRead" + buf.toString(CharsetUtil.UTF_8)); } @Override protected void messageReceived(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { - System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); + System.out.println("客端接受到的数据是messageReceived" + byteBuf.toString(CharsetUtil.UTF_8)); } } diff --git a/src/main/java/PECS/PECSTest.java b/src/main/java/PECS/PECSTest.java new file mode 100644 index 0000000..e0cb0cd --- /dev/null +++ b/src/main/java/PECS/PECSTest.java @@ -0,0 +1,25 @@ +package PECS; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author szh + * @create 2018-06-01 11:17 + **/ +public class PECSTest { + private void t(){ + List list =new ArrayList<>(); + B b = new B(); + A a =new A(); + } +} + +class A{ + +} +class B extends A{ + public void b(){ + System.out.println("b"); + } +} \ No newline at end of file diff --git a/src/main/java/StringTest/SplitTest.java b/src/main/java/StringTest/SplitTest.java new file mode 100644 index 0000000..29218c9 --- /dev/null +++ b/src/main/java/StringTest/SplitTest.java @@ -0,0 +1,17 @@ +package StringTest; + +/** + * @author szh + * @create 2018-05-30 22:07 + **/ +public class SplitTest { + public static void main(String[] args) { + String s ="Iam qwe"; + String[] s1=s.split(" "); +// System.out.println(s.substring(1)); + System.out.println(s.substring(0, 1)); +// for( String s2 :s1){ +// System.out.println(s2); +// } + } +} diff --git a/src/main/java/T/AbstractTest.java b/src/main/java/T/AbstractTest.java new file mode 100644 index 0000000..3209d66 --- /dev/null +++ b/src/main/java/T/AbstractTest.java @@ -0,0 +1,49 @@ +package T; + +/** + * @author szh + * @create 2018-05-28 0:10 + **/ +public abstract class AbstractTest { + public void methodWithBody(){ + System.out.println("body"); + } + public abstract void methodWithoutBody(); + protected void protectWithBody(){ + System.out.println("protectBody"); + } + protected abstract void ProtectWithoutBody(); + private void privateWithBody(){ + System.out.println("protectBody"); + } + abstract void defaultWithOutMethod(); + void defaultWithBody(){ + + } + public int i; + protected int pi; + private int privatei; + int defaulti; + + public static void main(String[] args) { + AbstractTest abstractTest =new AbstractTest() { + @Override + public void methodWithoutBody() { + + } + + @Override + protected void ProtectWithoutBody() { + + } + + @Override + void defaultWithOutMethod() { + + } + }; + } + + + +} diff --git a/src/main/java/T/ExceptionTest.java b/src/main/java/T/ExceptionTest.java new file mode 100644 index 0000000..babcf4f --- /dev/null +++ b/src/main/java/T/ExceptionTest.java @@ -0,0 +1,15 @@ +package T; + +/** + * @author szh + * @create 2018-05-28 22:50 + **/ +public class ExceptionTest { + private void test(){ + try{ + + }catch (Error e){ + e.printStackTrace(); + } + } +} diff --git a/src/main/java/T/InaAnTest.class b/src/main/java/T/InaAnTest.class new file mode 100644 index 0000000000000000000000000000000000000000..9f832f2834d406d71de0b19ee5337290728b10b5 GIT binary patch literal 361 zcmZut%Sr=55Uk!^GiEa;F%RD!yd`^ZFCGL%5J3n86?Vye5(k-(%*tjW_*se%@Zbmd zQDW~N1i?cW-PKi4-Cy4yp8$@qAEJUr6)R{~v5r=VHaY@bfeivFt^uKPYOHZ*1i#lG z5rT{CRudXSWA)W?KGu1v#xrKZBwOYaeQAoJKCtTCrh4HHr|LmTR1r!DtO{&OY++kq zM`9OygjyQ^iV4j^9?z7$i?7F1J#l}i!J|&#v$rh>L@j9Thp5squ6SuiSN_cTnWN!h41vy})}z@KmZLV+#SJ RU<}z?;|EH1tug1J{sUGyM124N literal 0 HcmV?d00001 diff --git a/src/main/java/T/InaAnTest.java b/src/main/java/T/InaAnTest.java new file mode 100644 index 0000000..bf25f2f --- /dev/null +++ b/src/main/java/T/InaAnTest.java @@ -0,0 +1,13 @@ +package T; + +/** + * @author szh + * @create 2018-05-31 0:29 + **/ +public class InaAnTest { + int a; + { + a=0; + System.out.println(a); + } +} diff --git a/src/main/java/T/IntTest.class b/src/main/java/T/IntTest.class new file mode 100644 index 0000000000000000000000000000000000000000..ed9f744dd0e0b0c742b82390380961e9a624e846 GIT binary patch literal 406 zcmZutOHaZ;5dNk-wyjl>3O>LGH{f6|-Y{M?CL}~nAlwUX$P(C^vY7a@G>VA_e}F&A zI9t7#n9aPtnQwMxKEK{S0Gy)X!^M^dfwG4X+de9&y6~*s5!e;jBT&rJB^1w;R_2_L zYqo}j{6%sn37b8o<@IttlIb8G%^30f$ub?wD`kVAtIa?z%*ixAyi3VHU*g%yfV8Eb=e6$RD;dG6`)3%O&ByYUGbcToBUCS*-G literal 0 HcmV?d00001 diff --git a/src/main/java/T/IntTest.java b/src/main/java/T/IntTest.java new file mode 100644 index 0000000..dc068a4 --- /dev/null +++ b/src/main/java/T/IntTest.java @@ -0,0 +1,20 @@ +package T; + +/** + * @author szh + * @create 2018-05-30 23:55 + **/ +public class IntTest { + { + System.out.println(this.a); + System.out.println("a"); + } + int a; + { + System.out.println("b"); + } + + public static void main(String[] args) { + new IntTest(); + } +} diff --git a/src/main/java/T/InterfaceTest.java b/src/main/java/T/InterfaceTest.java new file mode 100644 index 0000000..0a22250 --- /dev/null +++ b/src/main/java/T/InterfaceTest.java @@ -0,0 +1,16 @@ +package T; + +interface InterfaceTest { + default void say(){ + System.out.println(s); + } + public static void a(){ + + } + public abstract void s(); + int i=0; + public static int j =0; + public static final int m=0; + public int n=0; + String s =new String("1"); +} diff --git a/src/main/java/T/T2.java b/src/main/java/T/T2.java index b052a78..b46bc04 100644 --- a/src/main/java/T/T2.java +++ b/src/main/java/T/T2.java @@ -102,6 +102,7 @@ public static void main(String[] args) { for(int i :array){ System.out.println(i); } + } @Test public void te(){ diff --git a/src/main/java/operation/ScaleTest.java b/src/main/java/operation/ScaleTest.java new file mode 100644 index 0000000..af28612 --- /dev/null +++ b/src/main/java/operation/ScaleTest.java @@ -0,0 +1,28 @@ +package operation; + +import org.junit.Test; + +/** + * @author szh + * @create 2018-05-31 17:32 + **/ +public class ScaleTest { + public static void main(String[] args) { + System.out.println(Integer.toBinaryString(10)) ; + System.out.println(Integer.toBinaryString(10 >> 1)); +// System.out.println(5 ^ 10); + + } + @Test + public void hasAlternatingBits() { + int n=6; + int m= n ^ (n >>1); + if(n == 1){ + System.out.println(true); + } + if(m == n+(n/2) && m /2 !=0){ + System.out.println(true); + } + System.out.println(false); + } +} From 530551e489d69eaa608e5287abe3947610ee204a Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Thu, 26 Jul 2018 00:09:24 +0800 Subject: [PATCH 06/10] =?UTF-8?q?Leetcode=E4=B8=8A=E4=B8=A4=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Leetcode/MaxAreaofIsland.java | 49 +++++++++ .../MinimumAbsoluteDifferenceinBST.java | 102 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 src/main/java/Leetcode/MaxAreaofIsland.java create mode 100644 src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java diff --git a/src/main/java/Leetcode/MaxAreaofIsland.java b/src/main/java/Leetcode/MaxAreaofIsland.java new file mode 100644 index 0000000..18157b8 --- /dev/null +++ b/src/main/java/Leetcode/MaxAreaofIsland.java @@ -0,0 +1,49 @@ +package Leetcode; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author szh + * @create 2018-06-14 18:53 + **/ +public class MaxAreaofIsland { + public int maxAreaOfIsland(int[][] grid) { + List list =new ArrayList<>(); + for( int i =0 ;imax){ + max=i; + } + } + return max; + } + + public static void main(String[] args) { +// int[][] a =new int[][]{{1,1,0,0,0},{1,1,0,0,0},{0,0,0,1,1},{0,0,0,1,1}}; + int[][] a =new int[][]{{0},{0}}; + new MaxAreaofIsland().maxAreaOfIsland(a); + } +} diff --git a/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java b/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java new file mode 100644 index 0000000..43de540 --- /dev/null +++ b/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java @@ -0,0 +1,102 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-07-25 22:41 + **/ +public class MinimumAbsoluteDifferenceinBST { + + public int getMinimumDifference(TreeNode root) { + if(root != null){ + return compareTree(Integer.MAX_VALUE,root); + } + return 0; + } + public int compareTree(int min ,TreeNode node){ + + if(node.left != null){ + + TreeNode leftNode =node.left; + min=Math.min(min,compareTree(min,leftNode)); + int leftVal =Math.abs(node.val- node.left.val); + if(min > leftVal){ + min= leftVal; + } +// return compareTree(min,leftNode); + } + if(node.right != null){ + int rightVal =Math.abs(node.val- node.right.val); + if(min > rightVal){ + min= rightVal; + } + TreeNode rightNode =node.right; + min =Math.min(min,compareTree(min,rightNode)); + } + return min; + } + +// public int compareTreeV2(int min ,TreeNode root,TreeNode node){ +// +// int value = Math.abs(root.val - node.val); +// if(root.left != null){ +//// int leftVal =Math.abs(node.val- node.left.val); +//// if(min > leftVal){ +//// min= leftVal; +//// } +// TreeNode leftNode =node.left; +//// return compareTree(min,leftNode); +// } +// if(node.right != null){ +// int rightVal =Math.abs(node.val- node.right.val); +// if(min > rightVal){ +// min= rightVal; +// } +// TreeNode rightNode =node.right; +//// return compareTree(min,rightNode); +// } +// return min; +// } + int minDiff = Integer.MAX_VALUE; + TreeNode prev; + + public int getMinimum(TreeNode root) { + inorder(root); + return minDiff; + } + + public void inorder(TreeNode root) { + if (root == null) return; + inorder(root.left); + if (prev != null) minDiff = Math.min(minDiff, root.val - prev.val); + prev = root; + inorder(root.right); + } + + + public static void main(String[] args) { +// TreeNode t =new TreeNode(1); +// TreeNode t1 =new TreeNode(3); +// TreeNode t2 =new TreeNode(2); +// t1.left=t2; +// t.right=t1; + + TreeNode t =new TreeNode(236); + TreeNode t1 =new TreeNode(104); + TreeNode t2 =new TreeNode(227); + TreeNode t3 =new TreeNode(701); + TreeNode t4 =new TreeNode(911); + t1.right=t2; + t3.right=t4; + t.left=t1; + t.right=t3; +// System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimumDifference(t)); + System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimum(t)); + } + +} + class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode(int x) { val = x; } + } From ba2fccddf38bc1fa5fddad77ed7e6635e879e434 Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Thu, 16 Aug 2018 23:10:41 +0800 Subject: [PATCH 07/10] Leetcode --- .../java/Leetcode/CountBinarySubstrings.java | 31 ++++++++++ .../java/Leetcode/ExcelSheetColumnNumber.java | 33 ++++++++++ src/main/java/Leetcode/LemonadeChange.java | 50 ++++++++++++++++ .../MinimumAbsoluteDifferenceinBST.java | 60 ++++++++++++++----- src/main/java/Leetcode/RotateString.java | 30 ++++++++++ .../Leetcode/SearchinaBinarySearchTree.java | 44 ++++++++++++++ 6 files changed, 232 insertions(+), 16 deletions(-) create mode 100644 src/main/java/Leetcode/CountBinarySubstrings.java create mode 100644 src/main/java/Leetcode/ExcelSheetColumnNumber.java create mode 100644 src/main/java/Leetcode/LemonadeChange.java create mode 100644 src/main/java/Leetcode/RotateString.java create mode 100644 src/main/java/Leetcode/SearchinaBinarySearchTree.java diff --git a/src/main/java/Leetcode/CountBinarySubstrings.java b/src/main/java/Leetcode/CountBinarySubstrings.java new file mode 100644 index 0000000..c9c7015 --- /dev/null +++ b/src/main/java/Leetcode/CountBinarySubstrings.java @@ -0,0 +1,31 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-07-26 22:44 + **/ +public class CountBinarySubstrings { + public int countBinarySubstrings(String s) { + int[] groups = new int[s.length()]; + int t = 0; + groups[0] = 1; + for (int i = 1; i < s.length(); i++) { + if (s.charAt(i-1) != s.charAt(i)) { + groups[++t] = 1; + } else { + groups[t]++; + } + } + + int ans = 0; + for (int i = 1; i <= t; i++) { + ans += Math.min(groups[i-1], groups[i]); + } + return ans; + } + + public static void main(String[] args) { + String s ="00110011"; + System.out.println(new CountBinarySubstrings().countBinarySubstrings(s)); + } +} diff --git a/src/main/java/Leetcode/ExcelSheetColumnNumber.java b/src/main/java/Leetcode/ExcelSheetColumnNumber.java new file mode 100644 index 0000000..f008100 --- /dev/null +++ b/src/main/java/Leetcode/ExcelSheetColumnNumber.java @@ -0,0 +1,33 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-08-15 22:24 + **/ +public class ExcelSheetColumnNumber { + public static void main(String[] args) { + char c='A'; +// System.out.println(Math.abs(-64 + c)); + System.out.println(((int)Math.pow(26, 1))); + + System.out.println(new ExcelSheetColumnNumber().titleToNumber("AA")); + } + public int titleToNumber(String s) { + if(s == null || s.length() ==0){ + return 0; + } + int flag =-64; + int result=0; + int length =s.length(); + for(int i=0 ;i five =new Stack<>(); + Stack ten =new Stack<>(); + int[] money =new int[bills.length]; + for(int i =0 ;i<=bills.length ;i++){ + if(bills[i] == 5){ + five.push(bills[i]); + } + if(bills[i] == 10){ + ten.push(bills[i]); + if(five.size() == 0){ + return false; + } + five.pop(); + } + if(bills[i] == 20){ + if(five.size() == 0){ + return false; + } + if(ten.size() == 0){ + if(five.size() >=3){ + five.pop(); + five.pop(); + five.pop(); + }else{ + return false; + } + }else{ + ten.pop(); + five.pop(); + } + } + } + return true; + } + + public static void main(String[] args) { + int[] a= new int[]{5,5,5,10,5,5,10,20,20,20}; + new LemonadeChange().lemonadeChange(a); + } +} diff --git a/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java b/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java index 43de540..c540a1b 100644 --- a/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java +++ b/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java @@ -6,6 +6,33 @@ **/ public class MinimumAbsoluteDifferenceinBST { + TreeNode nodeval=null; + int min=Integer.MAX_VALUE; + + /////// + public int getMinimumDifferenceTwo(TreeNode root) { + if(root != null) + compareTreeNode(root); + return min; + } + public void compareTreeNode(TreeNode node){ + + if(node == null){ + return; + } + compareTreeNode(node.left); + if(nodeval != null){ + min =Math.min(node.val - nodeval.val ,min); + } + nodeval =node; + compareTreeNode(node.right); + } + + + + + + ///// public int getMinimumDifference(TreeNode root) { if(root != null){ return compareTree(Integer.MAX_VALUE,root); @@ -74,23 +101,24 @@ public void inorder(TreeNode root) { public static void main(String[] args) { -// TreeNode t =new TreeNode(1); -// TreeNode t1 =new TreeNode(3); -// TreeNode t2 =new TreeNode(2); -// t1.left=t2; -// t.right=t1; - - TreeNode t =new TreeNode(236); - TreeNode t1 =new TreeNode(104); - TreeNode t2 =new TreeNode(227); - TreeNode t3 =new TreeNode(701); - TreeNode t4 =new TreeNode(911); - t1.right=t2; - t3.right=t4; - t.left=t1; - t.right=t3; + TreeNode t =new TreeNode(1); + TreeNode t1 =new TreeNode(5); + TreeNode t2 =new TreeNode(3); + t1.left=t2; + t.right=t1; + +// TreeNode t =new TreeNode(236); +// TreeNode t1 =new TreeNode(104); +// TreeNode t2 =new TreeNode(227); +// TreeNode t3 =new TreeNode(701); +// TreeNode t4 =new TreeNode(911); +// t1.right=t2; +// t3.right=t4; +// t.left=t1; +// t.right=t3; // System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimumDifference(t)); - System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimum(t)); +// System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimum(t)); + System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimumDifferenceTwo(t)); } } diff --git a/src/main/java/Leetcode/RotateString.java b/src/main/java/Leetcode/RotateString.java new file mode 100644 index 0000000..9c8c1ad --- /dev/null +++ b/src/main/java/Leetcode/RotateString.java @@ -0,0 +1,30 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-08-16 22:48 + **/ +public class RotateString { + public boolean rotateString(String A, String B) { + String C = A +A ; + for(int i =0 ;i< C.length() ;i++){ + int index =i; + int j=0; + for(;j val){ + return compareAndSelect(root.left,val); + }else{ + return compareAndSelect(root.right,val); + } + } + public TreeNode compareAndSelect(TreeNode node , int val){ + if(node == null){ + return null; + } + if(node.val == val){ + return node; + } + if(node.val >val){ + return compareAndSelect(node.left,val); + }else{ + return compareAndSelect(node.right,val); + } + } + + class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } + } +} From f4d23a33496ee3c77022238c7b02442ee0757c84 Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Sat, 18 Aug 2018 00:06:30 +0800 Subject: [PATCH 08/10] Leetcode --- src/main/java/Leetcode/RotateString.java | 35 ++++++++++++++++- src/main/java/Leetcode/bitand2bitCharac.java | 40 ++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/main/java/Leetcode/bitand2bitCharac.java diff --git a/src/main/java/Leetcode/RotateString.java b/src/main/java/Leetcode/RotateString.java index 9c8c1ad..bd5ea95 100644 --- a/src/main/java/Leetcode/RotateString.java +++ b/src/main/java/Leetcode/RotateString.java @@ -1,5 +1,7 @@ package Leetcode; +import java.math.BigInteger; + /** * @author szh * @create 2018-08-16 22:48 @@ -23,8 +25,39 @@ public boolean rotateString(String A, String B) { } return false; } + public boolean rotateStringHash(String A, String B) { + if (A.equals(B)) return true; + + int MOD = 1_000_000_007; + int P = 113; + int Pinv = BigInteger.valueOf(P).modInverse(BigInteger.valueOf(MOD)).intValue(); + + long hb = 0, power = 1; + for (char x: B.toCharArray()) { + hb = (hb + power * x) % MOD; + power = power * P % MOD; + } + + long ha = 0; power = 1; + char[] ca = A.toCharArray(); + for (char x: ca) { + ha = (ha + power * x) % MOD; + power = power * P % MOD; + } + for (int i = 0; i < ca.length; ++i) { + char x = ca[i]; + ha += power * x - x; + ha %= MOD; + ha *= Pinv; + ha %= MOD; + if (ha == hb && (A.substring(i+1) + A.substring(0, i+1)).equals(B)) + return true; + + } + return false; + } public static void main(String[] args) { - System.out.println(new RotateString().rotateString("abcde", "abced")); + System.out.println(new RotateString().rotateStringHash("abcde", "abced")); } } diff --git a/src/main/java/Leetcode/bitand2bitCharac.java b/src/main/java/Leetcode/bitand2bitCharac.java new file mode 100644 index 0000000..3a65bcc --- /dev/null +++ b/src/main/java/Leetcode/bitand2bitCharac.java @@ -0,0 +1,40 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-08-17 22:50 + **/ +public class bitand2bitCharac { + public boolean isOneBitCharacter(int[] bits) { + int len =bits.length; + if(bits == null || bits.length == 0){ + return false; + } + if(len == 1 && bits[len-1] == 0){ + return true; + } + if(len == 2 && bits[0] == 0){ + return true; + }else if(bits[0] == 1){ + return false; + } + if(len >=3){ + if(len % 2 == 0){ + if(bits[len-2] == 1){ + return false; + }else{ + return true; + } + }else{ + if(bits[len-3] == 1){ + return true; + } + } + } + return false; + } + + public static void main(String[] args) { + new bitand2bitCharac().isOneBitCharacter(new int[]{1,0,0}); + } +} From 7b2f78896046cdd0397aeba4ae26e272931dc274 Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Sat, 18 Aug 2018 23:56:53 +0800 Subject: [PATCH 09/10] Leetcode --- src/main/java/Leetcode/MostCommonWord.java | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/Leetcode/MostCommonWord.java diff --git a/src/main/java/Leetcode/MostCommonWord.java b/src/main/java/Leetcode/MostCommonWord.java new file mode 100644 index 0000000..93d6e64 --- /dev/null +++ b/src/main/java/Leetcode/MostCommonWord.java @@ -0,0 +1,51 @@ +package Leetcode; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author szh + * @create 2018-08-18 23:31 + **/ +public class MostCommonWord { + public static void main(String[] args) { + new MostCommonWord().mostCommonWord("Bob hit a ball, the hit BALL flew far after it was hit.", new String[]{"hit"}); + } + + public String mostCommonWord(String paragraph, String[] banned) { + String[] words = paragraph.split(" "); + Set set = new HashSet<>(); + for (String s : banned) { + set.add(s); + } + Map map = new HashMap<>(); + for (String word : words) { + StringBuffer sb = new StringBuffer(); + char[] cArray = word.toCharArray(); + for (char c : cArray) { + if (Character.isLetter(c)) { + sb.append(c); + } + } + // word= word.replace(",",""); + // word= word.replace(".",""); + word = sb.toString(); + word = word.toLowerCase(); + map.put(word, map.get(word) == null ? 1 : map.get(word) + 1); + } + for (String s : set) { + map.remove(s); + } + String max = null; + int maxNum = 0; + for (Map.Entry temp : map.entrySet()) { + if ((int) temp.getValue() > maxNum) { + maxNum = (int) temp.getValue(); + max = (String) temp.getKey(); + } + } + return max; + } +} From bf4ea40546a2872089dee42ef4e20d88aeaed566 Mon Sep 17 00:00:00 2001 From: "somersames@gmail.com" Date: Mon, 17 Sep 2018 22:47:10 +0800 Subject: [PATCH 10/10] add Leetcode --- src/main/java/Interesting/ADDTest.class | Bin 0 -> 433 bytes src/main/java/Interesting/ADDTest.java | 15 ++++ src/main/java/Leetcode/AssignCookies.java | 25 ++++++ .../java/Leetcode/BackspaceStringCompare.java | 47 ++++++++++++ src/main/java/Leetcode/ContainsDuplicate.java | 30 ++++++++ .../MinimumDistanceBetweenBSTNodes.java | 58 ++++++++++++++ src/main/java/Leetcode/MissingNumber.java | 29 +++++++ .../java/Leetcode/NumberofBoomerangs.java | 72 ++++++++++++++++++ .../java/Leetcode/PositionsofLargeGroups.java | 36 +++++++++ .../Leetcode/StudentAttendanceRecord.java | 67 ++++++++++++++++ src/main/java/OperationTest/IntAndChar.java | 14 ++++ src/main/java/maxwellTest/IndexTest.java | 23 ++++++ 12 files changed, 416 insertions(+) create mode 100644 src/main/java/Interesting/ADDTest.class create mode 100644 src/main/java/Interesting/ADDTest.java create mode 100644 src/main/java/Leetcode/AssignCookies.java create mode 100644 src/main/java/Leetcode/BackspaceStringCompare.java create mode 100644 src/main/java/Leetcode/ContainsDuplicate.java create mode 100644 src/main/java/Leetcode/MinimumDistanceBetweenBSTNodes.java create mode 100644 src/main/java/Leetcode/MissingNumber.java create mode 100644 src/main/java/Leetcode/NumberofBoomerangs.java create mode 100644 src/main/java/Leetcode/PositionsofLargeGroups.java create mode 100644 src/main/java/Leetcode/StudentAttendanceRecord.java create mode 100644 src/main/java/OperationTest/IntAndChar.java create mode 100644 src/main/java/maxwellTest/IndexTest.java diff --git a/src/main/java/Interesting/ADDTest.class b/src/main/java/Interesting/ADDTest.class new file mode 100644 index 0000000000000000000000000000000000000000..01da6fc788aae03fb85760e85a9ba06b18851dd9 GIT binary patch literal 433 zcmY*VT}uK%6g^kh9bMOtH0{HJeA6Dl0c9O6kmF2wLwPQ-B`z<_x?~l6!g#! z=to6&wm=-1d+yvh_sp65{qy++;1mr985DCUq3mD_6@jY2Ho@+yQ0a3*y44;Ntjp*@ z5=sLV%Ij4yk@3i%EVyC?z6uHT*4<$4Kl$Fm4`<#`$10q4OrtZ5R`FC`DMNNIdcBcc z>JvkCVM7SiT-326uDs$M9fNo#{j`G%cny|V$2+WfL=Kv map =new HashMap<>(); + for(int i : g){ + map.put(i,map.get(i) == null? 1: map.get(i)+1); + } + int result=0; + for(int i :s){ + if(map.get(i) != null && map.get(i) !=0){ + map.put(i,map.get(i)-1); + result++; + } + } + return result; + } +} diff --git a/src/main/java/Leetcode/BackspaceStringCompare.java b/src/main/java/Leetcode/BackspaceStringCompare.java new file mode 100644 index 0000000..babb7ee --- /dev/null +++ b/src/main/java/Leetcode/BackspaceStringCompare.java @@ -0,0 +1,47 @@ +package Leetcode; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Stack; + +/** + * @author szh + * @create 2018-09-17 21:10 + **/ +public class BackspaceStringCompare { + public static void main(String[] args) { + new BackspaceStringCompare().backspaceCompare("ab#c","ad#c"); + } + public boolean backspaceCompare(String S, String T) { + Stack SU = new Stack<>(); + Stack TU = new Stack<>(); + char[] s1 =S.toCharArray(); + char[] t1 =T.toCharArray(); + for(int i =0 ; i < s1.length ;i++){ + if(s1[i] == '#'){ + if(!SU.isEmpty()){ + SU.pop(); + } + }else{ + SU.add(s1[i]); + } + } + for(int i =0 ; i < t1.length ;i++){ + if(t1[i] == '#'){ + if(!TU.isEmpty()){ + TU.pop(); + } + }else{ + TU.add(t1[i]); + } + } + while(!SU.isEmpty() && !TU.isEmpty()){ + if(SU.pop() == TU.pop()){ + continue; + }else{ + return false; + } + } + return SU.isEmpty() && TU.isEmpty() ? true :false; + } +} diff --git a/src/main/java/Leetcode/ContainsDuplicate.java b/src/main/java/Leetcode/ContainsDuplicate.java new file mode 100644 index 0000000..1d3534f --- /dev/null +++ b/src/main/java/Leetcode/ContainsDuplicate.java @@ -0,0 +1,30 @@ +package Leetcode; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author szh + * @create 2018-08-19 14:51 + **/ +public class ContainsDuplicate { + public boolean containsDuplicate(int[] nums) { + // for(int i =0 ;i set =new HashSet<>(); + for(int i=0 ;i map =new HashMap<>(); + int res=0; + for(int i =0 ;i< points.length ;i++){ + for(int j=0 ;j< points.length ;j++){ + if(i == j){ + continue; + } + int ditance =getDistance(points[i],points[j]); + map.put(ditance,map.getOrDefault(ditance,0)+1); + } + for(int val :map.values()){ + res+=(val*2); + } + map.clear(); + } + return res; + + } + public int getDistance(int[] a ,int[] b){ + // int dx =(a[0]-b[0]) < 0 ? b[0]- a[0] :a[0]-b[0]; + int dx =a[0]-b[0]; + // int dy=(a[1]-b[1]) < 0 ? b[1]- a[1] :a[1]-b[1]; + int dy=a[1]-b[1] ; + return dx* dx + dy *dy; + } + + public static void main(String[] args) { +// int[][] a =new int[][]{new int[]{0,0},new int[]{0,0},new int[]{0,0}}; + int[][] a =new int[][]{{0,0},{1,0},{2,0}}; + new NumberofBoomerangs().numberOfBoomerangs(a); + new NumberofBoomerangs().numberOfBoomerangs2(a); + } + public int numberOfBoomerangs2(int[][] points) { + int res = 0; + + Map map = new HashMap<>(); + for(int i=0; i map =new HashMap<>(); + new PositionsofLargeGroups().largeGroupPositions(s); +; } + public List> largeGroupPositions(String S) { + char[] c =S.toCharArray(); + List> result =new ArrayList<>(); + int start =0; + for(int i =1 ;i=3){ + List temp =new ArrayList<>(); + temp.add(start); + temp.add(i-1); + result.add(temp); + } + start =i; + } + } + return result; + } +} diff --git a/src/main/java/Leetcode/StudentAttendanceRecord.java b/src/main/java/Leetcode/StudentAttendanceRecord.java new file mode 100644 index 0000000..033edb7 --- /dev/null +++ b/src/main/java/Leetcode/StudentAttendanceRecord.java @@ -0,0 +1,67 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-09-15 21:53 + **/ +public class StudentAttendanceRecord { + public static void main(String[] args) { +// char c1 = 'A'; +// char c2 = 'P'; +// char c3 = 'C'; +// System.out.println(c1 == 1); +// System.out.println(c1 ^ c2); +// int[] i = new int[10]; +// System.out.println('C' ^ 1); +// System.out.println('C' ^ 2); +// System.out.println('C' ^ 3); +// System.out.println('C' ^ 4); +// System.out.println('C' | 1); +// System.out.println('C' | 2); +// System.out.println('C' | 3); +// System.out.println('C' | 4); +// System.out.println('C' ^ 5); +// System.out.println('C' ^ 6); +// System.out.println('C' ^ 7); +// System.out.println('C' ^ 8); +// System.out.println('C' ^ 9); +// System.out.println('C' ^ 10); +// System.out.println('C' ^ 11); +// System.out.println('C' ^ 12); +// System.out.println('C' ^ 13); +// int count =0; +// System.out.println(upLouti(0, 20)); +// System.out.println(count); +// int[] a = new int[21]; +// a[0] = 1; +// a[1] = 1; +// a[2] = 1; +// +// for (int i = 3; i <= 20; i++) { +// a[i] = a[i-1] + a[i-3]; +// System.out.println(i + " " + a[i]); +// } + System.out.println(puCiZhuan(0, 20)); + } + + + private static int upLouti(int step ,int end ){ + if(step == end || step == end -1 ){ + return 1; + } + return upLouti(step+1,end) + upLouti(step+2,end); + } + + private static int puCiZhuan(int step ,int end){ + if(step >= end){ + return 0; + } + if(step == end -1){ + return 1; + } + if(step == end -3){ + return 2; + } + return puCiZhuan(step+1,end) + puCiZhuan(step + 3 ,end); + } +} diff --git a/src/main/java/OperationTest/IntAndChar.java b/src/main/java/OperationTest/IntAndChar.java new file mode 100644 index 0000000..cafc139 --- /dev/null +++ b/src/main/java/OperationTest/IntAndChar.java @@ -0,0 +1,14 @@ +package OperationTest; + +/** + * @author szh + * @create 2018-06-08 23:30 + **/ +public class IntAndChar { + public static void main(String[] args) { + char c='C'; + System.out.println(90 - c); + String s ="qwert"; + System.out.println(s.substring(0, 2)); + } +} diff --git a/src/main/java/maxwellTest/IndexTest.java b/src/main/java/maxwellTest/IndexTest.java new file mode 100644 index 0000000..95e7819 --- /dev/null +++ b/src/main/java/maxwellTest/IndexTest.java @@ -0,0 +1,23 @@ +package maxwellTest; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 关于列表按照索引插入 + * + * @author szh + * @create 2018-09-02 13:37 + **/ +public class IndexTest { + public static void main(String[] args) { + List list =new ArrayList<>(); + list.add(2,2); + Map map =new HashMap<>(); + for(int i : map.values()){ + + } + } +}