From c7e8bbbb06a244562a93548a9cf06d1ba73d40da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=90=A6=E5=B3=B0?= Date: Sun, 16 Apr 2017 16:21:25 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=91=E7=9A=84?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/Thumbs.db | Bin 0 -> 11264 bytes .../byhieg/algorithmtutorial/BinaryTree.java | 188 ++++++++++++++++++ .../algorithmtutorialtest/BinaryTreeTest.java | 79 ++++++++ 3 files changed, 267 insertions(+) create mode 100644 images/Thumbs.db create mode 100644 src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java create mode 100644 src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java diff --git a/images/Thumbs.db b/images/Thumbs.db new file mode 100644 index 0000000000000000000000000000000000000000..65a9b7400285769b52ba274414de5da6a5a07121 GIT binary patch literal 11264 zcmeHt2T)W`*6$_foFxhfl9ikkB?ke?NEAtubCNIue^8JhARrkeNfvI z7;?^O=8d~=_x-=`)mDA`wqDhH_3gR$cjt89+u`)-K7CHtjE+z&CIFz>f7Aa*BXEoE>u>%2#&5zwEAqF_@zB6W zg8&UeG>Fh3MuP+mQZ&fWKu-aH0u4$usL-HB<8Sr+wYGmh|6d;gUBC@}c>`>K65xvd z^#lUYTKumQEr9d)HUD?p@DGZA%pV0o>c%ntY%hcXF+d!!1ndAw^d$n=0uq4mUwAt- zCjy89R%l55gBk&V7r?~$^BDib5C8N68_l<|{VC&LWdGUr|HbD1x8naw`+qL`Z~njE z2+*Tv6BZi9Yyd$26aY-xok4ozGr!IGzv;ih2>c`cqkf^50CII@HDv$;<9`}<6bw)R zurM)y-)O={-#GXF>wh=DQN{oC1n*=HFZ6G14AR@ z7bey=ws!Wf9UQ&9eSH1=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Si_>fTZ&4CiHeL^H~_s3Ye%~Bb55{*(406KdOW9m3@Gyc}=Lyc=U zRU28-UQ2ILQvCMuP0?k_5P0{zO(=cT(YbUcw)IJMSSid;BsA$QsDgb#b*NS`q9%qw z*@@faU?{uZ)kTQk!pS>lm%{m|zswm*O24$ixfEkVTGtJ`!9J)c$~*hTFLvKmw$Ij3 zqmI!;^^a#y=5NO?Sez1Rc*U;!)MQ$yy%+OWrvg&OH&W3@F4!jp&6htC6dj*81TV!9 z+vjxZ3#+=i3aGuu_sgW)3Nc)#-$Z)opWG5MYM2t;&rKvUr4Rb*N8P{TI)}6Jwx#O@ zB(^epVF4iX)(Xy>&e`*cR=gC z-ov88!VU7s0O|qPn4df+Kik~I-PhsuOsVvPP3h`qoydhY6p)Sf za^dL6i4|s)$_hzz=|us2BxSv_ER#BxQ9U9(>gvK(;yLFzm*@|_7uD%ldZ1?i8~j7# I|E`Gt1ISSgcmMzZ literal 0 HcmV?d00001 diff --git a/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java b/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java new file mode 100644 index 0000000..0fef3ec --- /dev/null +++ b/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java @@ -0,0 +1,188 @@ +package cn.byhieg.algorithmtutorial; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Stack; + +/** + * Created by byhieg on 17/4/15. + * Mail to byhieg@gmail.com + */ +public class BinaryTree { + + /** + * 递归的形式实现先续遍历 + * 根-左-右 + * + * @param root + */ + public static void preOrder1(Node root) { + if (root != null) { + System.out.print(root.data + " "); + preOrder1(root.left); + preOrder1(root.right); + } + } + + /** + * 非递归的形式实现先续遍历 + * 根-左-右 + * + * @param root + */ + public static void preOrder2(Node root) { + if (root != null) { + Stack stack = new Stack<>(); + stack.push(root); + while (!stack.isEmpty()) { + Node cur = stack.pop(); + System.out.print(cur.data + " "); + if (cur.right != null) { + stack.push(cur.right); + } + if (cur.left != null) { + stack.push(cur.left); + } + } + } + } + + /** + * 递归实现中序遍历 + * 左-根-右 + * + * @param root + */ + public static void inOrder1(Node root) { + if (root != null) { + inOrder1(root.left); + System.out.print(root.data + " "); + inOrder1(root.right); + } + } + + /** + * 非递归实现中序遍历 + * 左-根-右 + * + * @param root + */ + public static void inOrder2(Node root) { + if (root != null) { + Stack stack = new Stack<>(); + Node cur = root; + while (!stack.isEmpty() || cur != null) { + if (cur == null) { + Node node = stack.pop(); + System.out.print(node.data + " "); + cur = node.right; + } else { + stack.push(cur); + cur = cur.left; + } + + } + } + } + + /** + * 递归实现树的后续遍历 + * 左-右-根 + * + * @param root + */ + public static void postOrder1(Node root) { + if (root != null) { + postOrder1(root.left); + postOrder1(root.right); + System.out.print(root.data + " "); + } + } + + /** + * 非递归试树的后续遍历 + * 左-右-根 + * + * @param root + */ + public static void postOrder2(Node root) { + if (root != null) { + Stack tmpStack = new Stack<>(); + Stack resStack = new Stack<>(); + tmpStack.push(root); + while (!tmpStack.isEmpty()) { + Node cur = tmpStack.pop(); + resStack.push(cur); + if (cur.left != null) { + tmpStack.push(cur.left); + } + if (cur.right != null) { + tmpStack.push(cur.right); + } + } + + while (!resStack.isEmpty()) { + Node cur = resStack.pop(); + System.out.print(cur.data + " "); + } + } + } + + /** + * 层次遍历 + * + * @param root + */ + public static void levelOrder(Node root) { + if (root != null) { + Queue queue = new LinkedList<>(); + queue.offer(root); + while (!queue.isEmpty()) { + Node cur = queue.poll(); + System.out.print(cur.data + " "); + if (cur.left != null) { + queue.offer(cur.left); + } + if (cur.right != null) { + queue.offer(cur.right); + } + } + } + } + + /** + * 统计树的节点数 + * + * @param root + */ + public static int getNodes(Node root) { + if (root == null) { + return 0; + } + return getNodes(root.left) + getNodes(root.right) + 1; + } + + public static int getLeafs(Node root) { + if (root == null) { + return 0; + } + if (root.right == null && root.left == null) { + return 1; + } + return getLeafs(root.left) + getLeafs(root.right); + + } + + public static class Node { + public int data; + public Node left; + public Node right; + + + public Node(int data) { + this.data = data; + left = null; + right = null; + } + } +} diff --git a/src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java b/src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java new file mode 100644 index 0000000..8a3cf98 --- /dev/null +++ b/src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java @@ -0,0 +1,79 @@ +package cn.byhieg.algorithmtutorialtest; + +import cn.byhieg.algorithmtutorial.BinaryTree; +import cn.byhieg.iotutorial.bytestreamio.BufferdInputStreamExample; +import junit.framework.TestCase; + +/** + * Created by byhieg on 17/4/15. + * Mail to byhieg@gmail.com + */ +public class BinaryTreeTest extends TestCase { + + + BinaryTree.Node root = new BinaryTree.Node(1); + public void setUp() throws Exception { + super.setUp(); + BinaryTree.Node[] nodes = new BinaryTree.Node[10]; + nodes[0] = new BinaryTree.Node(2); + root.left = nodes[0]; + for (int i = 1 ; i < 10;i++) { + nodes[i] = new BinaryTree.Node(2 + i); + if (i % 2 == 0){ + nodes[i - 1].left = nodes[i]; + }else{ + nodes[i - 1].right = nodes[i]; + } + } + + } + + public void tearDown() throws Exception { + System.out.println(); + } + + public void testPreOrder1() throws Exception { + System.out.println("递归的先续遍历"); + BinaryTree.preOrder1(root); + } + + public void testPreOrder2() throws Exception { + System.out.println("非递归的先续遍历"); + BinaryTree.preOrder2(root); + } + + + public void testInOrder1() throws Exception { + System.out.println("递归的中序遍历"); + BinaryTree.inOrder1(root); + } + + public void testInOrder2() throws Exception { + System.out.println("非递归的中序遍历"); + BinaryTree.inOrder2(root); + } + + public void testPostOrder1() throws Exception { + System.out.println("递归的后续遍历"); + BinaryTree.postOrder1(root); + } + + public void testPostOrder2() throws Exception { + System.out.println("非递归的后续遍历"); + BinaryTree.postOrder2(root); + } + + public void testLevelOrder() throws Exception { + System.out.println("层次遍历"); + BinaryTree.levelOrder(root); + } + + public void testGetNodes() throws Exception { + System.out.println("节点数" + BinaryTree.getNodes(root)); + } + + public void testGetLeafs() throws Exception { + System.out.println("叶子数" + BinaryTree.getLeafs(root)); + } + +} \ No newline at end of file From 02de7695d1546d60d2d15bbe2bc6a9cd9a02f154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=90=A6=E5=B3=B0?= Date: Sun, 16 Apr 2017 16:58:48 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=91=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../byhieg/algorithmtutorial/BinaryTree.java | 69 +++++++++++++++++++ .../algorithmtutorialtest/BinaryTreeTest.java | 17 +++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java b/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java index 0fef3ec..62f4343 100644 --- a/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java +++ b/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java @@ -162,6 +162,11 @@ public static int getNodes(Node root) { return getNodes(root.left) + getNodes(root.right) + 1; } + /** + * 得到树的叶子节点的数目 + * @param root + * @return + */ public static int getLeafs(Node root) { if (root == null) { return 0; @@ -173,6 +178,70 @@ public static int getLeafs(Node root) { } + + /** + * 计算树的深度 + * @param root + * @return + */ + public static int getHeight(Node root){ + if (root == null) { + return 0; + } + int leftHeight = getHeight(root.left) + 1; + int rightHeight = getHeight(root.right) + 1; + return leftHeight > rightHeight ? leftHeight : rightHeight; + } + + /** + * 计算第K层的节点数 + * @param root + * @param k + * @return + */ + public static int calcKNodes(Node root, int k) { + if (root == null || k < 0) { + return 0; + } + if (k == 0){ + return 1; + } + return calcKNodes(root.left, k - 1) + calcKNodes(root.right, k - 1); + + } + + /** + * 判断两个树的结构是否相同 + * @param root1 + * @param root2 + * @return + */ + public static boolean isCommon(Node root1, Node root2) { + if (root1 == null && root2 == null) { + return true; + } else if (root1 == null || root2 == null) { + return false; + }else{ + boolean isLeftCommon = isCommon(root1.left, root2.left); + boolean isRightCommon = isCommon(root1.right, root2.right); + return isLeftCommon && isRightCommon; + } + } + + /** + * 得到树的镜像,即对于每一个节点,交换他们的左右孩子节点。 + * @param root + */ + public static void mirror(Node root) { + if (root != null) { + Node tmp = root.left; + root.left = root.right; + root.right = tmp; + mirror(root.left); + mirror(root.right); + } + } + public static class Node { public int data; public Node left; diff --git a/src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java b/src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java index 8a3cf98..9c1cfa5 100644 --- a/src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java +++ b/src/test/java/cn/byhieg/algorithmtutorialtest/BinaryTreeTest.java @@ -1,7 +1,6 @@ package cn.byhieg.algorithmtutorialtest; import cn.byhieg.algorithmtutorial.BinaryTree; -import cn.byhieg.iotutorial.bytestreamio.BufferdInputStreamExample; import junit.framework.TestCase; /** @@ -10,7 +9,6 @@ */ public class BinaryTreeTest extends TestCase { - BinaryTree.Node root = new BinaryTree.Node(1); public void setUp() throws Exception { super.setUp(); @@ -69,11 +67,22 @@ public void testLevelOrder() throws Exception { } public void testGetNodes() throws Exception { - System.out.println("节点数" + BinaryTree.getNodes(root)); + System.out.print("节点数" + BinaryTree.getNodes(root)); } public void testGetLeafs() throws Exception { - System.out.println("叶子数" + BinaryTree.getLeafs(root)); + System.out.print("叶子数" + BinaryTree.getLeafs(root)); + } + + public void testGetHeight() throws Exception { + System.out.print("树的高度" + BinaryTree.getHeight(root)); } + public void testCalcKNodes() throws Exception { + System.out.print("第2层的节点数" + BinaryTree.calcKNodes(root,2)); + } + + public void testMirror() throws Exception { + BinaryTree.mirror(root); + } } \ No newline at end of file From 8632db251c488e2bc5aec460b80c7e0a03c656ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=90=A6=E5=B3=B0?= Date: Tue, 2 May 2017 21:27:12 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E9=93=BE?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E7=9B=B8=E5=85=B3=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../byhieg/algorithmtutorial/BinaryTree.java | 28 ++++++ .../algorithmtutorial/SingleLinkList.java | 89 +++++++++++++++++++ .../SingleLinkListTest.java | 57 ++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 src/main/java/cn/byhieg/algorithmtutorial/SingleLinkList.java create mode 100644 src/test/java/cn/byhieg/algorithmtutorialtest/SingleLinkListTest.java diff --git a/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java b/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java index 62f4343..1b026ed 100644 --- a/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java +++ b/src/main/java/cn/byhieg/algorithmtutorial/BinaryTree.java @@ -242,6 +242,32 @@ public static void mirror(Node root) { } } + /** + * 得到两个节点的最近公共祖先节点。 + * 递归左右子树,如果返回的值都不为空,则表示在左右子树各找到一个target,因为最近的祖先就是cur + * 如果有一个为空,则就不为空就是最近公共祖先。 + * @param root + * @param target1 + * @param target2 + * @return + */ + public static Node findLCA(Node root, Node target1, Node target2) { + if (root == null) + return null; + + if (root == target1 || root == target2) { + return root; + } + Node left = findLCA(root.left, target1, target2); + Node right = findLCA(root.right, target1, target2); + if (left != null && right != null) { + return root; + } + return left != null ? left:right; + } + + + public static class Node { public int data; public Node left; @@ -254,4 +280,6 @@ public Node(int data) { right = null; } } + + } diff --git a/src/main/java/cn/byhieg/algorithmtutorial/SingleLinkList.java b/src/main/java/cn/byhieg/algorithmtutorial/SingleLinkList.java new file mode 100644 index 0000000..28b29ae --- /dev/null +++ b/src/main/java/cn/byhieg/algorithmtutorial/SingleLinkList.java @@ -0,0 +1,89 @@ +package cn.byhieg.algorithmtutorial; + +/** + * Created by byhieg on 17/5/2. + * Mail to byhieg@gmail.com + */ +public class SingleLinkList { + + + public Node head; + + /** + * 在当前链表尾部插入一个节点 + * + * @param data + * @return + */ + public Node insertFromTail(int data) { + Node cur = getHead(); + Node node = new Node(data); + if (cur == null) { + head = node; + return head; + } else { + while (cur.next != null) { + cur = cur.next; + } + cur.next = node; + } + return cur; + } + + /** + * 在当前链表头部插入一个节点 + * + * @param data + * @return + */ + public Node insertFromHead(int data) { + Node node = new Node(data); + node.next = head; + head = node; + return head; + } + + + public Node reverseLinkList() { + if (head == null) { + return head; + } + Node reverseHead = null; + Node cur = head; + Node prev = null; + while (cur != null) { + Node next = cur.next; + if (next == null) { + reverseHead = cur; + } + cur.next = prev; + prev = cur; + cur = next; + } + return reverseHead; + } + + /** + * 打印链表 + */ + public void printLinkList(Node head) { + Node cur = head; + while (cur != null) { + System.out.print(cur.data + " "); + cur = cur.next; + } + } + + public Node getHead() { + return head; + } + + public static class Node { + public int data; + public Node next; + + public Node(int data) { + this.data = data; + } + } +} diff --git a/src/test/java/cn/byhieg/algorithmtutorialtest/SingleLinkListTest.java b/src/test/java/cn/byhieg/algorithmtutorialtest/SingleLinkListTest.java new file mode 100644 index 0000000..862359a --- /dev/null +++ b/src/test/java/cn/byhieg/algorithmtutorialtest/SingleLinkListTest.java @@ -0,0 +1,57 @@ +package cn.byhieg.algorithmtutorialtest; + +import cn.byhieg.algorithmtutorial.SingleLinkList; +import junit.framework.TestCase; + +/** + * Created by byhieg on 17/5/2. + * Mail to byhieg@gmail.com + */ +public class SingleLinkListTest extends TestCase { + + + SingleLinkList linkList; + + public void setUp() throws Exception { + super.setUp(); + linkList = new SingleLinkList(); + } + + public void tearDown() throws Exception { +// linkList.printLinkList(linkList.head); +// System.out.println(); + } + + + public void testInsertFromTail() throws Exception { +// linkList.insertFromTail(1); +// linkList.insertFromTail(2); +// linkList.insertFromTail(3); +// linkList.insertFromTail(4); +// linkList.insertFromTail(5); +// linkList.insertFromTail(6); +// System.out.println("尾插入"); + } + + public void testInsertFromHead() throws Exception { +// linkList.insertFromHead(1); +// linkList.insertFromHead(2); +// linkList.insertFromHead(3); +// linkList.insertFromHead(4); +// linkList.insertFromHead(5); +// linkList.insertFromHead(6); +// System.out.println("头插入"); + } + public void testReverseLinkList() throws Exception { + linkList.insertFromHead(1); + linkList.insertFromHead(2); + linkList.insertFromHead(3); + linkList.insertFromHead(4); + linkList.insertFromHead(5); + linkList.insertFromHead(6); + linkList.printLinkList(linkList.reverseLinkList()); + } + public void testGetHead() throws Exception { + } + +} \ No newline at end of file From d200fb2c02e3ad351125a6a893dcb841e585fae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=90=A6=E5=B3=B0?= Date: Wed, 3 May 2017 17:23:12 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=98=BB=E5=A1=9E?= =?UTF-8?q?=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concurrent/blocking/ArrayBlock.java | 21 ++++++++++++ .../concurrent/blocking/Costumer.java | 31 +++++++++++++++++ .../concurrent/blocking/Producer.java | 30 ++++++++++++++++ .../blockingtest/ArrayBlockTest.java | 34 +++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java create mode 100644 src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java create mode 100644 src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java create mode 100644 src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java new file mode 100644 index 0000000..b31b674 --- /dev/null +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java @@ -0,0 +1,21 @@ +package cn.byhieg.threadtutorial.concurrent.blocking; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; + +/** + * Created by byhieg on 17/5/3. + * Mail to byhieg@gmail.com + */ +public class ArrayBlock { + + private BlockingQueue blockingQueue; + + public ArrayBlock(){ + blockingQueue = new ArrayBlockingQueue(1024); + } + + public BlockingQueue getBlockingQueue() { + return blockingQueue; + } +} diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java new file mode 100644 index 0000000..d69c647 --- /dev/null +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java @@ -0,0 +1,31 @@ +package cn.byhieg.threadtutorial.concurrent.blocking; + +import java.util.concurrent.BlockingQueue; + +/** + * Created by byhieg on 17/5/3. + * Mail to byhieg@gmail.com + */ +public class Costumer extends Thread{ + + private BlockingQueue blockingQueue; + + public Costumer(ArrayBlock arrayBlock) { + blockingQueue = arrayBlock.getBlockingQueue(); + this.setName("Costumer"); + } + + @Override + public void run() { + super.run(); + while (true) { + try { + Thread.sleep(2000); + String str = blockingQueue.take(); + System.out.println(getName() + " 取出数据 " + str); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java new file mode 100644 index 0000000..5298546 --- /dev/null +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java @@ -0,0 +1,30 @@ +package cn.byhieg.threadtutorial.concurrent.blocking; + +import java.util.concurrent.BlockingQueue; + +/** + * Created by byhieg on 17/5/3. + * Mail to byhieg@gmail.com + */ +public class Producer extends Thread { + + private BlockingQueue blockingQueue; + @Override + public void run() { + super.run(); + for (int i = 0 ; i < 5;i++) { + try { + System.out.println(getName() + " 生产数据"); + blockingQueue.put(i + ""); + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + public Producer(ArrayBlock arrayBlock){ + this.setName("Producer"); + blockingQueue = arrayBlock.getBlockingQueue(); + } +} diff --git a/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java new file mode 100644 index 0000000..8c695b2 --- /dev/null +++ b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java @@ -0,0 +1,34 @@ +package cn.byhieg.threadtutorialtest.concurrenttest.blockingtest; + +import cn.byhieg.threadtutorial.concurrent.blocking.ArrayBlock; +import cn.byhieg.threadtutorial.concurrent.blocking.Costumer; +import cn.byhieg.threadtutorial.concurrent.blocking.Producer; +import junit.framework.TestCase; + +import javax.swing.*; + +/** + * Created by byhieg on 17/5/3. + * Mail to byhieg@gmail.com + */ +public class ArrayBlockTest extends TestCase { + ArrayBlock block; + public void setUp() throws Exception { + super.setUp(); + block = new ArrayBlock(); + } + + public void tearDown() throws Exception { + } + + + public void testBlocking() throws Exception { + Producer producer = new Producer(block); + Costumer costumer = new Costumer(block); + producer.start(); + costumer.start(); + producer.join(); + costumer.join(); + + } +} \ No newline at end of file From 849f9f0f254cad65730340fbf06a319c12aa79e8 Mon Sep 17 00:00:00 2001 From: byhieg Date: Fri, 5 May 2017 15:45:47 +0800 Subject: [PATCH 05/17] nothing --- .../java/cn/byhieg/niotutorial/NioTest.java | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/main/java/cn/byhieg/niotutorial/NioTest.java b/src/main/java/cn/byhieg/niotutorial/NioTest.java index 7ee0a08..259ca37 100644 --- a/src/main/java/cn/byhieg/niotutorial/NioTest.java +++ b/src/main/java/cn/byhieg/niotutorial/NioTest.java @@ -6,6 +6,8 @@ import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.List; /** * Created by shiqifeng on 2017/4/10. @@ -14,22 +16,38 @@ public class NioTest { public static void main(String[] args) throws IOException { - String s = File.separator; - RandomAccessFile aFile = new RandomAccessFile("D:" + s + "read_file.txt","rw"); - FileChannel inChannel = aFile.getChannel(); - - ByteBuffer buf = ByteBuffer.allocate(48); - int bytesRead = inChannel.read(buf); - while (bytesRead != -1) { - buf.flip(); - while (buf.hasRemaining()) { - System.out.print((char) buf.get()); + for (int i = 2; i <= 100; i++) { + if(i == 2 || i == 5 || i == 7 || i == 3){ + System.out.print(i + " "); + continue; + } + if (i % 2 == 0 || i % 3 == 0 || i % 5 == 0 || i % 7 == 0) { + continue; } - buf.clear(); - bytesRead = inChannel.read(buf); + System.out.print(i + " "); + } + System.out.println(); + for (int i = 2 ; i <= 100;i++){ + if (isPrime(i)){ + System.out.print(i + " "); + } } + } + + + public static boolean isPrime(int n){ + if(n < 2){ + return false; + } + for (int i = 2; i <= Math.sqrt(n);i++){ + if (n % i == 0){ + return false; + } + } + return true; - aFile.close(); } + + } From 48d25d786f950fb80cd1690abcff7cbd789c9fbc Mon Sep 17 00:00:00 2001 From: byhieg Date: Fri, 5 May 2017 18:21:02 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8E=9F=E5=AD=90?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concurrent/atom/AtomFactory.java | 36 ++++++++++ .../concurrent/atom/MyObject.java | 12 ++++ .../atomtest/AtomFactoryTest.java | 69 +++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java create mode 100644 src/main/java/cn/byhieg/threadtutorial/concurrent/atom/MyObject.java create mode 100644 src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java new file mode 100644 index 0000000..36daa15 --- /dev/null +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java @@ -0,0 +1,36 @@ +package cn.byhieg.threadtutorial.concurrent.atom; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicIntegerArray; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Created by shiqifeng on 2017/5/5. + * Mail byhieg@gmail.com + */ +public class AtomFactory { + + private static final AtomFactory atomFactory = new AtomFactory(); + + private AtomFactory(){ + + } + + public static AtomFactory getInstance(){ + return atomFactory; + } + + public AtomicInteger createAtomInt(int a){ + return new AtomicInteger(a); + } + + public AtomicIntegerArray createAtomArray(int[] a) { + return new AtomicIntegerArray(a); + } + + public AtomicReference createAtomReference(MyObject object){ + AtomicReference objectAtomicReference = new AtomicReference<>(); + return objectAtomicReference; + } +} diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/MyObject.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/MyObject.java new file mode 100644 index 0000000..69ebbb6 --- /dev/null +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/MyObject.java @@ -0,0 +1,12 @@ +package cn.byhieg.threadtutorial.concurrent.atom; + +/** + * Created by shiqifeng on 2017/5/5. + * Mail byhieg@gmail.com + */ +public class MyObject { + + public String name = "byhieg"; + public int age = 24; + public volatile int id = 1; +} diff --git a/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java new file mode 100644 index 0000000..67aad49 --- /dev/null +++ b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java @@ -0,0 +1,69 @@ +package cn.byhieg.threadtutorialtest.concurrenttest.atomtest; + +import cn.byhieg.threadtutorial.concurrent.atom.AtomFactory; + +import cn.byhieg.threadtutorial.concurrent.atom.MyObject; +import junit.framework.TestCase; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicIntegerArray; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Created by shiqifeng on 2017/5/5. + * Mail byhieg@gmail.com + */ +public class AtomFactoryTest extends TestCase { + AtomicInteger integer; + AtomicIntegerArray array; + AtomicReference reference; + + public void setUp() throws Exception { + super.setUp(); + integer = AtomFactory.getInstance().createAtomInt(1); + } + + public void testAtomInt() throws Exception { + new Thread(()->{ + for (int i = 0; i < 10; i++) { + integer.getAndIncrement(); + System.out.println(getName() + " " + integer.get()); + } + }).start(); + + new Thread(()->{ + for (int i = 0; i < 10; i++) { + integer.getAndIncrement(); + System.out.println(getName() + " " + integer.get()); + } + }).start(); + + Thread.sleep(1000); + } + + public void testAtomArray() throws Exception { + int [] value = new int[]{1,2,3,4}; + array = AtomFactory.getInstance().createAtomArray(value); + array.getAndSet(1,10); + System.out.println(array.get(1)); + System.out.println(value[1]); + } + + public void testAtomRef()throws Exception { + MyObject object = new MyObject(); + reference = AtomFactory.getInstance().createAtomReference(object); + reference.set(object); + MyObject newObject = new MyObject(); + newObject.name = "xiaoli"; + reference.compareAndSet(object, newObject); + System.out.println(reference.get().name); + + } + + + public void tearDown() throws Exception { + + } + + +} \ No newline at end of file From 4d5f713eb52b6fba5cb2228c32bf3edb732569e1 Mon Sep 17 00:00:00 2001 From: byhieg Date: Sun, 7 May 2017 10:28:38 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8E=9F=E5=AD=90?= =?UTF-8?q?=E7=B1=BB=E6=9B=B4=E6=96=B0=E5=AD=97=E6=AE=B5=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../threadtutorial/concurrent/atom/AtomFactory.java | 12 ++++++------ .../concurrenttest/atomtest/AtomFactoryTest.java | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java index 36daa15..f5da772 100644 --- a/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/atom/AtomFactory.java @@ -1,9 +1,6 @@ package cn.byhieg.threadtutorial.concurrent.atom; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicIntegerArray; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.*; /** * Created by shiqifeng on 2017/5/5. @@ -30,7 +27,10 @@ public AtomicIntegerArray createAtomArray(int[] a) { } public AtomicReference createAtomReference(MyObject object){ - AtomicReference objectAtomicReference = new AtomicReference<>(); - return objectAtomicReference; + return new AtomicReference<>(); + } + + public AtomicIntegerFieldUpdater createAtomIntegerUpdate(String fieldName) { + return AtomicIntegerFieldUpdater.newUpdater(MyObject.class, fieldName); } } diff --git a/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java index 67aad49..e8b706a 100644 --- a/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java +++ b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/atomtest/AtomFactoryTest.java @@ -7,6 +7,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicIntegerArray; +import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicReference; /** @@ -17,6 +18,7 @@ public class AtomFactoryTest extends TestCase { AtomicInteger integer; AtomicIntegerArray array; AtomicReference reference; + AtomicIntegerFieldUpdater updater; public void setUp() throws Exception { super.setUp(); @@ -24,6 +26,7 @@ public void setUp() throws Exception { } public void testAtomInt() throws Exception { + System.out.println("int原子类"); new Thread(()->{ for (int i = 0; i < 10; i++) { integer.getAndIncrement(); @@ -42,6 +45,7 @@ public void testAtomInt() throws Exception { } public void testAtomArray() throws Exception { + System.out.println("原子类数组"); int [] value = new int[]{1,2,3,4}; array = AtomFactory.getInstance().createAtomArray(value); array.getAndSet(1,10); @@ -50,6 +54,7 @@ public void testAtomArray() throws Exception { } public void testAtomRef()throws Exception { + System.out.println("原子类"); MyObject object = new MyObject(); reference = AtomFactory.getInstance().createAtomReference(object); reference.set(object); @@ -57,7 +62,15 @@ public void testAtomRef()throws Exception { newObject.name = "xiaoli"; reference.compareAndSet(object, newObject); System.out.println(reference.get().name); + } + + public void testUpdater() throws Exception { + System.out.println("原子类更新字段"); + updater = AtomFactory.getInstance().createAtomIntegerUpdate("id"); + MyObject object = new MyObject(); + System.out.println(updater.getAndIncrement(object)); + System.out.println(updater.get(object)); } From dfdea96492994c84d4874c4a43dffad3e8be3fe0 Mon Sep 17 00:00:00 2001 From: byhieg Date: Sun, 7 May 2017 12:12:31 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Builder=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designpatterntutorial/builder/Person.java | 73 +++++++++++++++++++ .../BuilderTest.java | 16 ++++ 2 files changed, 89 insertions(+) create mode 100644 src/main/java/cn/byhieg/designpatterntutorial/builder/Person.java create mode 100644 src/test/java/cn/byhieg/designpatterntutorialtest/BuilderTest.java diff --git a/src/main/java/cn/byhieg/designpatterntutorial/builder/Person.java b/src/main/java/cn/byhieg/designpatterntutorial/builder/Person.java new file mode 100644 index 0000000..91077fd --- /dev/null +++ b/src/main/java/cn/byhieg/designpatterntutorial/builder/Person.java @@ -0,0 +1,73 @@ +package cn.byhieg.designpatterntutorial.builder; + +/** + * Created by shiqifeng on 2017/5/7. + * Mail byhieg@gmail.com + */ +public class Person { + + private int age; + private String name; + private int height; + private int weight; + + public int getAge() { + return age; + } + + public String getName() { + return name; + } + + public int getHeight() { + return height; + } + + public int getWeight() { + return weight; + } + + public Person(Builder builder) { + age = builder.age; + name = builder.name; + height = builder.height; + weight = builder.weight; + } + + @Override + public String toString() { + return "age = " + age + " name = " + name + " height = " + height + " weight = " + weight; + } + + public static class Builder{ + + private int age; + private String name; + private int height; + private int weight; + + public Builder setAge(int age) { + this.age = age; + return this; + } + + public Builder setName(String name) { + this.name = name; + return this; + } + + public Builder setHeight(int height) { + this.height = height; + return this; + } + + public Builder setWeight(int weight) { + this.weight = weight; + return this; + } + + public Person build() { + return new Person(this); + } + } +} diff --git a/src/test/java/cn/byhieg/designpatterntutorialtest/BuilderTest.java b/src/test/java/cn/byhieg/designpatterntutorialtest/BuilderTest.java new file mode 100644 index 0000000..2a67a00 --- /dev/null +++ b/src/test/java/cn/byhieg/designpatterntutorialtest/BuilderTest.java @@ -0,0 +1,16 @@ +package cn.byhieg.designpatterntutorialtest; + +import cn.byhieg.designpatterntutorial.builder.Person; +import junit.framework.TestCase; + +/** + * Created by shiqifeng on 2017/5/7. + * Mail byhieg@gmail.com + */ +public class BuilderTest extends TestCase { + public void testBuild() throws Exception { + Person person = new Person.Builder().setAge(24).setHeight(178).setName("byhieg").setWeight(80).build(); + System.out.println(person.toString()); + } + +} \ No newline at end of file From 3c1aee624f2df428e7986d32e493b8eeefaa1dc4 Mon Sep 17 00:00:00 2001 From: byhieg Date: Sun, 7 May 2017 16:03:30 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Alert=20Builder?= =?UTF-8?q?=E7=9A=84Builder=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../builder/SimpleDialog.java | 78 ++++++++++++++++++ .../builder/SimpleDialogController.java | 81 +++++++++++++++++++ .../SimpleDialogTest.java | 18 +++++ 3 files changed, 177 insertions(+) create mode 100644 src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialog.java create mode 100644 src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialogController.java create mode 100644 src/test/java/cn/byhieg/designpatterntutorialtest/SimpleDialogTest.java diff --git a/src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialog.java b/src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialog.java new file mode 100644 index 0000000..0d90062 --- /dev/null +++ b/src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialog.java @@ -0,0 +1,78 @@ +package cn.byhieg.designpatterntutorial.builder; + +/** + * Created by shiqifeng on 2017/5/7. + * Mail byhieg@gmail.com + */ +public class SimpleDialog { + + + public SimpleDialogController controller; + + public SimpleDialog(){ + controller = new SimpleDialogController(); + } + + public void setIcon(String icon) { + controller.setIcon(icon); + } + + public void setTitle(String title) { + controller.setTitle(title); + } + + public void setMessage(String message) { + controller.setMessage(message); + } + + public void setPositiveButton(String positiveButton) { + controller.setPositiveButton(positiveButton); + } + + public void setNegativeButton(String negativeButton) { + controller.setNegativeButton(negativeButton); + } + + + public static class Builder{ + SimpleDialogController.DialogParams P; + + public Builder(){ + P = new SimpleDialogController.DialogParams(); + } + + public Builder setIcon(String icon){ + P.icon = icon; + return this; + } + + public Builder setTitle(String title) { + P.title = title; + return this; + } + + public Builder setMessage(String message) { + P.message = message; + return this; + } + + public Builder setPositiveButton(String positiveButton) { + P.positiveButton = positiveButton; + return this; + } + + public Builder setNegativeButton(String negativeButton) { + P.negativeButton = negativeButton; + return this; + } + + public SimpleDialog create(){ + SimpleDialog dialog = new SimpleDialog(); + P.apply(dialog.controller); + System.out.println(" ICON = " + P.icon + " MESSAGE = " + P.message + " positiveButton = " + P.positiveButton + " negativeButton" + P.negativeButton); + return dialog; + } + } + + +} diff --git a/src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialogController.java b/src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialogController.java new file mode 100644 index 0000000..4d41b74 --- /dev/null +++ b/src/main/java/cn/byhieg/designpatterntutorial/builder/SimpleDialogController.java @@ -0,0 +1,81 @@ +package cn.byhieg.designpatterntutorial.builder; + +/** + * Created by shiqifeng on 2017/5/7. + * Mail byhieg@gmail.com + */ +public class SimpleDialogController { + + private String icon; + private String title; + private String message; + private String positiveButton; + private String negativeButton; + + public void setIcon(String icon) { + this.icon = icon; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setMessage(String message) { + this.message = message; + } + + public void setPositiveButton(String positiveButton) { + this.positiveButton = positiveButton; + } + + public void setNegativeButton(String negativeButton) { + this.negativeButton = negativeButton; + } + + public String getIcon() { + return icon; + } + + public String getTitle() { + return title; + } + + public String getMessage() { + return message; + } + + public String getPositiveButton() { + return positiveButton; + } + + public String getNegativeButton() { + return negativeButton; + } + + public static class DialogParams{ + public String icon; + public String title; + public String message; + public String positiveButton; + public String negativeButton; + + public void apply(SimpleDialogController controller) { + if (icon != null) { + controller.setIcon(icon); + } + if (title != null) { + controller.setTitle(title); + } + if (message != null) { + controller.setMessage(message); + } + if (positiveButton != null) { + controller.setPositiveButton(positiveButton); + } + if (negativeButton != null) { + controller.setNegativeButton(negativeButton); + } + } + } + +} diff --git a/src/test/java/cn/byhieg/designpatterntutorialtest/SimpleDialogTest.java b/src/test/java/cn/byhieg/designpatterntutorialtest/SimpleDialogTest.java new file mode 100644 index 0000000..002115a --- /dev/null +++ b/src/test/java/cn/byhieg/designpatterntutorialtest/SimpleDialogTest.java @@ -0,0 +1,18 @@ +package cn.byhieg.designpatterntutorialtest; + +import cn.byhieg.designpatterntutorial.builder.SimpleDialog; +import junit.framework.TestCase; + +/** + * Created by shiqifeng on 2017/5/7. + * Mail byhieg@gmail.com + */ +public class SimpleDialogTest extends TestCase { + + public void testBuilder() throws Exception { + SimpleDialog dialog = new SimpleDialog.Builder().setIcon("图标").setMessage("这是Dialog").setPositiveButton("确认").setNegativeButton("否定").create(); + + + } + +} \ No newline at end of file From c41dde8e35e07469c621afc9df071f95994b5d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=90=A6=E5=B3=B0?= Date: Tue, 9 May 2017 09:59:08 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=80=85=E6=B6=88=E8=B4=B9=E8=80=85-=E9=98=BB=E5=A1=9E?= =?UTF-8?q?=E9=98=9F=E5=88=97=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concurrent/blocking/ArrayBlock.java | 21 +++++++++++++++---- .../concurrent/blocking/Costumer.java | 2 +- .../concurrent/blocking/Producer.java | 3 +-- .../blockingtest/ArrayBlockTest.java | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java index b31b674..3687b31 100644 --- a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/ArrayBlock.java @@ -1,7 +1,10 @@ package cn.byhieg.threadtutorial.concurrent.blocking; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; +import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; + +import javax.sound.midi.SoundbankResource; +import java.lang.management.LockInfo; +import java.util.concurrent.*; /** * Created by byhieg on 17/5/3. @@ -11,8 +14,18 @@ public class ArrayBlock { private BlockingQueue blockingQueue; - public ArrayBlock(){ - blockingQueue = new ArrayBlockingQueue(1024); + public ArrayBlock(int index) { + switch (index) { + case 0: + blockingQueue = new ArrayBlockingQueue(3); + break; + case 1: + blockingQueue = new LinkedBlockingQueue<>(); + break; + case 2: + blockingQueue = new SynchronousQueue<>(); + break; + } } public BlockingQueue getBlockingQueue() { diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java index d69c647..f88b45f 100644 --- a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Costumer.java @@ -20,7 +20,7 @@ public void run() { super.run(); while (true) { try { - Thread.sleep(2000); + Thread.sleep(5000); String str = blockingQueue.take(); System.out.println(getName() + " 取出数据 " + str); } catch (InterruptedException e) { diff --git a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java index 5298546..a2d12eb 100644 --- a/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java +++ b/src/main/java/cn/byhieg/threadtutorial/concurrent/blocking/Producer.java @@ -14,9 +14,8 @@ public void run() { super.run(); for (int i = 0 ; i < 5;i++) { try { - System.out.println(getName() + " 生产数据"); blockingQueue.put(i + ""); - Thread.sleep(1000); + System.out.println(getName() + " 生产数据"); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java index 8c695b2..c48566c 100644 --- a/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java +++ b/src/test/java/cn/byhieg/threadtutorialtest/concurrenttest/blockingtest/ArrayBlockTest.java @@ -15,7 +15,7 @@ public class ArrayBlockTest extends TestCase { ArrayBlock block; public void setUp() throws Exception { super.setUp(); - block = new ArrayBlock(); + block = new ArrayBlock(2); } public void tearDown() throws Exception { From 5a4753da6357fef702ca6118b6ac07a6fcc7a85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=90=A6=E5=B3=B0?= Date: Sun, 18 Jun 2017 17:03:55 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=92=E5=B9=B6?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/byhieg/algorithmtutorial/Sort.java | 54 +++++++++++++++++++ .../algorithmtutorialtest/SortTest.java | 9 +++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/java/cn/byhieg/algorithmtutorial/Sort.java b/src/main/java/cn/byhieg/algorithmtutorial/Sort.java index 6229a1f..6794e42 100644 --- a/src/main/java/cn/byhieg/algorithmtutorial/Sort.java +++ b/src/main/java/cn/byhieg/algorithmtutorial/Sort.java @@ -128,6 +128,59 @@ public void bubbleSort2(int[] nums) { } } + /** + * 归并排序,将数组一分为二,对于每一子数组继续进行上述步骤,直到子数组只有1个元素,那么自然是有序的。 + * 然后不断合并两个数组,直到合并到整个数组。 + * 时间复杂度o(NlgN) + * 空间复杂度o(N) + * @param nums + */ + public void mergeSort(int[] nums) { + int length = nums.length; + int low = 0; + int high = length - 1; + realSort(nums, low, high); + } + + /** + * 归并排序真正的sort函数 + * @param nums 待排序的数组 + * @param low 最低位 + * @param high 最高位 + */ + private void realSort(int[] nums, int low, int high) { + int mid = (low + high) / 2; + if (low < high) { + realSort(nums, low, mid); + realSort(nums, mid + 1, high); + realMerge(nums, low, mid, high); + } + } + + private void realMerge(int[] nums, int low, int mid, int high) { + int[] tmpNums = new int[high - low + 1]; + int leftPoint = low; + int rightPoint = mid + 1; + int index = 0; + + while (leftPoint <= mid && rightPoint <= high) { + if (nums[leftPoint] < nums[rightPoint]) { + tmpNums[index++] = nums[leftPoint++]; + }else{ + tmpNums[index++] = nums[rightPoint++]; + } + } + + while (leftPoint <= mid) { + tmpNums[index++] = nums[leftPoint++]; + } + while (rightPoint <= high) { + tmpNums[index++] = nums[rightPoint++]; + } + + System.arraycopy(tmpNums, 0, nums, low, tmpNums.length); + } + /** * 快速排序,选定一个切分元素,每一轮排序后,都保证切分元素之前的元素都小于切分元素,切分元素之后的元素都大于切分元素 * 时间复杂度o(NlgN) @@ -263,4 +316,5 @@ public void sink(int [] nums, int i,int n) { } + } diff --git a/src/test/java/cn/byhieg/algorithmtutorialtest/SortTest.java b/src/test/java/cn/byhieg/algorithmtutorialtest/SortTest.java index 08c1d90..046daca 100644 --- a/src/test/java/cn/byhieg/algorithmtutorialtest/SortTest.java +++ b/src/test/java/cn/byhieg/algorithmtutorialtest/SortTest.java @@ -41,8 +41,13 @@ public void tearDown() throws Exception { // new Sort().quickSort(nums); // } - public void testHeapSort() throws Exception { - new Sort().heapSort(nums); +// public void testHeapSort() throws Exception { +// new Sort().heapSort(nums); +// } + + public void testMergeSort() throws Exception { + new Sort().mergeSort(nums); + } } \ No newline at end of file From e5a710dae2385bbff30cd53899a9197a0974df11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E7=90=A6=E5=B3=B0?= Date: Sat, 24 Jun 2017 21:44:36 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 ++++++++++++++---- .../JavaTutorial\347\233\256\345\275\225.jpg" | Bin 353150 -> 0 bytes .../JavaTutorial\347\233\256\345\275\225.png" | Bin 0 -> 400831 bytes 3 files changed, 17 insertions(+), 4 deletions(-) delete mode 100644 "images/JavaTutorial\347\233\256\345\275\225.jpg" create mode 100644 "images/JavaTutorial\347\233\256\345\275\225.png" diff --git a/README.md b/README.md index 49941a0..88bb506 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # JavaTutorial内容说明 该Java教程是学习Java过程中对Java知识点进行梳理。每一个包中的代码都有一个ReadMe来说明该包代码的作用以及知识点。 +src包里面是Java的源码,test包里面是针对源码的测试 -![Alt text](images/JavaTutorial目录.jpg) +![Alt text](images/JavaTutorial目录.png) ## ThreadTutorial内容说明 在源码路径下`cn.byhieg.threadtutorial`中放置的是Java多线程的代码和测试例子,在每一个章的包下,都有一个ReadMe来说明该章的知识点。 @@ -67,9 +68,6 @@ MapTutorial中的知识点有 - TreeMap的使用 - LinkedHashMap的使用 - - - ## AnnotationTutorial内容说明 在源码路径下`cn.byhieg.annotationtutorial`中放置的是Java注解类的代码和测试例子。在每一个包里面,都有一个ReadMe来说明该章的知识点。 @@ -79,7 +77,22 @@ MapTutorial中的知识点有 在源码路径下`cn.byhieg.iotutorial`中放置的是Java io类的代码和测试例子。在每一个包里面,都有一个ReadMe来说明该章的知识点。 +## DesignPattern内容说明 + +在源码路径下`cn.byhieg.designpatterntutorial`中放置的是Java 设计模式的代码和测试的例子。目前有 + +- 代理模式 +- 单例模式 +- builder模式 +## algorithmtutorial内容说明 +在源码路径下`cn.byhieg.algorithmtutorial`中放置的是Java实现的一些算法,内容如下: +- 二叉搜索树 +- 二叉树的常见的算法 +- 查找算法, +- 图的算法(DFS,BFS,Dijkstra) +- 单链表的算法 +- 排序算法。 diff --git "a/images/JavaTutorial\347\233\256\345\275\225.jpg" "b/images/JavaTutorial\347\233\256\345\275\225.jpg" deleted file mode 100644 index a4603a6e1fee9a5143d9d3147e1e181688b9c5e7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 353150 zcmeEubySq^y0#*SN~s7)BPkuyH6Tb02-1yoGc*jXCSam(+lCcc*lB5B0tL z&N=(rYoFu(_Wtu*>$sNG;vL@idG6=Fulu^Ldjb^ROJY4CdUEgHJuGP{aYf*h>%Dtu z{Etw8pIGyoy#+qqcTkjkd#|vMWCQr-v8|Mb!@Ya>Ga$3%L9@3u_Ku$(R7V7>P; zaQUl$@2Yz!w@<>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