From 03d8198f7830e3133899ec8a6a3a7c18ccf0c37c Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Thu, 16 Mar 2017 18:21:35 +0800 Subject: [PATCH 01/27] =?UTF-8?q?1=E3=80=81concurrentHashmap=E7=A0=94?= =?UTF-8?q?=E7=A9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConcurrentHashMapTestList.java | 37 +++++++++++++++++++ .../viewer/collections/HashMapTestList.java | 5 +++ 2 files changed, 42 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/collections/ConcurrentHashMapTestList.java diff --git a/jlh/src/main/java/com/jlh/viewer/collections/ConcurrentHashMapTestList.java b/jlh/src/main/java/com/jlh/viewer/collections/ConcurrentHashMapTestList.java new file mode 100644 index 0000000..3d77a68 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/collections/ConcurrentHashMapTestList.java @@ -0,0 +1,37 @@ +package com.jlh.viewer.collections; + +import java.util.Hashtable; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Created by jlh + * On 2017/3/15 0015. + */ +public class ConcurrentHashMapTestList { + public static void main(String[] args) { + + /* + * + * 并发三大特性: + * 原子性 + * 可见性, + * 重排序 + * + * JDK1.8 以下 + * concurrent 每次访问只对某一个segment加锁 使用lock 来实现, + * 因此其他线程访问不同segment 不会阻塞,性能高 + * segment --> tb1 -->tb2 + * segment --> tb1 + * segment --> + * JDK1.8 + * concurrent Treebin对象,代替treenode ,包涵锁的功能,链表长了以后使用treebin对象, + * 也就是代替了树的根节点,其余节点为treenode + * 对段(segment)的锁定是通过 synchronized 来完成 (写操作) 读操作通过cas完成 + * hashtable是对整个操作进行 synchronized 所以,每次操作都会锁整个对象,性能差 + * */ + Hashtable hashtable = new Hashtable(); + ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap(); + for (int i=0;i<14;i++) + concurrentHashMap.put("key_"+i,"huaizuo_" + i); + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/collections/HashMapTestList.java b/jlh/src/main/java/com/jlh/viewer/collections/HashMapTestList.java index 5950582..08afe8e 100644 --- a/jlh/src/main/java/com/jlh/viewer/collections/HashMapTestList.java +++ b/jlh/src/main/java/com/jlh/viewer/collections/HashMapTestList.java @@ -9,6 +9,11 @@ import java.util.HashMap; */ public class HashMapTestList { public static void main(String[] args) { + /* + * JDK 1.8 + * concurrent 不再仅仅是数组+链表,而是数组+链表+红黑树 链表大于8自动转为红黑树 + */ + //linkedHashMap 与hashmap的区别是,增加了记录插入顺序,遍历时可以按插入顺序遍历 // 负载0.75 默认16capacity Entry bucket[] ---> Entry-->Entry--->....Entry 数组+链表 链表地址法 // threshold(临界值) = 负载*capacity iterator 保证快速失败--> volatile modcount 保持可见性 新增和删除操作+1 修改不变 HashMap map=new HashMap<>(); -- Gitee From ff2ce2ae6ca5b1b73b29bf0979ce1928bb22f022 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Fri, 17 Mar 2017 13:44:12 +0800 Subject: [PATCH 02/27] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B-?= =?UTF-8?q?=E5=A0=86=20=E8=87=AA=E6=88=91=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java b/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java index f6239e0..8f71624 100644 --- a/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java @@ -7,12 +7,10 @@ import java.lang.reflect.Array; * On 2017/3/15 0015. */ public class MHeap { - private Class type; private T[] datas; private int store; - public MHeap(int size,Class type){ - this.type=type; - datas= (T[]) Array.newInstance(type,size); + public MHeap(int size){ + datas= (T[]) Array.newInstance(Comparable.class,size); store=0; } public boolean push (T d){ @@ -61,7 +59,7 @@ public class MHeap { } public static void main(String[] args) { - MHeap mHeap = new MHeap<>(15,Integer.class); + MHeap mHeap = new MHeap<>(15); mHeap.push(5); mHeap.push(3); mHeap.push(6); -- Gitee From 98cecfb3a76a99b27ffffe64a0072ba3560f0991 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Fri, 17 Mar 2017 17:28:29 +0800 Subject: [PATCH 03/27] =?UTF-8?q?=E7=BA=A2=E9=BB=91=E6=A0=91=EF=BC=88?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=8C=E5=8F=94=E7=88=B6=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E4=B8=BA=E7=BA=A2=E8=89=B2=E8=BF=98=E6=9C=AA=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jlh/viewer/algorithm/TreeBin.java | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/algorithm/TreeBin.java diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/TreeBin.java b/jlh/src/main/java/com/jlh/viewer/algorithm/TreeBin.java new file mode 100644 index 0000000..b6cdea3 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/TreeBin.java @@ -0,0 +1,189 @@ +package com.jlh.viewer.algorithm; + +/** + * Created by jlh + * On 2017/3/17 0017. + */ +public class TreeBin { + private static final boolean BLACK=true; + private static final boolean RED=false; + private TreeNode root; + private Integer size; + + public TreeBin() { + root=new TreeNode(); + root.color=BLACK; + root.left=null; + root.right=null; + root.parent=null; + size=0; + } + + public boolean push (T v){ + TreeNode node = findNode(v); + node.value=v; + size++; + adjust(node); + return true; + } + + + private void adjust(TreeNode t){ + TreeNode parent,gparent; + while ((parent=t.parent)!=null&&parent.color==RED){ + gparent=parent.parent; + //父节点是祖父节点的左节点 + if (parent==gparent.left){ + TreeNode uncle= gparent.right; + //1. 叔叔节点是黑色的 节点是父节点的左子树 + if((uncle==null||uncle.color==BLACK)&&(t==parent.left)){ + parent.color=BLACK; + gparent.color=RED; + rightRotate(gparent); + } + // 叔叔是黑色的 节点是父节点的右子树 + else if ((uncle==null||uncle.color==BLACK)&&t==parent.right){ + t.color=BLACK; + gparent.color=RED; + leftRotate(parent); + rightRotate(gparent); + } + + }else {//父节点是祖父节点的右节点 + TreeNode uncle= gparent.left; + // 叔叔是黑色的 节点是父节点的右子树 + if((uncle==null||uncle.color==BLACK)&&(t==parent.right)){ + parent.color=BLACK; + gparent.color=RED; + leftRotate(gparent); + } + // 叔叔是黑色的 节点是父节点的左子树 + else if ((uncle==null||uncle.color==BLACK)&&t==parent.left){ + t.color=BLACK; + gparent.color=RED; + rightRotate(parent); + leftRotate(gparent); + } + + } + } + root.color=BLACK; + } + + private void leftRotate(TreeNode x){ + // 设置x的右孩子为y + TreeNode y = x.right; + + // 将 “y的左孩子” 设为 “x的右孩子”; + // 如果y的左孩子非空,将 “x” 设为 “y的左孩子的父亲” + x.right = y.left; + if (y.left != null) + y.left.parent = x; + + // 将 “x的父亲” 设为 “y的父亲” + y.parent = x.parent; + + if (x.parent == null) { + this.root = y; // 如果 “x的父亲” 是空节点,则将y设为根节点 + } else { + if (x.parent.left == x) + x.parent.left = y; // 如果 x是它父节点的左孩子,则将y设为“x的父节点的左孩子” + else + x.parent.right = y; // 如果 x是它父节点的左孩子,则将y设为“x的父节点的左孩子” + } + + // 将 “x” 设为 “y的左孩子” + y.left = x; + // 将 “x的父节点” 设为 “y” + x.parent = y; + } + + private void rightRotate(TreeNode y){ + TreeNode x= y.left; + y.left=x.right; + if (x.right!=null){ + x.right.parent=y; + } + x.parent=y.parent; + if (y.parent==null){ + root=x; + }else { + if (y.parent.left==y) + y.parent.left=x; + else + y.parent.right=x; + } + x.right=y; + y.parent=x; + } + + private TreeNode findNode(T v){ + if (size.equals(0)) + return root; + TreeNode p = root; + while (true){ + if (p.value.compareTo(v)>0&&p.left!=null) + p=p.left; + else if (p.value.compareTo(v)>0&&p.left==null){ + p.left=createChild(p); + return p.left; + } + else if (p.value.compareTo(v)<=0&&p.right!=null) + p=p.right; + else if (p.value.compareTo(v)<=0&&p.right==null){ + p.right=createChild(p); + return p.right; + } + + } + } + + private TreeNode createChild(TreeNode p){ + TreeNode child= new TreeNode(); + child.left=null; + child.right=null; + child.parent=p; + return child; + } + + + public static void main(String[] args) { + TreeBin treeBin = new TreeBin<>(); + treeBin.push(2); + treeBin.push(1); + treeBin.push(3); + treeBin.push(4); + System.out.println(treeBin); + } + private static class TreeNode { + /** + * 节点的颜色,false代表红色,true代表黑色 + */ + private Boolean color =RED ; + /** + * 节点值 + */ + private K value; + /** + * 左节点 + */ + private TreeNode left; + /** + * 右节点 + */ + private TreeNode right; + /** + * 父节点 + */ + private TreeNode parent; + + } + + @Override + public String toString() { + return "TreeBin{" + + "root=" + root + + ", size=" + size + + '}'; + } +} -- Gitee From 0914bcd2b2c4e96cf0a3a6073926179913990d55 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Sat, 25 Mar 2017 13:56:53 +0800 Subject: [PATCH 04/27] =?UTF-8?q?1=E3=80=81JAVA=20memory=20leak=20study?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/jlh/viewer/acm/Main.java | 29 +++++++++++++++++++ .../java/com/jlh/viewer/algorithm/MHeap.java | 12 +++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/Main.java diff --git a/jlh/src/main/java/com/jlh/viewer/acm/Main.java b/jlh/src/main/java/com/jlh/viewer/acm/Main.java new file mode 100644 index 0000000..b81d81b --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/Main.java @@ -0,0 +1,29 @@ +package com.jlh.viewer.acm; + + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/3/19. + * 19:44 + */ +import java.util.Arrays; +import java.util.HashSet; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while(sc.hasNext()){ + HashSet hashSet = new HashSet<>(); + int n= sc.nextInt(); + sc.nextLine(); + for (int i=0;i { datas[b]=temp; } - public static void main(String[] args) { + public static void main(String[] args) throws UnsupportedEncodingException { MHeap mHeap = new MHeap<>(15,Integer.class); mHeap.push(5); mHeap.push(3); mHeap.push(6); System.out.println(mHeap.pop()); + printByte("中文".getBytes()); + printByte("中文".getBytes("utf-8")); + } + + public static void printByte (byte[] bytes){ + for (byte b:bytes){ + System.out.print(b); + } + System.out.println(); } } -- Gitee From ad554044888377014d11a3bfbfbd82c448ec03d9 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Sat, 25 Mar 2017 13:59:55 +0800 Subject: [PATCH 05/27] =?UTF-8?q?interface=20=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java diff --git a/jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java b/jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java new file mode 100644 index 0000000..3e8fc2f --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java @@ -0,0 +1,10 @@ +package com.jlh.viewer.interfaceT; + +/** + * com.jlh.viewer.interfaceT + * Created by ASUS on 2017/3/25. + * 13:59 + */ +public interface Test { + abstract void test(); +} -- Gitee From c9b1df8bd0b43d290d53ebc81027276a098faea7 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Wed, 29 Mar 2017 13:44:52 +0800 Subject: [PATCH 06/27] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A0=86=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E4=B8=AD=20push=20=E8=B0=83=E6=95=B4=E5=A0=86?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jlh/viewer/algorithm/MHeap.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java b/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java index c51894e..d8c3401 100644 --- a/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/MHeap.java @@ -19,7 +19,7 @@ public class MHeap { int k=store; datas[store++]=d; if (k>=1) { - adjust((k-1)/2); + adjust2((k-1)/2); } } return false; @@ -35,6 +35,23 @@ public class MHeap { return null; } + private void adjust2(int parent){ + int l=parent*2+1; + int r=parent*2+2; + int index = parent; + if (l { mHeap.push(5); mHeap.push(3); mHeap.push(6); - System.out.println(mHeap.pop()); + mHeap.push(7); + mHeap.push(2); + mHeap.push(9); + while (mHeap.store>0) + System.out.println(mHeap.pop()); } } -- Gitee From 84b674ac3ee53ba687bda50dbc1e53b9608c4339 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Fri, 31 Mar 2017 16:49:06 +0800 Subject: [PATCH 07/27] =?UTF-8?q?java=209=20=E8=AF=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/pom.xml | 12 +++++ jlh/src/main/java/com/jlh/jdk9/http/Main.java | 25 ++++++++++ .../main/java/com/jlh/jdk9/process/Main.java | 22 +++++++++ .../main/java/com/jlh/jdk9/trywith/Main.java | 19 ++++++++ jlh/src/main/java/com/jlh/viewer/Test.java | 26 +++++++++++ .../main/java/com/jlh/viewer/acm/Main.java | 46 ++++++++++++++----- .../java/com/jlh/viewer/http/httpsUtils.java | 8 ++++ .../java/com/jlh/viewer/interfaceT/Test.java | 3 ++ jlh/src/main/java/module-info.java | 8 ++++ 9 files changed, 158 insertions(+), 11 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/jdk9/http/Main.java create mode 100644 jlh/src/main/java/com/jlh/jdk9/process/Main.java create mode 100644 jlh/src/main/java/com/jlh/jdk9/trywith/Main.java create mode 100644 jlh/src/main/java/com/jlh/viewer/Test.java create mode 100644 jlh/src/main/java/com/jlh/viewer/http/httpsUtils.java create mode 100644 jlh/src/main/java/module-info.java diff --git a/jlh/pom.xml b/jlh/pom.xml index 5919466..5d6b30b 100644 --- a/jlh/pom.xml +++ b/jlh/pom.xml @@ -10,6 +10,18 @@ 4.0.0 jlh + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.9 + 1.9 + + + + \ No newline at end of file diff --git a/jlh/src/main/java/com/jlh/jdk9/http/Main.java b/jlh/src/main/java/com/jlh/jdk9/http/Main.java new file mode 100644 index 0000000..eec6e43 --- /dev/null +++ b/jlh/src/main/java/com/jlh/jdk9/http/Main.java @@ -0,0 +1,25 @@ +package com.jlh.jdk9.http; + + +import jdk.incubator.http.HttpClient; +import jdk.incubator.http.HttpRequest; +import jdk.incubator.http.HttpResponse; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; + +/** + * Created by jlh + * On 2017/3/31 0031. + */ +public class Main { + public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException { + URI httpURI= new URI("https://www.baidu.com"); + HttpRequest request = HttpRequest.newBuilder(httpURI).GET().build(); + HttpClient httpClient = HttpClient.newHttpClient(); + HttpResponse response=httpClient.send(request, (statusCode, responseHeaders) -> HttpResponse.BodyProcessor.asString(Charset.forName("UTF-8"))); + System.out.println(response); + } +} diff --git a/jlh/src/main/java/com/jlh/jdk9/process/Main.java b/jlh/src/main/java/com/jlh/jdk9/process/Main.java new file mode 100644 index 0000000..6fac807 --- /dev/null +++ b/jlh/src/main/java/com/jlh/jdk9/process/Main.java @@ -0,0 +1,22 @@ +package com.jlh.jdk9.process; + +import java.time.Duration; +import java.time.Instant; +import java.util.Optional; + +/** + * Created by jlh + * On 2017/3/31 0031. + */ +public class Main { + public static void main(String[] args) { + ProcessHandle processHandle = ProcessHandle.current(); + long PID = processHandle.getPid(); + System.out.println(PID); + ProcessHandle.Info procInfo = processHandle.info(); + Optional argsp = procInfo.arguments(); + Optional cmd = procInfo.commandLine(); + Optional startTime = procInfo.startInstant(); + Optional cpuUsage = procInfo.totalCpuDuration(); + } +} diff --git a/jlh/src/main/java/com/jlh/jdk9/trywith/Main.java b/jlh/src/main/java/com/jlh/jdk9/trywith/Main.java new file mode 100644 index 0000000..5d37c61 --- /dev/null +++ b/jlh/src/main/java/com/jlh/jdk9/trywith/Main.java @@ -0,0 +1,19 @@ +package com.jlh.jdk9.trywith; + +import java.io.IOException; +import java.io.InputStream; + +/** + * Created by jlh + * On 2017/3/31 0031. + */ +public class Main { + public static void main(String[] args) throws IOException { + InputStream in = System.in; + try (in){ + System.out.println(in.read()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java new file mode 100644 index 0000000..74ac2ad --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -0,0 +1,26 @@ +package com.jlh.viewer; + +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Scanner; + +/** + * Created by jlh + * On 2017/3/24 0024. + */ + + +public class Test { + public static void main(String[] args) throws IOException { + Double a = Double.MAX_VALUE; + System.out.println(String.valueOf(a)); + BigDecimal c=new BigDecimal(a); + System.out.println(c); + System.out.println(Long.MAX_VALUE); + + String ares="abbabc"; + Scanner sc = new Scanner(System.in); + while (sc.hasNext()) + System.out.println(sc.nextByte(3)); + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/acm/Main.java b/jlh/src/main/java/com/jlh/viewer/acm/Main.java index b81d81b..51baf8d 100644 --- a/jlh/src/main/java/com/jlh/viewer/acm/Main.java +++ b/jlh/src/main/java/com/jlh/viewer/acm/Main.java @@ -6,24 +6,48 @@ package com.jlh.viewer.acm; * Created by ASUS on 2017/3/19. * 19:44 */ -import java.util.Arrays; -import java.util.HashSet; + import java.util.Scanner; +import java.util.Stack; public class Main { + private static int[][] arr=new int[1005][1005]; + private static boolean[] is=new boolean[1005]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ - HashSet hashSet = new HashSet<>(); - int n= sc.nextInt(); - sc.nextLine(); - for (int i=0;i stack = new Stack<>(); + stack.push(1); + is[1]=true; + int res=0; + while (!stack.empty()){ + int i = stack.pop(); + for (int j=1;j<=n;j++){ + if (arr[i][j]==1&& !is[j]){ + stack.push(j); + is[j]=true; + res++; + } + } } - System.out.println(hashSet.size()); + System.out.println(res); + } + } + + public static void init(int n){ + for (int i=0;i<=n;i++) { + is[i]=false; + for (int j = 0; j <= n; j++) + arr[i][j] = 0; } } } \ No newline at end of file diff --git a/jlh/src/main/java/com/jlh/viewer/http/httpsUtils.java b/jlh/src/main/java/com/jlh/viewer/http/httpsUtils.java new file mode 100644 index 0000000..7c34851 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/http/httpsUtils.java @@ -0,0 +1,8 @@ +package com.jlh.viewer.http; + +/** + * Created by jlh + * On 2017/3/29 0029. + */ +public class httpsUtils { +} diff --git a/jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java b/jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java index 3e8fc2f..1cf2b25 100644 --- a/jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/interfaceT/Test.java @@ -7,4 +7,7 @@ package com.jlh.viewer.interfaceT; */ public interface Test { abstract void test(); + static String pr(){ + return "2333"; + } } diff --git a/jlh/src/main/java/module-info.java b/jlh/src/main/java/module-info.java new file mode 100644 index 0000000..c61131a --- /dev/null +++ b/jlh/src/main/java/module-info.java @@ -0,0 +1,8 @@ +/** + * Created by jlh + * On 2017/3/31 0031. + * + */ +module jlh { + requires jdk.incubator.httpclient; +} \ No newline at end of file -- Gitee From 41a8f22e79a432d8b8b85afc0479dfe3aa88d528 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Wed, 5 Apr 2017 10:58:14 +0800 Subject: [PATCH 08/27] =?UTF-8?q?base64=20=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jlh/viewer/base64/Base64Utils.java | 16 +++++ .../main/java/com/jlh/viewer/base64/Main.java | 71 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/base64/Base64Utils.java create mode 100644 jlh/src/main/java/com/jlh/viewer/base64/Main.java diff --git a/jlh/src/main/java/com/jlh/viewer/base64/Base64Utils.java b/jlh/src/main/java/com/jlh/viewer/base64/Base64Utils.java new file mode 100644 index 0000000..531dc45 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/base64/Base64Utils.java @@ -0,0 +1,16 @@ +package com.jlh.viewer.base64; + +import java.util.Base64; + +/** + * Created by jlh + * On 2017/4/5 0005. + */ +public class Base64Utils { + public static String encode(byte[] context){ + return Base64.getEncoder().encodeToString(context); + } + public static byte[] decode (String context){ + return Base64.getDecoder().decode(context); + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/base64/Main.java b/jlh/src/main/java/com/jlh/viewer/base64/Main.java new file mode 100644 index 0000000..f7b26ed --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/base64/Main.java @@ -0,0 +1,71 @@ +package com.jlh.viewer.base64; + +import java.io.*; + +/** + * Created by jlh + * On 2017/4/5 0005. + */ +public class Main { + public static void main(String[] args) { + byte[] data = null; + byte[] buffer= new byte[1024]; + File file = new File("D:\\test\\orignal.jpg"); + try (FileInputStream in = new FileInputStream(file);ByteArrayOutputStream byteArrayOutputStream= new ByteArrayOutputStream(1024)){ + int size=0; + while ((size=in.read(buffer))!=-1){ + byteArrayOutputStream.write(buffer,0,size); + } + data=byteArrayOutputStream.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + } + String encode= Base64Utils.encode(data); + //存储 + + File codeFile = new File("D:\\test\\code.txt"); + if (codeFile.exists()) + codeFile.delete(); + try { + codeFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + + try(FileWriter fileWriter = new FileWriter(codeFile)) { + fileWriter.write(encode); + fileWriter.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + //输出解密图片 + File decodeFile = new File("D:\\test\\decode.jpg"); + if (decodeFile.exists()) + decodeFile.delete(); + try { + decodeFile.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } + String codeContext= null; + try (FileReader reader = new FileReader(codeFile)){ + StringBuffer stringBuffer =new StringBuffer(); + char[] buf = new char[1024]; + int size=0; + while ((size=reader.read(buf))!=-1){ + stringBuffer.append(buf); + } + codeContext=stringBuffer.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + + byte[] decodeByte=Base64Utils.decode(codeContext); + try (FileOutputStream out =new FileOutputStream(decodeFile)) { + out.write(decodeByte); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} -- Gitee From 43366a64e68c8a5ba03fb8efc40ba75747dd6ab2 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Fri, 7 Apr 2017 09:17:28 +0800 Subject: [PATCH 09/27] =?UTF-8?q?base64=20=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/viewer/Test.java | 7 ++++ .../main/java/com/jlh/viewer/base64/Main.java | 3 +- .../com/jlh/viewer/thread/ThreadWait.java | 36 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/thread/ThreadWait.java diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index 74ac2ad..de7080c 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -23,4 +23,11 @@ public class Test { while (sc.hasNext()) System.out.println(sc.nextByte(3)); } + + public static class Woe{ + private static void dos(){} + public void dos2(){ + dos(); + } + } } diff --git a/jlh/src/main/java/com/jlh/viewer/base64/Main.java b/jlh/src/main/java/com/jlh/viewer/base64/Main.java index f7b26ed..0ef89d1 100644 --- a/jlh/src/main/java/com/jlh/viewer/base64/Main.java +++ b/jlh/src/main/java/com/jlh/viewer/base64/Main.java @@ -49,7 +49,7 @@ public class Main { } String codeContext= null; try (FileReader reader = new FileReader(codeFile)){ - StringBuffer stringBuffer =new StringBuffer(); + StringBuilder stringBuffer =new StringBuilder(); char[] buf = new char[1024]; int size=0; while ((size=reader.read(buf))!=-1){ @@ -68,4 +68,5 @@ public class Main { } } + } diff --git a/jlh/src/main/java/com/jlh/viewer/thread/ThreadWait.java b/jlh/src/main/java/com/jlh/viewer/thread/ThreadWait.java new file mode 100644 index 0000000..a2b7e44 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/thread/ThreadWait.java @@ -0,0 +1,36 @@ +package com.jlh.viewer.thread; + +import java.util.concurrent.TimeUnit; + +/** + * Created by jlh + * On 2017/4/6 0006. + */ +public class ThreadWait { + private static Thread th1,th2; + private static int flag=0; + public static void main(String[] args) throws InterruptedException { + + th1=new Thread(()->{ + for(;;){ + synchronized (th1) { + System.out.println("th1"); + try { + if (flag==0) + th1.wait(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + }); + th1.start(); + TimeUnit.SECONDS.sleep(2); + synchronized (th1){ + th1.notifyAll(); + TimeUnit.SECONDS.sleep(2); + System.out.println(11111); + } + + } +} -- Gitee From 747a3862a69e45bd7b244cc833084f62a47220e2 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Fri, 7 Apr 2017 09:19:46 +0800 Subject: [PATCH 10/27] =?UTF-8?q?interface=20=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/jlh/viewer/acm/Main.java | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/jlh/src/main/java/com/jlh/viewer/acm/Main.java b/jlh/src/main/java/com/jlh/viewer/acm/Main.java index b81d81b..81f69b5 100644 --- a/jlh/src/main/java/com/jlh/viewer/acm/Main.java +++ b/jlh/src/main/java/com/jlh/viewer/acm/Main.java @@ -6,24 +6,44 @@ package com.jlh.viewer.acm; * Created by ASUS on 2017/3/19. * 19:44 */ -import java.util.Arrays; -import java.util.HashSet; -import java.util.Scanner; +import java.util.*; public class Main { - public static void main(String[] args) { + public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ - HashSet hashSet = new HashSet<>(); - int n= sc.nextInt(); + int n=sc.nextInt(),m=sc.nextInt(); sc.nextLine(); + ArrayList arrayList = new ArrayList<>(); + HashMap> mp = new HashMap<>(); + HashMap mp2=new HashMap<>(); for (int i=0;i set = new HashSet<>(); + String[] strs=input.split(" "); + set.addAll(Arrays.asList(strs)); + mp.put(input,set); } - System.out.println(hashSet.size()); + for (int i=0;i Date: Fri, 7 Apr 2017 16:41:39 +0800 Subject: [PATCH 11/27] =?UTF-8?q?ExceptionTest=E6=B5=8B=E8=AF=95=E6=96=B0?= =?UTF-8?q?=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jlh/viewer/exception/ExceptionTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/exception/ExceptionTest.java diff --git a/jlh/src/main/java/com/jlh/viewer/exception/ExceptionTest.java b/jlh/src/main/java/com/jlh/viewer/exception/ExceptionTest.java new file mode 100644 index 0000000..a77e8e1 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/exception/ExceptionTest.java @@ -0,0 +1,31 @@ +package com.jlh.viewer.exception; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +/** + * Created by jlh + * On 2017/4/7 0007. + */ +public class ExceptionTest { + private static int x=100; + private static void add(){} + public static void main(String[] args) { + List list = Arrays.asList(1,2,3,4); + list.forEach(System.out::println); + ExceptionTest exceptionTest = new ExceptionTest(); + try{ + throw new IOException("123"); + } catch (IOException e) { + System.out.println("IOE"); + } catch (Exception e){ + System.out.println("E"); + } + } + + + private class ass{ + void add(){} + } +} -- Gitee From 4e4deaef3e7827beb5948d94207583f0d59e9e79 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Mon, 10 Apr 2017 09:57:07 +0800 Subject: [PATCH 12/27] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/jdk9/http/Main.java | 2 ++ .../java/com/jlh/viewer/algorithm/MQueue.java | 6 ++--- .../com/jlh/viewer/algorithm/MergeSort.java | 22 ++----------------- .../com/jlh/viewer/base64/Base64Utils.java | 6 ++--- .../main/java/com/jlh/viewer/base64/Main.java | 7 +++--- .../jlh/viewer/exception/ExceptionTest.java | 19 ++++++++++------ 6 files changed, 24 insertions(+), 38 deletions(-) diff --git a/jlh/src/main/java/com/jlh/jdk9/http/Main.java b/jlh/src/main/java/com/jlh/jdk9/http/Main.java index eec6e43..a43fbed 100644 --- a/jlh/src/main/java/com/jlh/jdk9/http/Main.java +++ b/jlh/src/main/java/com/jlh/jdk9/http/Main.java @@ -15,6 +15,7 @@ import java.nio.charset.Charset; * On 2017/3/31 0031. */ public class Main { + public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException { URI httpURI= new URI("https://www.baidu.com"); HttpRequest request = HttpRequest.newBuilder(httpURI).GET().build(); @@ -22,4 +23,5 @@ public class Main { HttpResponse response=httpClient.send(request, (statusCode, responseHeaders) -> HttpResponse.BodyProcessor.asString(Charset.forName("UTF-8"))); System.out.println(response); } + } diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java b/jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java index dd295d1..4dbbb36 100644 --- a/jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java @@ -34,13 +34,11 @@ public class MQueue { } public boolean isEmpty(){ - return store==0?true:false; + return store == 0; } public boolean isFull(){ - if (store==datas.length) - return true; - return false; + return store == datas.length; } @Override diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/MergeSort.java b/jlh/src/main/java/com/jlh/viewer/algorithm/MergeSort.java index 89d6177..69832dc 100644 --- a/jlh/src/main/java/com/jlh/viewer/algorithm/MergeSort.java +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/MergeSort.java @@ -18,7 +18,7 @@ public class MergeSort { reslove(a,first,last-1,new int[a.length]); } - public void reslove(int a[],int first,int last,int []temp){ + private void reslove(int a[], int first, int last, int[] temp){ if (first list = Arrays.asList(1,2,3,4); + + List list = Arrays.asList(1, 2, 3, 4); list.forEach(System.out::println); ExceptionTest exceptionTest = new ExceptionTest(); - try{ + try { throw new IOException("123"); } catch (IOException e) { System.out.println("IOE"); - } catch (Exception e){ + } catch (Exception e) { System.out.println("E"); } } - private class ass{ - void add(){} + private class ass { + void add() { + } } } -- Gitee From 221adcf5923b6cb54a806c49e0d60187d2418912 Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Tue, 11 Apr 2017 17:02:28 +0800 Subject: [PATCH 13/27] =?UTF-8?q?lambda=E6=B5=8B=E8=AF=95=E5=92=8Cgsonform?= =?UTF-8?q?at?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jlh/viewer/gsonFomartTest.java | 119 ++++++++++++++++++ .../main/java/com/jlh/viewer/lambda/Main.java | 24 ++++ 2 files changed, 143 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/gsonFomartTest.java create mode 100644 jlh/src/main/java/com/jlh/viewer/lambda/Main.java diff --git a/jlh/src/main/java/com/jlh/viewer/gsonFomartTest.java b/jlh/src/main/java/com/jlh/viewer/gsonFomartTest.java new file mode 100644 index 0000000..0ccfaea --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/gsonFomartTest.java @@ -0,0 +1,119 @@ +package com.jlh.viewer; + +/** + * Created by jlh + * On 2017/4/11 0011. + */ +public class gsonFomartTest { + + + /** + * reason : 成功1 + * result : {"jobid":"2015120913503797592","realname":"商世界","bankcard":"6259656360701234","idcard":"310329198103050011","mobile":"18912341234","res":"2","message":"认证信息不匹配"} + * error_code : 0 + */ + + private String reason; + private ResultBean result; + private int error_code; + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public ResultBean getResult() { + return result; + } + + public void setResult(ResultBean result) { + this.result = result; + } + + public int getError_code() { + return error_code; + } + + public void setError_code(int error_code) { + this.error_code = error_code; + } + + public static class ResultBean { + /** + * jobid : 2015120913503797592 + * realname : 商世界 + * bankcard : 6259656360701234 + * idcard : 310329198103050011 + * mobile : 18912341234 + * res : 2 + * message : 认证信息不匹配 + */ + + private String jobid; + private String realname; + private String bankcard; + private String idcard; + private String mobile; + private String res; + private String message; + + public String getJobid() { + return jobid; + } + + public void setJobid(String jobid) { + this.jobid = jobid; + } + + public String getRealname() { + return realname; + } + + public void setRealname(String realname) { + this.realname = realname; + } + + public String getBankcard() { + return bankcard; + } + + public void setBankcard(String bankcard) { + this.bankcard = bankcard; + } + + public String getIdcard() { + return idcard; + } + + public void setIdcard(String idcard) { + this.idcard = idcard; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getRes() { + return res; + } + + public void setRes(String res) { + this.res = res; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/lambda/Main.java b/jlh/src/main/java/com/jlh/viewer/lambda/Main.java new file mode 100644 index 0000000..d40806c --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/lambda/Main.java @@ -0,0 +1,24 @@ +package com.jlh.viewer.lambda; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * Created by jlh + * On 2017/4/11 0011. + */ +public class Main { + public static void main(String[] args) { + String []key ={"k1","k2","k3","k4","k5"}; + List list= Arrays.asList(1,2,3,4,5); + list.stream().collect( + (Supplier>) ArrayList::new, + (integers, integer) -> integers.add(integer), + List::addAll + ).forEach(System.out::print); + } +} -- Gitee From 9cab5a27692909aed5811069bca1b1985efb191d Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Tue, 11 Apr 2017 19:34:11 +0800 Subject: [PATCH 14/27] Merge branch 'master' of https://git.oschina.net/rohou/test-mvn # Conflicts: # jlh/src/main/java/com/jlh/viewer/acm/Main.java --- jlh/src/main/java/com/jlh/jdk9/http/Main.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/jlh/src/main/java/com/jlh/jdk9/http/Main.java b/jlh/src/main/java/com/jlh/jdk9/http/Main.java index eec6e43..146cf6e 100644 --- a/jlh/src/main/java/com/jlh/jdk9/http/Main.java +++ b/jlh/src/main/java/com/jlh/jdk9/http/Main.java @@ -1,25 +1,25 @@ package com.jlh.jdk9.http; -import jdk.incubator.http.HttpClient; -import jdk.incubator.http.HttpRequest; -import jdk.incubator.http.HttpResponse; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.Charset; - -/** - * Created by jlh - * On 2017/3/31 0031. - */ -public class Main { - public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException { - URI httpURI= new URI("https://www.baidu.com"); - HttpRequest request = HttpRequest.newBuilder(httpURI).GET().build(); - HttpClient httpClient = HttpClient.newHttpClient(); - HttpResponse response=httpClient.send(request, (statusCode, responseHeaders) -> HttpResponse.BodyProcessor.asString(Charset.forName("UTF-8"))); - System.out.println(response); - } -} +//import jdk.incubator.http.HttpClient; +//import jdk.incubator.http.HttpRequest; +//import jdk.incubator.http.HttpResponse; +// +//import java.io.IOException; +//import java.net.URI; +//import java.net.URISyntaxException; +//import java.nio.charset.Charset; +// +///** +// * Created by jlh +// * On 2017/3/31 0031. +// */ +//public class Main { +// public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException { +// URI httpURI= new URI("https://www.baidu.com"); +// HttpRequest request = HttpRequest.newBuilder(httpURI).GET().build(); +// HttpClient httpClient = HttpClient.newHttpClient(); +// HttpResponse response=httpClient.send(request, (statusCode, responseHeaders) -> HttpResponse.BodyProcessor.asString(Charset.forName("UTF-8"))); +// System.out.println(response); +// } +//} -- Gitee From 69d3beafa504475bb65a563acc7aa6ae713a5435 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Tue, 11 Apr 2017 19:35:07 +0800 Subject: [PATCH 15/27] =?UTF-8?q?jdk9=E4=BB=A3=E7=A0=81=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=20netty=E7=AE=80=E5=8D=95demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/pom.xml | 14 ++++- .../main/java/com/jlh/jdk9/process/Main.java | 42 +++++++-------- .../main/java/com/jlh/jdk9/trywith/Main.java | 12 ++--- .../com/jlh/netty/client/HelloClient.java | 53 +++++++++++++++++++ .../jlh/netty/client/HelloClientHandler.java | 29 ++++++++++ .../netty/client/HelloClientInitializer.java | 37 +++++++++++++ .../jlh/netty/server/HelloServerHandler.java | 29 ++++++++++ .../netty/server/HelloServerInitializer.java | 31 +++++++++++ .../java/com/jlh/netty/server/ServerMain.java | 33 ++++++++++++ jlh/src/main/java/com/jlh/viewer/Test.java | 8 +-- jlh/src/main/java/module-info.java | 7 +-- 11 files changed, 259 insertions(+), 36 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/netty/client/HelloClient.java create mode 100644 jlh/src/main/java/com/jlh/netty/client/HelloClientHandler.java create mode 100644 jlh/src/main/java/com/jlh/netty/client/HelloClientInitializer.java create mode 100644 jlh/src/main/java/com/jlh/netty/server/HelloServerHandler.java create mode 100644 jlh/src/main/java/com/jlh/netty/server/HelloServerInitializer.java create mode 100644 jlh/src/main/java/com/jlh/netty/server/ServerMain.java diff --git a/jlh/pom.xml b/jlh/pom.xml index 5d6b30b..017a5d3 100644 --- a/jlh/pom.xml +++ b/jlh/pom.xml @@ -10,14 +10,24 @@ 4.0.0 jlh + + + + io.netty + netty-all + 4.1.6.Final + + + + org.apache.maven.plugins maven-compiler-plugin - 1.9 - 1.9 + 1.8 + 1.8 diff --git a/jlh/src/main/java/com/jlh/jdk9/process/Main.java b/jlh/src/main/java/com/jlh/jdk9/process/Main.java index 6fac807..57cd6ee 100644 --- a/jlh/src/main/java/com/jlh/jdk9/process/Main.java +++ b/jlh/src/main/java/com/jlh/jdk9/process/Main.java @@ -1,22 +1,22 @@ package com.jlh.jdk9.process; - -import java.time.Duration; -import java.time.Instant; -import java.util.Optional; - -/** - * Created by jlh - * On 2017/3/31 0031. - */ -public class Main { - public static void main(String[] args) { - ProcessHandle processHandle = ProcessHandle.current(); - long PID = processHandle.getPid(); - System.out.println(PID); - ProcessHandle.Info procInfo = processHandle.info(); - Optional argsp = procInfo.arguments(); - Optional cmd = procInfo.commandLine(); - Optional startTime = procInfo.startInstant(); - Optional cpuUsage = procInfo.totalCpuDuration(); - } -} +// +//import java.time.Duration; +//import java.time.Instant; +//import java.util.Optional; +// +///** +// * Created by jlh +// * On 2017/3/31 0031. +// */ +//public class Main { +// public static void main(String[] args) { +// ProcessHandle processHandle = ProcessHandle.current(); +// long PID = processHandle.getPid(); +// System.out.println(PID); +// ProcessHandle.Info procInfo = processHandle.info(); +// Optional argsp = procInfo.arguments(); +// Optional cmd = procInfo.commandLine(); +// Optional startTime = procInfo.startInstant(); +// Optional cpuUsage = procInfo.totalCpuDuration(); +// } +//} diff --git a/jlh/src/main/java/com/jlh/jdk9/trywith/Main.java b/jlh/src/main/java/com/jlh/jdk9/trywith/Main.java index 5d37c61..20114a8 100644 --- a/jlh/src/main/java/com/jlh/jdk9/trywith/Main.java +++ b/jlh/src/main/java/com/jlh/jdk9/trywith/Main.java @@ -9,11 +9,11 @@ import java.io.InputStream; */ public class Main { public static void main(String[] args) throws IOException { - InputStream in = System.in; - try (in){ - System.out.println(in.read()); - } catch (IOException e) { - e.printStackTrace(); - } +// InputStream in = System.in; +// try (in){ +// System.out.println(in.read()); +// } catch (IOException e) { +// e.printStackTrace(); +// } } } diff --git a/jlh/src/main/java/com/jlh/netty/client/HelloClient.java b/jlh/src/main/java/com/jlh/netty/client/HelloClient.java new file mode 100644 index 0000000..960a694 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/client/HelloClient.java @@ -0,0 +1,53 @@ +package com.jlh.netty.client; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +/** + * com.jlh.netty.client + * Created by ASUS on 2017/4/11. + * 19:19 + */ +public class HelloClient { + public static String host = "127.0.0.1"; + public static int port = 7878; + public static void main(String[] args) throws IOException, InterruptedException { + EventLoopGroup group = new NioEventLoopGroup(); + try { + Bootstrap b = new Bootstrap(); + b.group(group) + .channel(NioSocketChannel.class) + .handler(new HelloClientInitializer()); + + // 连接服务端 + Channel ch = b.connect(host, port).sync().channel(); + + // 控制台输入 + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + for (; ; ) { + String line = in.readLine(); + if (line == null) { + continue; + } + /* + * 向服务端发送在控制台输入的文本 并用"\r\n"结尾 + * 之所以用\r\n结尾 是因为我们在handler中添加了 DelimiterBasedFrameDecoder 帧解码。 + * 这个解码器是一个根据\n符号位分隔符的解码器。所以每条消息的最后必须加上\n否则无法识别和解码 + * */ + ch.writeAndFlush(line + "\r\n"); + } + } + finally{ + group.shutdownGracefully(); + } + } + +} + diff --git a/jlh/src/main/java/com/jlh/netty/client/HelloClientHandler.java b/jlh/src/main/java/com/jlh/netty/client/HelloClientHandler.java new file mode 100644 index 0000000..825d2d3 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/client/HelloClientHandler.java @@ -0,0 +1,29 @@ +package com.jlh.netty.client; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + +/** + * com.jlh.netty.client + * Created by ASUS on 2017/4/11. + * 19:23 + */ +public class HelloClientHandler extends SimpleChannelInboundHandler { + @Override + protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { + + System.out.println("Server say : " + msg); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + System.out.println("Client active "); + super.channelActive(ctx); + } + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + System.out.println("Client close "); + super.channelInactive(ctx); + } +} diff --git a/jlh/src/main/java/com/jlh/netty/client/HelloClientInitializer.java b/jlh/src/main/java/com/jlh/netty/client/HelloClientInitializer.java new file mode 100644 index 0000000..d7e3a1c --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/client/HelloClientInitializer.java @@ -0,0 +1,37 @@ +package com.jlh.netty.client; + +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.DelimiterBasedFrameDecoder; +import io.netty.handler.codec.Delimiters; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; + +/** + * com.jlh.netty.client + * Created by ASUS on 2017/4/11. + * 19:22 + */ +public class HelloClientInitializer extends ChannelInitializer { + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + + + ChannelPipeline pipeline = socketChannel.pipeline(); + + /* + * 这个地方的 必须和服务端对应上。否则无法正常解码和编码 + * + * 解码和编码 我将会在下一张为大家详细的讲解。再次暂时不做详细的描述 + * + * */ + pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); + pipeline.addLast("decoder", new StringDecoder()); + pipeline.addLast("encoder", new StringEncoder()); + + // 客户端的逻辑 + pipeline.addLast("handler", new HelloClientHandler()); + + } +} diff --git a/jlh/src/main/java/com/jlh/netty/server/HelloServerHandler.java b/jlh/src/main/java/com/jlh/netty/server/HelloServerHandler.java new file mode 100644 index 0000000..7d860b1 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/server/HelloServerHandler.java @@ -0,0 +1,29 @@ +package com.jlh.netty.server; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + +import java.net.InetAddress; + +/** + * com.jlh.netty.server + * Created by ASUS on 2017/4/11. + * 19:16 + */ +public class HelloServerHandler extends SimpleChannelInboundHandler { + @Override + protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception { + // 收到消息直接打印输出 + System.out.println(ctx.channel().remoteAddress() + " Say : " + msg); + + // 返回客户端消息 - 我已经接收到了你的消息 + ctx.writeAndFlush("Received your message !\n"); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + System.out.println("RamoteAddress : " + ctx.channel().remoteAddress() + " active !"); + ctx.writeAndFlush( "Welcome to " + InetAddress.getLocalHost().getHostName() + " service!\n"); + super.channelActive(ctx); + } +} diff --git a/jlh/src/main/java/com/jlh/netty/server/HelloServerInitializer.java b/jlh/src/main/java/com/jlh/netty/server/HelloServerInitializer.java new file mode 100644 index 0000000..0c19a0a --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/server/HelloServerInitializer.java @@ -0,0 +1,31 @@ +package com.jlh.netty.server; + +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.DelimiterBasedFrameDecoder; +import io.netty.handler.codec.Delimiters; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; + +/** + * com.jlh.netty.server + * Created by ASUS on 2017/4/11. + * 19:14 + */ +public class HelloServerInitializer extends ChannelInitializer { + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + ChannelPipeline pipeline = socketChannel.pipeline(); + + // 以("\n")为结尾分割的 解码器 + pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter())); + + // 字符串解码 和 编码 + pipeline.addLast("decoder", new StringDecoder()); + pipeline.addLast("encoder", new StringEncoder()); + + // 自己的逻辑Handler + pipeline.addLast("handler", new HelloServerHandler()); + } +} diff --git a/jlh/src/main/java/com/jlh/netty/server/ServerMain.java b/jlh/src/main/java/com/jlh/netty/server/ServerMain.java new file mode 100644 index 0000000..cca03f7 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/server/ServerMain.java @@ -0,0 +1,33 @@ +package com.jlh.netty.server; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; + +/** + * com.jlh.netty.server + * Created by ASUS on 2017/4/11. + * 19:05 + */ +public class ServerMain { + private static final int portNumber = 7878; + public static void main(String[] args) throws InterruptedException { + EventLoopGroup bossGroup = new NioEventLoopGroup(); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + try{ + ServerBootstrap b = new ServerBootstrap(); + b.group(bossGroup, workerGroup); + b.channel(NioServerSocketChannel.class); + b.childHandler(new HelloServerInitializer()); + ChannelFuture f = b.bind(portNumber).sync(); + // 监听服务器关闭监听 + f.channel().closeFuture().sync(); + + }finally { + bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + } + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index de7080c..d9c590e 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -17,11 +17,9 @@ public class Test { BigDecimal c=new BigDecimal(a); System.out.println(c); System.out.println(Long.MAX_VALUE); - String ares="abbabc"; - Scanner sc = new Scanner(System.in); - while (sc.hasNext()) - System.out.println(sc.nextByte(3)); + System.out.println(100%3.9); + } public static class Woe{ @@ -30,4 +28,6 @@ public class Test { dos(); } } + + } diff --git a/jlh/src/main/java/module-info.java b/jlh/src/main/java/module-info.java index c61131a..eba005a 100644 --- a/jlh/src/main/java/module-info.java +++ b/jlh/src/main/java/module-info.java @@ -3,6 +3,7 @@ * On 2017/3/31 0031. * */ -module jlh { - requires jdk.incubator.httpclient; -} \ No newline at end of file +//module jlh { +// requires jdk.incubator.httpclient; +// requires netty.all; +//} \ No newline at end of file -- Gitee From 17301bf08b7abac5b29453321465b427902b394f Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Wed, 12 Apr 2017 10:07:26 +0800 Subject: [PATCH 16/27] =?UTF-8?q?netty=20=E6=96=B0=E5=A2=9E=20=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E4=BC=A0=E8=BE=93DEMO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/pom.xml | 3 +- jlh/src/main/java/com/jlh/netty/Command.java | 36 +++++++++++++++++++ .../com/jlh/netty/client/HelloClient.java | 17 +++++---- .../jlh/netty/client/ObjectClientHandler.java | 31 ++++++++++++++++ .../netty/client/ObjectClientInitializer.java | 22 ++++++++++++ .../jlh/netty/server/ObjectServerHandler.java | 29 +++++++++++++++ .../netty/server/ObjectServerInitializer.java | 20 +++++++++++ .../java/com/jlh/netty/server/ServerMain.java | 2 +- 8 files changed, 151 insertions(+), 9 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/netty/Command.java create mode 100644 jlh/src/main/java/com/jlh/netty/client/ObjectClientHandler.java create mode 100644 jlh/src/main/java/com/jlh/netty/client/ObjectClientInitializer.java create mode 100644 jlh/src/main/java/com/jlh/netty/server/ObjectServerHandler.java create mode 100644 jlh/src/main/java/com/jlh/netty/server/ObjectServerInitializer.java diff --git a/jlh/pom.xml b/jlh/pom.xml index 017a5d3..0b0975e 100644 --- a/jlh/pom.xml +++ b/jlh/pom.xml @@ -15,9 +15,10 @@ io.netty netty-all - 4.1.6.Final + 4.1.9.Final + diff --git a/jlh/src/main/java/com/jlh/netty/Command.java b/jlh/src/main/java/com/jlh/netty/Command.java new file mode 100644 index 0000000..0db8e19 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/Command.java @@ -0,0 +1,36 @@ +package com.jlh.netty; + +import java.io.Serializable; + +/** + * Created by jlh + * On 2017/4/12 0012. + */ +public class Command implements Serializable{ + private String code; + private String value; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public String toString() { + return "Command{" + + "code='" + code + '\'' + + ", value='" + value + '\'' + + '}'; + } +} diff --git a/jlh/src/main/java/com/jlh/netty/client/HelloClient.java b/jlh/src/main/java/com/jlh/netty/client/HelloClient.java index 960a694..0759f73 100644 --- a/jlh/src/main/java/com/jlh/netty/client/HelloClient.java +++ b/jlh/src/main/java/com/jlh/netty/client/HelloClient.java @@ -1,5 +1,6 @@ package com.jlh.netty.client; +import com.jlh.netty.Command; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.EventLoopGroup; @@ -9,6 +10,7 @@ import io.netty.channel.socket.nio.NioSocketChannel; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.Scanner; /** * com.jlh.netty.client @@ -24,24 +26,25 @@ public class HelloClient { Bootstrap b = new Bootstrap(); b.group(group) .channel(NioSocketChannel.class) - .handler(new HelloClientInitializer()); + .handler(new ObjectClientInitializer()); // 连接服务端 Channel ch = b.connect(host, port).sync().channel(); // 控制台输入 - BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + Scanner in = new Scanner((System.in)); for (; ; ) { - String line = in.readLine(); - if (line == null) { - continue; - } + String code = in.nextLine(); + String value = in.nextLine(); + Command c = new Command(); + c.setCode(code); + c.setValue(value); /* * 向服务端发送在控制台输入的文本 并用"\r\n"结尾 * 之所以用\r\n结尾 是因为我们在handler中添加了 DelimiterBasedFrameDecoder 帧解码。 * 这个解码器是一个根据\n符号位分隔符的解码器。所以每条消息的最后必须加上\n否则无法识别和解码 * */ - ch.writeAndFlush(line + "\r\n"); + ch.writeAndFlush(c); } } finally{ diff --git a/jlh/src/main/java/com/jlh/netty/client/ObjectClientHandler.java b/jlh/src/main/java/com/jlh/netty/client/ObjectClientHandler.java new file mode 100644 index 0000000..0b71e66 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/client/ObjectClientHandler.java @@ -0,0 +1,31 @@ +package com.jlh.netty.client; + +import com.jlh.netty.Command; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.SimpleChannelInboundHandler; + +/** + * Created by jlh + * On 2017/4/12 0012. + */ +public class ObjectClientHandler extends SimpleChannelInboundHandler { + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Command msg) throws Exception { + + System.out.println("Server say : " + msg); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + System.out.println("Client active "); + super.channelActive(ctx); + } + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + System.out.println("Client close "); + super.channelInactive(ctx); + } +} diff --git a/jlh/src/main/java/com/jlh/netty/client/ObjectClientInitializer.java b/jlh/src/main/java/com/jlh/netty/client/ObjectClientInitializer.java new file mode 100644 index 0000000..928c50d --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/client/ObjectClientInitializer.java @@ -0,0 +1,22 @@ +package com.jlh.netty.client; + +import io.netty.channel.ChannelInitializer; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.serialization.ClassResolvers; +import io.netty.handler.codec.serialization.ObjectDecoder; +import io.netty.handler.codec.serialization.ObjectEncoder; + +/** + * Created by jlh + * On 2017/4/12 0012. + */ +public class ObjectClientInitializer extends ChannelInitializer { + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + socketChannel.pipeline().addLast( + new ObjectEncoder(), + new ObjectDecoder(Integer.MAX_VALUE , ClassResolvers.cacheDisabled(null)), + new ObjectClientHandler()); + + } +} diff --git a/jlh/src/main/java/com/jlh/netty/server/ObjectServerHandler.java b/jlh/src/main/java/com/jlh/netty/server/ObjectServerHandler.java new file mode 100644 index 0000000..de17252 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/server/ObjectServerHandler.java @@ -0,0 +1,29 @@ +package com.jlh.netty.server; + +import com.jlh.netty.Command; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + +import java.net.InetAddress; + +/** + * Created by jlh + * On 2017/4/12 0012. + */ +public class ObjectServerHandler extends SimpleChannelInboundHandler { + @Override + protected void channelRead0(ChannelHandlerContext ctx, Command msg) throws Exception { + // 收到消息直接打印输出 + System.out.println(ctx.channel().remoteAddress() + " Say : " + msg); + + // 返回客户端消息 - 我已经接收到了你的消息 + ctx.writeAndFlush("Received your message !\n"); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + System.out.println("RamoteAddress : " + ctx.channel().remoteAddress() + " active !"); + ctx.writeAndFlush( "Welcome to " + InetAddress.getLocalHost().getHostName() + " service!\n"); + super.channelActive(ctx); + } +} diff --git a/jlh/src/main/java/com/jlh/netty/server/ObjectServerInitializer.java b/jlh/src/main/java/com/jlh/netty/server/ObjectServerInitializer.java new file mode 100644 index 0000000..a652567 --- /dev/null +++ b/jlh/src/main/java/com/jlh/netty/server/ObjectServerInitializer.java @@ -0,0 +1,20 @@ +package com.jlh.netty.server; + +import io.netty.channel.ChannelInitializer; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.serialization.ClassResolvers; +import io.netty.handler.codec.serialization.ObjectDecoder; +import io.netty.handler.codec.serialization.ObjectEncoder; + +/** + * Created by jlh + * On 2017/4/12 0012. + */ +public class ObjectServerInitializer extends ChannelInitializer{ + @Override + protected void initChannel(SocketChannel socketChannel) throws Exception { + socketChannel.pipeline().addLast(new ObjectEncoder() + ,new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null) + ),new ObjectServerHandler()); + } +} diff --git a/jlh/src/main/java/com/jlh/netty/server/ServerMain.java b/jlh/src/main/java/com/jlh/netty/server/ServerMain.java index cca03f7..8114ad7 100644 --- a/jlh/src/main/java/com/jlh/netty/server/ServerMain.java +++ b/jlh/src/main/java/com/jlh/netty/server/ServerMain.java @@ -20,7 +20,7 @@ public class ServerMain { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup); b.channel(NioServerSocketChannel.class); - b.childHandler(new HelloServerInitializer()); + b.childHandler(new ObjectServerInitializer()); ChannelFuture f = b.bind(portNumber).sync(); // 监听服务器关闭监听 f.channel().closeFuture().sync(); -- Gitee From d3faeca15ad3208a269baa66088becbeacbeedfa Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Wed, 12 Apr 2017 15:30:05 +0800 Subject: [PATCH 17/27] =?UTF-8?q?=E5=B0=8F=E7=B1=B3GIT=E6=A8=A1=E6=8B=9F?= =?UTF-8?q?=E9=A2=98ACM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jlh/viewer/acm/Solution.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/Solution.java diff --git a/jlh/src/main/java/com/jlh/viewer/acm/Solution.java b/jlh/src/main/java/com/jlh/viewer/acm/Solution.java new file mode 100644 index 0000000..638708b --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/Solution.java @@ -0,0 +1,51 @@ +package com.jlh.viewer.acm; + +/** + * Created by jlh + * On 2017/4/12 0012. + */ +public class Solution { + /** + * 返回git树上两点的最近分割点 + * + * @param matrix 接邻矩阵,表示git树,matrix[i][j] == '1' 当且仅当git树中第i个和第j个节点有连接,节点0为git树的跟节点 + * @param indexA 节点A的index + * @param indexB 节点B的index + * @return 整型 + */ + public int getSplitNode(String[] matrix, int indexA, int indexB) { + boolean[] vis = new boolean[matrix.length]; + vis[0]=true; + String[] resA= reslove(matrix,0,indexA,vis).split(","); + String[] resB=reslove(matrix,0,indexB,vis).split(","); + int i=0; + for (;i Date: Wed, 19 Apr 2017 11:38:46 +0800 Subject: [PATCH 18/27] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=92=E6=B3=A1?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/viewer/Test.java | 30 ++++---- .../main/java/com/jlh/viewer/acm/Main.java | 74 ++++++++++--------- .../com/jlh/viewer/algorithm/BubbleSort.java | 33 +++++++++ 3 files changed, 88 insertions(+), 49 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/algorithm/BubbleSort.java diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index d9c590e..dd85a1d 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -2,6 +2,9 @@ package com.jlh.viewer; import java.io.IOException; import java.math.BigDecimal; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; import java.util.Scanner; /** @@ -11,23 +14,24 @@ import java.util.Scanner; public class Test { + private static int ss=1; public static void main(String[] args) throws IOException { - Double a = Double.MAX_VALUE; - System.out.println(String.valueOf(a)); - BigDecimal c=new BigDecimal(a); - System.out.println(c); - System.out.println(Long.MAX_VALUE); - String ares="abbabc"; - System.out.println(100%3.9); - + B b = new B(); + System.out.println(b.geta()); + System.out.println(((A)b).geta()); } - public static class Woe{ - private static void dos(){} - public void dos2(){ - dos(); + public static class A { + int a = 1; + public int geta(){ + return ss; } } - + public static class B extends A{ + int a= 2; + public int geta(){ + return a; + } + } } diff --git a/jlh/src/main/java/com/jlh/viewer/acm/Main.java b/jlh/src/main/java/com/jlh/viewer/acm/Main.java index 51baf8d..7c8882a 100644 --- a/jlh/src/main/java/com/jlh/viewer/acm/Main.java +++ b/jlh/src/main/java/com/jlh/viewer/acm/Main.java @@ -1,53 +1,55 @@ package com.jlh.viewer.acm; +import java.util.Arrays; +import java.util.Scanner; + /** * com.jlh.viewer.acm * Created by ASUS on 2017/3/19. * 19:44 */ -import java.util.Scanner; -import java.util.Stack; - public class Main { - private static int[][] arr=new int[1005][1005]; - private static boolean[] is=new boolean[1005]; - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - while(sc.hasNext()){ - int n=sc.nextInt(),m=sc.nextInt(); - if (n==0&&m==0) - break; - init(n); - for (int i=0;i stack = new Stack<>(); - stack.push(1); - is[1]=true; - int res=0; - while (!stack.empty()){ - int i = stack.pop(); - for (int j=1;j<=n;j++){ - if (arr[i][j]==1&& !is[j]){ - stack.push(j); - is[j]=true; - res++; - } - } + + /** + * 计算你能获得的最大收益 + * + * @param prices Prices[i]即第i天的股价 + * @return 整型 + */ + public int calculateMax(int[] prices) { + int max = 0; + for (int i=1;i Date: Wed, 19 Apr 2017 15:23:22 +0800 Subject: [PATCH 19/27] =?UTF-8?q?Numberic=20KeyPad=20=E6=9C=AA=E9=80=9A?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/viewer/Test.java | 12 +-- .../java/com/jlh/viewer/acm/LuckyString.java | 52 +++++++++++++ .../main/java/com/jlh/viewer/acm/Main.java | 1 - .../com/jlh/viewer/acm/NumbericKeyPad.java | 73 +++++++++++++++++++ 4 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/LuckyString.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/NumbericKeyPad.java diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index dd85a1d..ee65903 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -17,21 +17,23 @@ public class Test { private static int ss=1; public static void main(String[] args) throws IOException { B b = new B(); - System.out.println(b.geta()); - System.out.println(((A)b).geta()); + System.out.println(B.geta()); + System.out.println(A.geta()); } public static class A { int a = 1; - public int geta(){ + static int b =1; + public static int geta(){ return ss; } } public static class B extends A{ int a= 2; - public int geta(){ - return a; + static int b=2; + public static int getb(){ + return b; } } } diff --git a/jlh/src/main/java/com/jlh/viewer/acm/LuckyString.java b/jlh/src/main/java/com/jlh/viewer/acm/LuckyString.java new file mode 100644 index 0000000..ccbb81e --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/LuckyString.java @@ -0,0 +1,52 @@ +package com.jlh.viewer.acm; + +import java.util.HashSet; +import java.util.Scanner; +import java.util.TreeSet; + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/4/19. + * 13:12 + */ +public class LuckyString { + static boolean[] fib = new boolean[105]; + + public static int diff(String input){ + HashSet tol =new HashSet<>(); + for (int i=0;i=105) + break; + fib[sum]=true; + pre1=pre2; + pre2=sum; + } + Scanner sc = new Scanner(System.in); + while (sc.hasNext()){ + String input =sc.nextLine(); + TreeSet flag =new TreeSet<>(); + for (int i=0;i0;n--){ + String input =sc.nextLine(); + while (true) { + int i = 1; + int[] nums = transf(input); + for (; i < nums.length ; i++) { + if (flag[nums[i-1]][nums[i]]!=1) { + break; + } + } + if (i=0&&jw!=0; i--){ + if(a[i]-'0'>0){ + a[i] += jw; + jw = 0; + } + else{ + a[i] = '9'; + jw = -1; + } + for(int j=i+1;j Date: Wed, 19 Apr 2017 15:41:33 +0800 Subject: [PATCH 20/27] =?UTF-8?q?Numberic=20KeyPad=20=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jlh/viewer/acm/NumbericKeyPad.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/jlh/src/main/java/com/jlh/viewer/acm/NumbericKeyPad.java b/jlh/src/main/java/com/jlh/viewer/acm/NumbericKeyPad.java index 369b2b5..4b0bba5 100644 --- a/jlh/src/main/java/com/jlh/viewer/acm/NumbericKeyPad.java +++ b/jlh/src/main/java/com/jlh/viewer/acm/NumbericKeyPad.java @@ -25,27 +25,27 @@ public class NumbericKeyPad { int n = sc.nextInt(); sc.nextLine(); for (;n>0;n--){ - String input =sc.nextLine(); + char[] inp =sc.nextLine().toCharArray(); while (true) { int i = 1; - int[] nums = transf(input); - for (; i < nums.length ; i++) { - if (flag[nums[i-1]][nums[i]]!=1) { + for (; i < inp.length ; i++) { + int p=inp[i-1]-'0'; + int r=inp[i]-'0'; + if (flag[p][r]!=1) { break; } } - if (i=0&&jw!=0; i--){ @@ -60,14 +60,6 @@ public class NumbericKeyPad { for(int j=i+1;j Date: Wed, 19 Apr 2017 17:28:00 +0800 Subject: [PATCH 21/27] =?UTF-8?q?=E5=A4=9A=E6=80=81=E7=A0=94=E7=A9=B6?= =?UTF-8?q?=EF=BC=8C=E9=9D=99=E6=80=81=E6=96=B9=E6=B3=95=EF=BC=8C=E9=9D=99?= =?UTF-8?q?=E6=80=81=E5=8F=98=E9=87=8F=EF=BC=8C=E6=88=90=E5=91=98=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=9D=87=E4=B8=8D=E7=BB=A7=E6=89=BF=EF=BC=8C=E4=B8=BA?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E6=A0=B9=E6=8D=AE=E5=BC=95=E7=94=A8=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=86=B3=E5=AE=9A=E4=BD=BF=E7=94=A8=E5=93=AA=E4=B8=AA?= =?UTF-8?q?=EF=BC=8C=E6=88=90=E5=91=98=E6=96=B9=E6=B3=95=E4=B8=BA=E5=A4=9A?= =?UTF-8?q?=E6=80=81=EF=BC=8C=E6=A0=B9=E6=8D=AE=E5=AF=B9=E8=B1=A1=E6=9C=AC?= =?UTF-8?q?=E8=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/viewer/Test.java | 26 +++++++----- jlh/src/main/java/com/jlh/viewer/dynaic.java | 42 ++++++++++++++++++++ 2 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/dynaic.java diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index ee65903..b44435f 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -17,23 +17,29 @@ public class Test { private static int ss=1; public static void main(String[] args) throws IOException { B b = new B(); - System.out.println(B.geta()); - System.out.println(A.geta()); + b.getb(); + ((A)b).getb(); } public static class A { - int a = 1; - static int b =1; - public static int geta(){ - return ss; + int b =1 ; + public void getb(){ + System.out.println("p"+b); + } + public static void geta(){ + System.out.println("a"); } } public static class B extends A{ - int a= 2; - static int b=2; - public static int getb(){ - return b; + int b=2; + public static void geta(){ + System.out.println("b"); + } + + @Override + public void getb() { + System.out.println("c"+b); } } } diff --git a/jlh/src/main/java/com/jlh/viewer/dynaic.java b/jlh/src/main/java/com/jlh/viewer/dynaic.java new file mode 100644 index 0000000..fdcb61b --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/dynaic.java @@ -0,0 +1,42 @@ +package com.jlh.viewer; + +/** + * com.jlh.viewer + * Created by ASUS on 2017/4/19. + * 16:39 + */ +public class dynaic { + public static void main(String[] args) { + Son s = new Son(); + System.out.println(s.a); + System.out.println(((Father)s).a); + System.out.println(s.b); + System.out.println(((Father)s).b); + System.out.println(s.get()); + System.out.println(((Father)s).get()); + s.work(); + ((Father)s).work(); + } + static class Father { + int a=1; + static int b=1; + public int get(){ + return a; + } + public static void work(){ + System.out.println("father"); + } + } + + static class Son extends Father{ + int a=2; + static int b=2; + public int get(){ + return a; + } + public static void work(){ + System.out.println("son"); + } + } + +} -- Gitee From 2b368b0f9daabc4c61198e638a59a1a58280db98 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Wed, 19 Apr 2017 21:27:14 +0800 Subject: [PATCH 22/27] =?UTF-8?q?springouting=20=E6=9C=AA=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20maxValInrange=20=E9=80=9A=E8=BF=87=20=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E5=8C=BA=E9=97=B4=E6=9C=80=E5=A4=A7=E5=80=BC=20?= =?UTF-8?q?=E7=BA=BF=E6=AE=B5=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jlh/viewer/acm/MaxValInRange.java | 77 +++++++++++++++++++ .../java/com/jlh/viewer/acm/SpringOuting.java | 41 ++++++++++ .../com/jlh/viewer/algorithm/LineTree.java | 47 +++++++++++ 3 files changed, 165 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/MaxValInRange.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/SpringOuting.java create mode 100644 jlh/src/main/java/com/jlh/viewer/algorithm/LineTree.java diff --git a/jlh/src/main/java/com/jlh/viewer/acm/MaxValInRange.java b/jlh/src/main/java/com/jlh/viewer/acm/MaxValInRange.java new file mode 100644 index 0000000..709e6f5 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/MaxValInRange.java @@ -0,0 +1,77 @@ +package com.jlh.viewer.acm; + +import java.util.Scanner; + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/4/19. + * 19:14 + */ +public class MaxValInRange { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (sc.hasNext()){ + int n=sc.nextInt(); + int m=sc.nextInt(); + LineTree lineTree =new LineTree(n); + for (int i=1;i<=n;i++){ + int tmp= sc.nextInt(); + lineTree.update(i,tmp); + } + for (int i=0;ib){ + a=a^b; + b=a^b; + a=a^b; + } + if (c.equals("U")) + lineTree.update(a,b); + else + System.out.println(lineTree.query(a,b)); + } + } + } + public static class LineTree{ + int[] tree; + int size; + public LineTree(int n){ + tree= new int[n*4+1]; + size=n; + } + public void update (int n,int value){ + update(1,1,size,n,value); + } + private int update (int index,int left,int right,int n,int value){ + if (left==right){ + tree[index]=value; + return value; + }else { + int mid = (left+right)/2; + if (mid>=n) + tree[index]=Math.max(update(index*2,left,mid,n,value),tree[index*2+1]); + else + tree[index]=Math.max(update(index*2+1,mid+1,right,n,value),tree[index*2]); + } + return tree[index]; + } + + public int query (int start,int end){ + return query(1,1,size,start,end); + } + private int query (int index,int left,int right,int start,int end){ + if (left>=start&&right<=end) + return tree[index]; + int mid = (left+right)/2; + int a = 0,b=0; + if (start<=mid) + a=query(index*2,left,mid,start,end); + if (end>mid) + b=query(index*2+1,mid+1,right,start,end); + + return Math.max(a,b); + } + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/acm/SpringOuting.java b/jlh/src/main/java/com/jlh/viewer/acm/SpringOuting.java new file mode 100644 index 0000000..303fd19 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/SpringOuting.java @@ -0,0 +1,41 @@ +package com.jlh.viewer.acm; + +import java.util.Scanner; + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/4/19. + * 17:40 + */ +public class SpringOuting { + private static int []score = new int[1005]; + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + while (sc.hasNext()){ + int n=sc.nextInt(),k=sc.nextInt(); + int maxs=-1,mindex=-1; + init(k); + for (int i=0;i=0;j--){ + int inp= sc.nextInt(); + score[inp]+=j; + if (maxs=n) + tree[index]=Math.max(update(index*2,left,mid,n,value),tree[index*2+1]); + else + tree[index]=Math.max(update(index*2+1,mid+1,right,n,value),tree[index*2]); + } + return tree[index]; + } + + public int query (int start,int end){ + return query(1,1,size,start,end); + } + private int query (int index,int left,int right,int start,int end){ + if (left>=start&&right<=end) + return tree[index]; + int mid = (left+right)/2; + int a = 0,b=0; + if (start<=mid) + a=query(index*2,left,mid,start,end); + if (end>mid) + b=query(index*2+1,mid+1,right,start,end); + + return Math.max(a,b); + } +} -- Gitee From 19601ba5be35f81089a7a824e89481d8178473db Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Thu, 20 Apr 2017 17:41:46 +0800 Subject: [PATCH 23/27] =?UTF-8?q?=E7=89=9B=E5=AE=A2=E7=BD=91=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=BC=96=E7=A8=8B=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlh/src/main/java/com/jlh/viewer/Test.java | 27 +----- .../java/com/jlh/viewer/acm/BinarySeach.java | 32 +++++++ .../main/java/com/jlh/viewer/acm/Coder.java | 50 +++++++++++ .../java/com/jlh/viewer/acm/FirstRepeat.java | 26 ++++++ .../main/java/com/jlh/viewer/acm/Flip.java | 32 +++++++ .../com/jlh/viewer/acm/LongestDistance.java | 19 ++++ .../main/java/com/jlh/viewer/acm/Main.java | 89 ++++++++++--------- .../java/com/jlh/viewer/acm/PokerCompare.java | 62 +++++++++++++ .../com/jlh/viewer/acm/SimpleErrorRecord.java | 44 +++++++++ .../main/java/com/jlh/viewer/acm/Visit.java | 56 ++++++++++++ 10 files changed, 371 insertions(+), 66 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/BinarySeach.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/Coder.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/FirstRepeat.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/Flip.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/LongestDistance.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/PokerCompare.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/SimpleErrorRecord.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/Visit.java diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index b44435f..8c826b7 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -14,32 +14,9 @@ import java.util.Scanner; public class Test { - private static int ss=1; public static void main(String[] args) throws IOException { - B b = new B(); - b.getb(); - ((A)b).getb(); + short a= (short) 65537; + System.out.println(a); } - public static class A { - int b =1 ; - public void getb(){ - System.out.println("p"+b); - } - public static void geta(){ - System.out.println("a"); - } - } - - public static class B extends A{ - int b=2; - public static void geta(){ - System.out.println("b"); - } - - @Override - public void getb() { - System.out.println("c"+b); - } - } } diff --git a/jlh/src/main/java/com/jlh/viewer/acm/BinarySeach.java b/jlh/src/main/java/com/jlh/viewer/acm/BinarySeach.java new file mode 100644 index 0000000..9f22522 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/BinarySeach.java @@ -0,0 +1,32 @@ +package com.jlh.viewer.acm; + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/4/20. + * 16:10 + */ +public class BinarySeach { + public int getPos(int[] A, int n, int val) { + // write code here + int pos =search(A,0,n-1,val ); + int index =pos ; + for (;index>=0;index--){ + if (A[pos]!=A[index]) + return index+1; + } + return 0; + } + public int search (int[] A,int left,int right,int val){ + int mid = (left+right)/2; + if (A[mid]==val) + return mid; + else if (A[mid] mp = new LinkedHashMap<>(); + for (int i=0;i0) + mp.put(i,num); + } + ArrayList> list = new ArrayList<>(mp.entrySet()); + Collections.sort(list, new Comparator>() { + @Override + public int compare(Map.Entry o1, Map.Entry o2) { + return o1.getValue().compareTo(o2.getValue())*-1; + } + }); + String[] res=new String [list.size()]; + for (int i=0;i=0&&a=0&&b map = new LinkedHashMap();//LinkedHashMap而不是hashmap!!!!! + String key; + String filename; + String path; + while (in.hasNext()) { + path = in.next(); +//将路径转换为文件名 + int id = path.lastIndexOf('\\'); +//如果找不到说明只有文件名没有路径 + filename = id < 0 ? path : path.substring(id + 1); + int linenum = in.nextInt(); +//统计频率 + key = filename + " " + linenum; + if (map.containsKey(key)) { + map.put(key, map.get(key) + 1); + } else { + map.put(key, 1); } } - return max; - } - public int minFrom (int []price,int l,int r){ - int min = Integer.MAX_VALUE; - for (int i=l;i> list = new LinkedList>(map.entrySet()); + Collections.sort(list, new Comparator>() { + //降序 + @Override + public int compare(Entry arg0, Entry arg1) { + return (arg1.getValue() - arg0.getValue()) == 0 ? (arg0.getValue() - arg1.getValue()) : (arg1.getValue() - arg0.getValue()); + } + }); +//只输出前8条 + int m = 0; + for (Map.Entry mapping : list) { + m++; + if (m <= 8) { + String[] str = mapping.getKey().split(" "); + String k = str[0].length() > 16 ? str[0].substring(str[0].length() - 16) : str[0]; + String n = str[1]; + System.out.println(k + " " + n + " " + mapping.getValue()); + } else { + break; + } - public static void main(String[] args) { - System.out.println(); - Main main =new Main(); - Scanner sc = new Scanner(System.in); - while (sc.hasNext()){ - String[] input = sc.nextLine().split(","); - int [] nums= new int [input.length]; - for (int i=0;i mp = new LinkedHashMap<>(); + while (sc.hasNext()){ + String input = sc.next(); + if (input.equals("-1")) + break; + Integer line= sc.nextInt(); + String name = input.substring(input.lastIndexOf("\\")+1); + if (mp.containsKey(name+" "+line)){ + mp.put(name+" "+line,mp.get(name+" "+line)+1); + }else { + mp.put(name+" "+line,1); + } + } + ArrayList> a = new ArrayList<>(mp.entrySet()); + Collections.sort(a, new Comparator>() { + @Override + public int compare(Map.Entry o1, Map.Entry o2) { + int res= o1.getValue().compareTo(o2.getValue()); + return res*-1; + } + }); + int m=0; + for (Map.Entry entry:a){ + m++; + if (m>8) + break; + String temp[]=entry.getKey().split(" "); + System.out.println(temp[0].substring(Math.max(temp[0].length()-16,0),temp[0].length())+" "+temp[1]+" "+entry.getValue()); + + } + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/acm/Visit.java b/jlh/src/main/java/com/jlh/viewer/acm/Visit.java new file mode 100644 index 0000000..846e355 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/Visit.java @@ -0,0 +1,56 @@ +package com.jlh.viewer.acm; + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/4/20. + * 17:23 + */ +public class Visit { + public int countPath(int[][] map, int n, int m) { + int a1=-1,b1=-1,a2=-1,b2=-1; + int[][] dp=new int[n][m]; + for (int i=0;i=0;i+=x){ + for (int j=b1+y;y==1?j=0;j+=y){ + if (map[i][j]==-1) + dp[i][j]=0; + else + dp[i][j]=dp[i-x][j]+dp[i][j-y]; + } + } + return dp[a2][b2]; + } + + public static void main(String[] args) { + Visit visit = new Visit(); + System.out.println(visit.countPath(new int[][]{{0,1,0},{2,0,0}},2,3)); + } +} -- Gitee From 437cad639a76ee7d88e201b15cd928e84f291758 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Sat, 22 Apr 2017 15:58:37 +0800 Subject: [PATCH 24/27] =?UTF-8?q?=E7=89=9B=E5=AE=A2=E7=BD=91=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E7=BC=96=E7=A8=8B=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/jlh/viewer/NIO/Main.java | 34 +++++ jlh/src/main/java/com/jlh/viewer/Test.java | 17 +-- .../java/com/jlh/viewer/acm/MaxInnerRec.java | 38 ++++++ .../java/com/jlh/viewer/acm/StringCount.java | 30 +++++ .../jlh/viewer/algorithm/TreeIntroduce.java | 3 + jlh/src/main/java/com/jlh/viewer/out.txt | 119 ++++++++++++++++++ .../jlh/viewer/thread/ReentrantLockTest.java | 12 ++ 7 files changed, 246 insertions(+), 7 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/NIO/Main.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/MaxInnerRec.java create mode 100644 jlh/src/main/java/com/jlh/viewer/acm/StringCount.java create mode 100644 jlh/src/main/java/com/jlh/viewer/out.txt create mode 100644 jlh/src/main/java/com/jlh/viewer/thread/ReentrantLockTest.java diff --git a/jlh/src/main/java/com/jlh/viewer/NIO/Main.java b/jlh/src/main/java/com/jlh/viewer/NIO/Main.java new file mode 100644 index 0000000..9903a6e --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/NIO/Main.java @@ -0,0 +1,34 @@ +package com.jlh.viewer.NIO; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +/** + * com.jlh.viewer.NIO + * Created by ASUS on 2017/4/22. + * 13:33 + */ +public class Main { + public static void main(String[] args) throws IOException { + + FileInputStream fileInputStream= new FileInputStream("D:\\work\\workSpace\\test-mvn\\jlh\\src\\main\\java\\com\\jlh\\viewer\\gsonFomartTest.java"); + FileOutputStream fileOutputStream = new FileOutputStream("D:\\work\\workSpace\\test-mvn\\jlh\\src\\main\\java\\com\\jlh\\viewer\\out.txt"); + FileChannel fileChannel=fileInputStream.getChannel(),fileChannel1=fileOutputStream.getChannel(); + + ByteBuffer byteBuffer = ByteBuffer.allocate(1024); + byteBuffer.clear(); + while (fileChannel.read(byteBuffer)!=-1){ + byteBuffer.flip(); + fileChannel1.write(byteBuffer); + byteBuffer.clear(); + } + + fileChannel.close(); + fileChannel1.close(); + fileOutputStream.close(); + fileInputStream.close(); + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index 8c826b7..6dea9cf 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -2,10 +2,7 @@ package com.jlh.viewer; import java.io.IOException; import java.math.BigDecimal; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Scanner; +import java.util.*; /** * Created by jlh @@ -14,9 +11,15 @@ import java.util.Scanner; public class Test { + private Integer a=1; public static void main(String[] args) throws IOException { - short a= (short) 65537; - System.out.println(a); + ArrayList a = new ArrayList<>(); + HashMap b= new HashMap<>(); + } + public class A{ + private Integer a=2; + public Integer getA(){ + return a; + } } - } diff --git a/jlh/src/main/java/com/jlh/viewer/acm/MaxInnerRec.java b/jlh/src/main/java/com/jlh/viewer/acm/MaxInnerRec.java new file mode 100644 index 0000000..4f42b25 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/MaxInnerRec.java @@ -0,0 +1,38 @@ +package com.jlh.viewer.acm; + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/4/21. + * 15:12 + */ +public class MaxInnerRec { + public int countArea(int[] A, int n) { + int max =-1; + for (int i=0;i=0){ + if (A[j]>=A[i]) { + num++; + j--; + }else + break; + } + j=i+1; + while (j=A[i]) { + num++; + j++; + }else + break; + } + max = Math.max(num*A[i],max); + } + return max; + } + + public static void main(String[] args) { + MaxInnerRec maxInnerRec = new MaxInnerRec(); + System.out.println(maxInnerRec.countArea(new int[]{281,179,386,165,88,500},6)); + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/acm/StringCount.java b/jlh/src/main/java/com/jlh/viewer/acm/StringCount.java new file mode 100644 index 0000000..f156a2f --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/acm/StringCount.java @@ -0,0 +1,30 @@ +package com.jlh.viewer.acm; + +import java.util.Scanner; + +/** + * com.jlh.viewer.acm + * Created by ASUS on 2017/4/21. + * 15:30 + */ +public class StringCount { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (sc.hasNext()) { + String a1 = sc.next(), a2 = sc.next(); + int l1 = sc.nextInt(), l2 = sc.nextInt(); + char[] b1 = a1.toCharArray(), b2 = a2.toCharArray(); + int dp[] =new int[120]; + int result=0; + for(int i=1; i<=l2; i++){ + dp[i] = (26*(dp[i-1]))%1000007; + if(i<=b1.length) dp[i] -=b1[i-1]; + if(i<=b2.length) dp[i] +=b2[i-1]; + if(i == b2.length) dp[i]--; + if(i>=l1) result += dp[i]; + } + System.out.println(result%1000007); + } + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/TreeIntroduce.java b/jlh/src/main/java/com/jlh/viewer/algorithm/TreeIntroduce.java index d8305e4..be12c32 100644 --- a/jlh/src/main/java/com/jlh/viewer/algorithm/TreeIntroduce.java +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/TreeIntroduce.java @@ -16,6 +16,9 @@ public class TreeIntroduce { * 完全二叉树:k-1层 满节点 ,k层从左往右填满 * 满二叉树:所有节点都满 ,第K层 节点数量 2^(k-1) 总结点数量 2^k-1 * 堆:一般就是大小堆,是特殊的完全二叉树,节点值大于或小于子节点 + * K叉树总结点个数=kn*n+ k(n-1)*(n-1).... k2*2 +k1+1 kn 为n度的节点个数 + * 线索二叉树 ,记录该节点按中序遍历时候的前驱和后继,一般右子树为空就用了记录后继,左为空记录前驱 + * * * * 根据前序和中序还原二叉树:前序遍历第一个一定是树的根节点,然后从中序中找到根节点位置,从左填起 diff --git a/jlh/src/main/java/com/jlh/viewer/out.txt b/jlh/src/main/java/com/jlh/viewer/out.txt new file mode 100644 index 0000000..0ccfaea --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/out.txt @@ -0,0 +1,119 @@ +package com.jlh.viewer; + +/** + * Created by jlh + * On 2017/4/11 0011. + */ +public class gsonFomartTest { + + + /** + * reason : 成功1 + * result : {"jobid":"2015120913503797592","realname":"商世界","bankcard":"6259656360701234","idcard":"310329198103050011","mobile":"18912341234","res":"2","message":"认证信息不匹配"} + * error_code : 0 + */ + + private String reason; + private ResultBean result; + private int error_code; + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public ResultBean getResult() { + return result; + } + + public void setResult(ResultBean result) { + this.result = result; + } + + public int getError_code() { + return error_code; + } + + public void setError_code(int error_code) { + this.error_code = error_code; + } + + public static class ResultBean { + /** + * jobid : 2015120913503797592 + * realname : 商世界 + * bankcard : 6259656360701234 + * idcard : 310329198103050011 + * mobile : 18912341234 + * res : 2 + * message : 认证信息不匹配 + */ + + private String jobid; + private String realname; + private String bankcard; + private String idcard; + private String mobile; + private String res; + private String message; + + public String getJobid() { + return jobid; + } + + public void setJobid(String jobid) { + this.jobid = jobid; + } + + public String getRealname() { + return realname; + } + + public void setRealname(String realname) { + this.realname = realname; + } + + public String getBankcard() { + return bankcard; + } + + public void setBankcard(String bankcard) { + this.bankcard = bankcard; + } + + public String getIdcard() { + return idcard; + } + + public void setIdcard(String idcard) { + this.idcard = idcard; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getRes() { + return res; + } + + public void setRes(String res) { + this.res = res; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/thread/ReentrantLockTest.java b/jlh/src/main/java/com/jlh/viewer/thread/ReentrantLockTest.java new file mode 100644 index 0000000..08d43c7 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/thread/ReentrantLockTest.java @@ -0,0 +1,12 @@ +package com.jlh.viewer.thread; + +import java.util.concurrent.locks.ReentrantLock; + +/** + * com.jlh.viewer.thread + * Created by ASUS on 2017/4/21. + * 14:48 + */ +public class ReentrantLockTest { + private ReentrantLock lock = new ReentrantLock(); +} -- Gitee From 0cd471d590beb3d1b71a421ce1b7215b53d1d634 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Sun, 23 Apr 2017 09:57:32 +0800 Subject: [PATCH 25/27] =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jlh/viewer/genericity/Main.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/genericity/Main.java diff --git a/jlh/src/main/java/com/jlh/viewer/genericity/Main.java b/jlh/src/main/java/com/jlh/viewer/genericity/Main.java new file mode 100644 index 0000000..a84d4e0 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/genericity/Main.java @@ -0,0 +1,36 @@ +package com.jlh.viewer.genericity; + +/** + * com.jlh.viewer.genericity + * Created by ASUS on 2017/4/23. + * 9:46 + */ +public class Main { + public static class Stack { + private int size; + private int top=-1; + private Object[] datas; + + public Stack(int size) { + this.size=size; + datas=new Object[size]; + } + public T pop(){ + return (top >= 0) ? (T) datas[top--] : null; + } + public void push (T v){ + if (top+1 stack =new Stack<>(3); + stack.push(2); + System.out.println(stack.pop()); + stack.push(1); + stack.push(3); + stack.push(4); + stack.push(5); + System.out.println(1); + } +} -- Gitee From 42373901edebc0862363c902f6e3d6d7c8b6bfa8 Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Wed, 3 May 2017 09:54:10 +0800 Subject: [PATCH 26/27] =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E6=B1=A0=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/jlh/viewer/NIO/Main.java | 1 + jlh/src/main/java/com/jlh/viewer/Test.java | 52 +++++++++++++++++-- .../viewer/genericity/ExtendSuperTest.java | 31 +++++++++++ .../com/jlh/viewer/thread/ThreadPool.java | 18 +++++++ 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 jlh/src/main/java/com/jlh/viewer/genericity/ExtendSuperTest.java create mode 100644 jlh/src/main/java/com/jlh/viewer/thread/ThreadPool.java diff --git a/jlh/src/main/java/com/jlh/viewer/NIO/Main.java b/jlh/src/main/java/com/jlh/viewer/NIO/Main.java index 9903a6e..37032fa 100644 --- a/jlh/src/main/java/com/jlh/viewer/NIO/Main.java +++ b/jlh/src/main/java/com/jlh/viewer/NIO/Main.java @@ -23,6 +23,7 @@ public class Main { while (fileChannel.read(byteBuffer)!=-1){ byteBuffer.flip(); fileChannel1.write(byteBuffer); + byteBuffer.clear(); } diff --git a/jlh/src/main/java/com/jlh/viewer/Test.java b/jlh/src/main/java/com/jlh/viewer/Test.java index 6dea9cf..89c1560 100644 --- a/jlh/src/main/java/com/jlh/viewer/Test.java +++ b/jlh/src/main/java/com/jlh/viewer/Test.java @@ -3,6 +3,7 @@ package com.jlh.viewer; import java.io.IOException; import java.math.BigDecimal; import java.util.*; +import java.util.concurrent.Executors; /** * Created by jlh @@ -11,10 +12,22 @@ import java.util.*; public class Test { - private Integer a=1; + private static Integer a=1; + private static Integer b=a+1; + public static void main(String[] args) throws IOException { - ArrayList a = new ArrayList<>(); - HashMap b= new HashMap<>(); + Person[] a= new Person[]{new Person(2),new Person(1),new Person(3)}; + Arrays.stream(a).forEach(System.out::println); + Arrays.sort(a); + Arrays.stream(a).forEach(System.out::println); + HashMap mp = new HashMap<>(); + mp.put("key0","0"); + mp.entrySet().forEach(System.out::println); + mp.entrySet().forEach(m->{ + m.setValue("val"+m.getValue()); + }); + mp.entrySet().forEach(System.out::println); + } public class A{ private Integer a=2; @@ -22,4 +35,37 @@ public class Test { return a; } } + + public static class Person implements Comparable{ + private Integer old; + + public Person(Integer old) { + this.old = old; + } + + public Integer getOld() { + return old; + } + + public void setOld(Integer old) { + this.old = old; + } + + @Override + public String toString() { + return "Person{" + + "old=" + old + + '}'; + } + + @Override + public int compareTo(Person o) { + int res=0; + if (this.old{ + T t; + } + + + public static void main(String[] args) { + D d = new D(); + D d1 = new D(); +// D d2 = new D(); + List a =new ArrayList<>(); + a.add(new C()); + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/thread/ThreadPool.java b/jlh/src/main/java/com/jlh/viewer/thread/ThreadPool.java new file mode 100644 index 0000000..bad6554 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/thread/ThreadPool.java @@ -0,0 +1,18 @@ +package com.jlh.viewer.thread; + +import java.util.concurrent.*; + +/** + * com.jlh.viewer.thread + * Created by ASUS on 2017/4/25. + * 13:36 + */ +public class ThreadPool { + public static void main(String[] args) { + ExecutorService executorService = new ThreadPoolExecutor(5, 10, + 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), (r, executor) -> { + executor.getQueue().poll(); + executor.getQueue().offer(r); + }); + } +} -- Gitee From beee65e8a15b1df97f4995cab62dbe44a8127b0f Mon Sep 17 00:00:00 2001 From: jlhde123 ASUS <472327024@qq.com> Date: Wed, 3 May 2017 10:04:56 +0800 Subject: [PATCH 27/27] =?UTF-8?q?XX=20=E6=A8=A1=E5=9D=97=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + xx/pom.xml | 30 +++++++++++++++++++ .../java/com/xx/base/string/StringBase.java | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 xx/pom.xml diff --git a/pom.xml b/pom.xml index 39e3c3e..772942d 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ jlh + xx diff --git a/xx/pom.xml b/xx/pom.xml new file mode 100644 index 0000000..67038ad --- /dev/null +++ b/xx/pom.xml @@ -0,0 +1,30 @@ + + + + test + com.xx + 1.0-SNAPSHOT + + 4.0.0 + + xx + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + \ No newline at end of file diff --git a/xx/src/main/java/com/xx/base/string/StringBase.java b/xx/src/main/java/com/xx/base/string/StringBase.java index fb59790..cab9353 100644 --- a/xx/src/main/java/com/xx/base/string/StringBase.java +++ b/xx/src/main/java/com/xx/base/string/StringBase.java @@ -1,4 +1,4 @@ -package java.com.xx.base.string; +package com.xx.base.string; /** * author: XiongXin -- Gitee