diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3425b85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/* +target/* +*.iml \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index fa609d6..1401148 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,32 +1,16 @@ - - - - - - - - - - - - - - - - + - - + - - + + \ No newline at end of file diff --git a/.idea/libraries/Maven__io_netty_netty_all_5_0_0_Alpha2.xml b/.idea/libraries/Maven__io_netty_netty_all_5_0_0_Alpha2.xml new file mode 100644 index 0000000..c7b9c5c --- /dev/null +++ b/.idea/libraries/Maven__io_netty_netty_all_5_0_0_Alpha2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml new file mode 100644 index 0000000..a82457d --- /dev/null +++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index dfca8c4..5755a99 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + - - - - - 1.8 - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index fdedb92..452c3f5 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index ecdcd4c..db7ee93 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,115 @@ Javabasis Javabasis 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + +<<<<<<< HEAD + + + io.netty + netty-all + 5.0.0.Alpha2 + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + RELEASE + + + + cglib + cglib + 3.2.5 + + + + org.springframework + spring-jdbc + 5.0.3.RELEASE + +======= + + + io.netty + netty-all + 5.0.0.Alpha2 + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + RELEASE + + + + cglib + cglib + 3.2.5 + + + + org.springframework + spring-jdbc + 5.0.3.RELEASE + +>>>>>>> 24b1076e7ad80d6921ddc6d64256caadbbb6ec95 + + + com.alibaba + fastjson + 1.2.47 + + + + com.fasterxml.jackson.core + jackson-core + 2.9.4 + + + + com.fasterxml.jackson.core + jackson-databind + 2.9.4 + + + + org.javassist + javassist + 3.22.0-GA + + \ No newline at end of file diff --git a/src/main/java/ExceptionAndError/TestErroe.java b/src/main/java/ExceptionAndError/TestErroe.java new file mode 100644 index 0000000..4b49c20 --- /dev/null +++ b/src/main/java/ExceptionAndError/TestErroe.java @@ -0,0 +1,33 @@ +package ExceptionAndError; + +/** + * @author szh + * @create 2018-05-25 16:08 + **/ +public class TestErroe { + Runnable runnable =new Runnable() { + @Override + public void run() { + for(int i =0 ;i< 100000 ;i++){ +// if(i>50){ +// try { +// Thread.currentThread().sleep(1000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } + } + } + }; + private void startThread(){ + Thread thread =new Thread(runnable); + thread.start(); + thread.stop(); + } + + public static void main(String[] args) { + TestErroe testErroe =new TestErroe(); + testErroe.startThread(); + Thread.currentThread(); + } +} diff --git a/src/main/java/Interesting/ADDTest.class b/src/main/java/Interesting/ADDTest.class new file mode 100644 index 0000000..01da6fc Binary files /dev/null and b/src/main/java/Interesting/ADDTest.class differ diff --git a/src/main/java/Interesting/ADDTest.java b/src/main/java/Interesting/ADDTest.java new file mode 100644 index 0000000..cce522f --- /dev/null +++ b/src/main/java/Interesting/ADDTest.java @@ -0,0 +1,15 @@ +package Interesting; + + +/** + * @author szh + * @create 2018-06-06 20:30 + **/ +public class ADDTest { + public static void main(String[] args) { + int a=6,b; + b=(++a)+(++a)+(++a); + System.out.println(b); + System.out.println(a); + } +} diff --git a/src/main/java/Leetcode/AssignCookies.java b/src/main/java/Leetcode/AssignCookies.java new file mode 100644 index 0000000..2175c4e --- /dev/null +++ b/src/main/java/Leetcode/AssignCookies.java @@ -0,0 +1,25 @@ +package Leetcode; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author szh + * @create 2018-08-31 22:40 + **/ +public class AssignCookies { + public int findContentChildren(int[] g, int[] s) { + Map map =new HashMap<>(); + for(int i : g){ + map.put(i,map.get(i) == null? 1: map.get(i)+1); + } + int result=0; + for(int i :s){ + if(map.get(i) != null && map.get(i) !=0){ + map.put(i,map.get(i)-1); + result++; + } + } + return result; + } +} diff --git a/src/main/java/Leetcode/BackspaceStringCompare.java b/src/main/java/Leetcode/BackspaceStringCompare.java new file mode 100644 index 0000000..babb7ee --- /dev/null +++ b/src/main/java/Leetcode/BackspaceStringCompare.java @@ -0,0 +1,47 @@ +package Leetcode; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Stack; + +/** + * @author szh + * @create 2018-09-17 21:10 + **/ +public class BackspaceStringCompare { + public static void main(String[] args) { + new BackspaceStringCompare().backspaceCompare("ab#c","ad#c"); + } + public boolean backspaceCompare(String S, String T) { + Stack SU = new Stack<>(); + Stack TU = new Stack<>(); + char[] s1 =S.toCharArray(); + char[] t1 =T.toCharArray(); + for(int i =0 ; i < s1.length ;i++){ + if(s1[i] == '#'){ + if(!SU.isEmpty()){ + SU.pop(); + } + }else{ + SU.add(s1[i]); + } + } + for(int i =0 ; i < t1.length ;i++){ + if(t1[i] == '#'){ + if(!TU.isEmpty()){ + TU.pop(); + } + }else{ + TU.add(t1[i]); + } + } + while(!SU.isEmpty() && !TU.isEmpty()){ + if(SU.pop() == TU.pop()){ + continue; + }else{ + return false; + } + } + return SU.isEmpty() && TU.isEmpty() ? true :false; + } +} diff --git a/src/main/java/Leetcode/ContainsDuplicate.java b/src/main/java/Leetcode/ContainsDuplicate.java new file mode 100644 index 0000000..1d3534f --- /dev/null +++ b/src/main/java/Leetcode/ContainsDuplicate.java @@ -0,0 +1,30 @@ +package Leetcode; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author szh + * @create 2018-08-19 14:51 + **/ +public class ContainsDuplicate { + public boolean containsDuplicate(int[] nums) { + // for(int i =0 ;i set =new HashSet<>(); + for(int i=0 ;i five =new Stack<>(); + Stack ten =new Stack<>(); + int[] money =new int[bills.length]; + for(int i =0 ;i<=bills.length ;i++){ + if(bills[i] == 5){ + five.push(bills[i]); + } + if(bills[i] == 10){ + ten.push(bills[i]); + if(five.size() == 0){ + return false; + } + five.pop(); + } + if(bills[i] == 20){ + if(five.size() == 0){ + return false; + } + if(ten.size() == 0){ + if(five.size() >=3){ + five.pop(); + five.pop(); + five.pop(); + }else{ + return false; + } + }else{ + ten.pop(); + five.pop(); + } + } + } + return true; + } + + public static void main(String[] args) { + int[] a= new int[]{5,5,5,10,5,5,10,20,20,20}; + new LemonadeChange().lemonadeChange(a); + } +} diff --git a/src/main/java/Leetcode/MaxAreaofIsland.java b/src/main/java/Leetcode/MaxAreaofIsland.java new file mode 100644 index 0000000..18157b8 --- /dev/null +++ b/src/main/java/Leetcode/MaxAreaofIsland.java @@ -0,0 +1,49 @@ +package Leetcode; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author szh + * @create 2018-06-14 18:53 + **/ +public class MaxAreaofIsland { + public int maxAreaOfIsland(int[][] grid) { + List list =new ArrayList<>(); + for( int i =0 ;imax){ + max=i; + } + } + return max; + } + + public static void main(String[] args) { +// int[][] a =new int[][]{{1,1,0,0,0},{1,1,0,0,0},{0,0,0,1,1},{0,0,0,1,1}}; + int[][] a =new int[][]{{0},{0}}; + new MaxAreaofIsland().maxAreaOfIsland(a); + } +} diff --git a/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java b/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java new file mode 100644 index 0000000..c540a1b --- /dev/null +++ b/src/main/java/Leetcode/MinimumAbsoluteDifferenceinBST.java @@ -0,0 +1,130 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-07-25 22:41 + **/ +public class MinimumAbsoluteDifferenceinBST { + + TreeNode nodeval=null; + int min=Integer.MAX_VALUE; + + /////// + public int getMinimumDifferenceTwo(TreeNode root) { + if(root != null) + compareTreeNode(root); + return min; + } + public void compareTreeNode(TreeNode node){ + + if(node == null){ + return; + } + compareTreeNode(node.left); + if(nodeval != null){ + min =Math.min(node.val - nodeval.val ,min); + } + nodeval =node; + compareTreeNode(node.right); + } + + + + + + ///// + public int getMinimumDifference(TreeNode root) { + if(root != null){ + return compareTree(Integer.MAX_VALUE,root); + } + return 0; + } + public int compareTree(int min ,TreeNode node){ + + if(node.left != null){ + + TreeNode leftNode =node.left; + min=Math.min(min,compareTree(min,leftNode)); + int leftVal =Math.abs(node.val- node.left.val); + if(min > leftVal){ + min= leftVal; + } +// return compareTree(min,leftNode); + } + if(node.right != null){ + int rightVal =Math.abs(node.val- node.right.val); + if(min > rightVal){ + min= rightVal; + } + TreeNode rightNode =node.right; + min =Math.min(min,compareTree(min,rightNode)); + } + return min; + } + +// public int compareTreeV2(int min ,TreeNode root,TreeNode node){ +// +// int value = Math.abs(root.val - node.val); +// if(root.left != null){ +//// int leftVal =Math.abs(node.val- node.left.val); +//// if(min > leftVal){ +//// min= leftVal; +//// } +// TreeNode leftNode =node.left; +//// return compareTree(min,leftNode); +// } +// if(node.right != null){ +// int rightVal =Math.abs(node.val- node.right.val); +// if(min > rightVal){ +// min= rightVal; +// } +// TreeNode rightNode =node.right; +//// return compareTree(min,rightNode); +// } +// return min; +// } + int minDiff = Integer.MAX_VALUE; + TreeNode prev; + + public int getMinimum(TreeNode root) { + inorder(root); + return minDiff; + } + + public void inorder(TreeNode root) { + if (root == null) return; + inorder(root.left); + if (prev != null) minDiff = Math.min(minDiff, root.val - prev.val); + prev = root; + inorder(root.right); + } + + + public static void main(String[] args) { + TreeNode t =new TreeNode(1); + TreeNode t1 =new TreeNode(5); + TreeNode t2 =new TreeNode(3); + t1.left=t2; + t.right=t1; + +// TreeNode t =new TreeNode(236); +// TreeNode t1 =new TreeNode(104); +// TreeNode t2 =new TreeNode(227); +// TreeNode t3 =new TreeNode(701); +// TreeNode t4 =new TreeNode(911); +// t1.right=t2; +// t3.right=t4; +// t.left=t1; +// t.right=t3; +// System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimumDifference(t)); +// System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimum(t)); + System.out.println(new MinimumAbsoluteDifferenceinBST().getMinimumDifferenceTwo(t)); + } + +} + class TreeNode { + int val; + TreeNode left; + TreeNode right; + TreeNode(int x) { val = x; } + } diff --git a/src/main/java/Leetcode/MinimumDistanceBetweenBSTNodes.java b/src/main/java/Leetcode/MinimumDistanceBetweenBSTNodes.java new file mode 100644 index 0000000..0d15798 --- /dev/null +++ b/src/main/java/Leetcode/MinimumDistanceBetweenBSTNodes.java @@ -0,0 +1,58 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-08-24 22:20 + **/ +public class MinimumDistanceBetweenBSTNodes { +// public static int difference =1000; +// public static TreeNode node1; +// public int minDiffInBST(TreeNode root) { +// if(root != null){ +// compareNode(root); +// } +// return difference; +// } +// public void compareNode(TreeNode node){ +// if(node == null){ +// return ; +// } +// compareNode(node.left); +// if(node1 != null){ +// difference= Math.min(Math.abs(node.val - node1.val), difference); +// } +// node1 = node; +// compareNode(node.right); +// } +public static int difference1 =1000; + public static TreeNode node1; + public int minDiffInBST(TreeNode root) { + if(root != null){ + compareNode(root); + } + return difference1; + } + public void compareNode(TreeNode node){ + if(node == null){ + return ; + } + compareNode(node.left); + if(node1 != null){ + difference1= Math.min(difference1 , Math.abs(node.val - node1.val)); + } + node1 = node; + compareNode(node.right); + } + public static void main(String[] args) { + TreeNode t =new TreeNode(27); + TreeNode t1 =new TreeNode(34); + TreeNode t2 =new TreeNode(58); + TreeNode t3 =new TreeNode(50); + TreeNode t4 =new TreeNode(44); + t3.left = t4; + t2.left=t3; + t1.right=t2; + t.right=t1; + System.out.println(new MinimumDistanceBetweenBSTNodes().minDiffInBST(t)); + } +} diff --git a/src/main/java/Leetcode/MissingNumber.java b/src/main/java/Leetcode/MissingNumber.java new file mode 100644 index 0000000..099e7cc --- /dev/null +++ b/src/main/java/Leetcode/MissingNumber.java @@ -0,0 +1,29 @@ +package Leetcode; + +import java.util.Arrays; + +/** + * @author szh + * @create 2018-09-14 23:44 + **/ +public class MissingNumber { + public int missingNumber(int[] nums) { + Arrays.sort(nums); + if(nums == null || nums.length == 0){ + return 0; + } + int result =0; + int i =0; + for( ; i< nums.length ; i++){ + result += (i ^ nums[i]); + } + result = result ^ i; + return result; + } + + public static void main(String[] args) { + System.out.println(0 ^ 1); + System.out.println(1 ^ 2); + System.out.println((0 ^ 1)); + } +} diff --git a/src/main/java/Leetcode/MostCommonWord.java b/src/main/java/Leetcode/MostCommonWord.java new file mode 100644 index 0000000..93d6e64 --- /dev/null +++ b/src/main/java/Leetcode/MostCommonWord.java @@ -0,0 +1,51 @@ +package Leetcode; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * @author szh + * @create 2018-08-18 23:31 + **/ +public class MostCommonWord { + public static void main(String[] args) { + new MostCommonWord().mostCommonWord("Bob hit a ball, the hit BALL flew far after it was hit.", new String[]{"hit"}); + } + + public String mostCommonWord(String paragraph, String[] banned) { + String[] words = paragraph.split(" "); + Set set = new HashSet<>(); + for (String s : banned) { + set.add(s); + } + Map map = new HashMap<>(); + for (String word : words) { + StringBuffer sb = new StringBuffer(); + char[] cArray = word.toCharArray(); + for (char c : cArray) { + if (Character.isLetter(c)) { + sb.append(c); + } + } + // word= word.replace(",",""); + // word= word.replace(".",""); + word = sb.toString(); + word = word.toLowerCase(); + map.put(word, map.get(word) == null ? 1 : map.get(word) + 1); + } + for (String s : set) { + map.remove(s); + } + String max = null; + int maxNum = 0; + for (Map.Entry temp : map.entrySet()) { + if ((int) temp.getValue() > maxNum) { + maxNum = (int) temp.getValue(); + max = (String) temp.getKey(); + } + } + return max; + } +} diff --git a/src/main/java/Leetcode/NumberofBoomerangs.java b/src/main/java/Leetcode/NumberofBoomerangs.java new file mode 100644 index 0000000..fbb4c51 --- /dev/null +++ b/src/main/java/Leetcode/NumberofBoomerangs.java @@ -0,0 +1,72 @@ +package Leetcode; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author szh + * @create 2018-09-03 23:54 + **/ +public class NumberofBoomerangs { + public int numberOfBoomerangs(int[][] points) { + Map map =new HashMap<>(); + int res=0; + for(int i =0 ;i< points.length ;i++){ + for(int j=0 ;j< points.length ;j++){ + if(i == j){ + continue; + } + int ditance =getDistance(points[i],points[j]); + map.put(ditance,map.getOrDefault(ditance,0)+1); + } + for(int val :map.values()){ + res+=(val*2); + } + map.clear(); + } + return res; + + } + public int getDistance(int[] a ,int[] b){ + // int dx =(a[0]-b[0]) < 0 ? b[0]- a[0] :a[0]-b[0]; + int dx =a[0]-b[0]; + // int dy=(a[1]-b[1]) < 0 ? b[1]- a[1] :a[1]-b[1]; + int dy=a[1]-b[1] ; + return dx* dx + dy *dy; + } + + public static void main(String[] args) { +// int[][] a =new int[][]{new int[]{0,0},new int[]{0,0},new int[]{0,0}}; + int[][] a =new int[][]{{0,0},{1,0},{2,0}}; + new NumberofBoomerangs().numberOfBoomerangs(a); + new NumberofBoomerangs().numberOfBoomerangs2(a); + } + public int numberOfBoomerangs2(int[][] points) { + int res = 0; + + Map map = new HashMap<>(); + for(int i=0; i map =new HashMap<>(); + new PositionsofLargeGroups().largeGroupPositions(s); +; } + public List> largeGroupPositions(String S) { + char[] c =S.toCharArray(); + List> result =new ArrayList<>(); + int start =0; + for(int i =1 ;i=3){ + List temp =new ArrayList<>(); + temp.add(start); + temp.add(i-1); + result.add(temp); + } + start =i; + } + } + return result; + } +} diff --git a/src/main/java/Leetcode/RotateString.java b/src/main/java/Leetcode/RotateString.java new file mode 100644 index 0000000..bd5ea95 --- /dev/null +++ b/src/main/java/Leetcode/RotateString.java @@ -0,0 +1,63 @@ +package Leetcode; + +import java.math.BigInteger; + +/** + * @author szh + * @create 2018-08-16 22:48 + **/ +public class RotateString { + public boolean rotateString(String A, String B) { + String C = A +A ; + for(int i =0 ;i< C.length() ;i++){ + int index =i; + int j=0; + for(;j val){ + return compareAndSelect(root.left,val); + }else{ + return compareAndSelect(root.right,val); + } + } + public TreeNode compareAndSelect(TreeNode node , int val){ + if(node == null){ + return null; + } + if(node.val == val){ + return node; + } + if(node.val >val){ + return compareAndSelect(node.left,val); + }else{ + return compareAndSelect(node.right,val); + } + } + + class TreeNode { + int val; + TreeNode left; + TreeNode right; + + TreeNode(int x) { + val = x; + } + } +} diff --git a/src/main/java/Leetcode/StudentAttendanceRecord.java b/src/main/java/Leetcode/StudentAttendanceRecord.java new file mode 100644 index 0000000..033edb7 --- /dev/null +++ b/src/main/java/Leetcode/StudentAttendanceRecord.java @@ -0,0 +1,67 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-09-15 21:53 + **/ +public class StudentAttendanceRecord { + public static void main(String[] args) { +// char c1 = 'A'; +// char c2 = 'P'; +// char c3 = 'C'; +// System.out.println(c1 == 1); +// System.out.println(c1 ^ c2); +// int[] i = new int[10]; +// System.out.println('C' ^ 1); +// System.out.println('C' ^ 2); +// System.out.println('C' ^ 3); +// System.out.println('C' ^ 4); +// System.out.println('C' | 1); +// System.out.println('C' | 2); +// System.out.println('C' | 3); +// System.out.println('C' | 4); +// System.out.println('C' ^ 5); +// System.out.println('C' ^ 6); +// System.out.println('C' ^ 7); +// System.out.println('C' ^ 8); +// System.out.println('C' ^ 9); +// System.out.println('C' ^ 10); +// System.out.println('C' ^ 11); +// System.out.println('C' ^ 12); +// System.out.println('C' ^ 13); +// int count =0; +// System.out.println(upLouti(0, 20)); +// System.out.println(count); +// int[] a = new int[21]; +// a[0] = 1; +// a[1] = 1; +// a[2] = 1; +// +// for (int i = 3; i <= 20; i++) { +// a[i] = a[i-1] + a[i-3]; +// System.out.println(i + " " + a[i]); +// } + System.out.println(puCiZhuan(0, 20)); + } + + + private static int upLouti(int step ,int end ){ + if(step == end || step == end -1 ){ + return 1; + } + return upLouti(step+1,end) + upLouti(step+2,end); + } + + private static int puCiZhuan(int step ,int end){ + if(step >= end){ + return 0; + } + if(step == end -1){ + return 1; + } + if(step == end -3){ + return 2; + } + return puCiZhuan(step+1,end) + puCiZhuan(step + 3 ,end); + } +} diff --git a/src/main/java/Leetcode/bitand2bitCharac.java b/src/main/java/Leetcode/bitand2bitCharac.java new file mode 100644 index 0000000..3a65bcc --- /dev/null +++ b/src/main/java/Leetcode/bitand2bitCharac.java @@ -0,0 +1,40 @@ +package Leetcode; + +/** + * @author szh + * @create 2018-08-17 22:50 + **/ +public class bitand2bitCharac { + public boolean isOneBitCharacter(int[] bits) { + int len =bits.length; + if(bits == null || bits.length == 0){ + return false; + } + if(len == 1 && bits[len-1] == 0){ + return true; + } + if(len == 2 && bits[0] == 0){ + return true; + }else if(bits[0] == 1){ + return false; + } + if(len >=3){ + if(len % 2 == 0){ + if(bits[len-2] == 1){ + return false; + }else{ + return true; + } + }else{ + if(bits[len-3] == 1){ + return true; + } + } + } + return false; + } + + public static void main(String[] args) { + new bitand2bitCharac().isOneBitCharacter(new int[]{1,0,0}); + } +} diff --git a/src/main/java/Loop/Hello.asm b/src/main/java/Loop/Hello.asm new file mode 100644 index 0000000..73feaf0 Binary files /dev/null and b/src/main/java/Loop/Hello.asm differ diff --git a/src/main/java/Loop/LoopTest.asm b/src/main/java/Loop/LoopTest.asm new file mode 100644 index 0000000..73feaf0 Binary files /dev/null and b/src/main/java/Loop/LoopTest.asm differ diff --git a/src/main/java/Loop/LoopTest.class b/src/main/java/Loop/LoopTest.class new file mode 100644 index 0000000..9c85b02 Binary files /dev/null and b/src/main/java/Loop/LoopTest.class differ diff --git a/src/main/java/Loop/LoopTest.java b/src/main/java/Loop/LoopTest.java new file mode 100644 index 0000000..46d5f94 --- /dev/null +++ b/src/main/java/Loop/LoopTest.java @@ -0,0 +1,28 @@ +package Loop; + +/** + * @author szh + * @create 2018-05-21 20:31 + **/ +public class LoopTest { + private static void maxOut(){ + int[] a =new int[100]; + for(int i = 0; i<200 ;i++){ + for(int j=0;j<10;j++){ + a[i]=a[j]+1; + } + } + } + private static void minOut(){ + int[] a =new int[100]; + for(int i = 0; i<10 ;i++){ + for(int j=0;j<200;j++){ + a[i]=a[j]+1; + } + } + } + public static void main(String[] args){ + maxOut(); + minOut(); + } +} diff --git a/src/main/java/NettyInAction/ch2/echo/EchoClient.java b/src/main/java/NettyInAction/ch2/echo/EchoClient.java index bce4639..4481285 100644 --- a/src/main/java/NettyInAction/ch2/echo/EchoClient.java +++ b/src/main/java/NettyInAction/ch2/echo/EchoClient.java @@ -3,10 +3,7 @@ import io.netty.bootstrap.Bootstrap; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.EventLoopGroup; +import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; @@ -40,20 +37,29 @@ protected void initChannel(SocketChannel socketChannel) throws Exception { } }); ChannelFuture f= b.connect().sync(); + f.addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture channelFuture) throws Exception { + if(f.isSuccess()){ + System.out.println("有客户端链接"); + } + } + }); Channel channel =f.channel(); Scanner scanner =new Scanner(System.in); // ByteBuf byteBuf=null; while (true){ String Message =scanner.nextLine(); if(Message.length() != 0){ + if(Message.equals("exit")){ + break; + } // byteBuf.writeBytes(Message.getBytes()); System.out.println(Message); // f.channel().writeAndFlush(Unpooled.copiedBuffer(Message,CharsetUtil.UTF_8)); // f.channel().flush(); System.out.println(f.channel().isActive()); e.list.get(0).writeAndFlush(Unpooled.copiedBuffer(Message,CharsetUtil.UTF_8)); - }if(Message =="exit"){ - break; } } f.channel().closeFuture().sync(); diff --git a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java index 8eaf1f1..70f94e3 100644 --- a/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java +++ b/src/main/java/NettyInAction/ch2/echo/EchoClientHandle.java @@ -2,6 +2,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.util.CharsetUtil; @@ -12,12 +13,16 @@ /** * Created by szh on 2017/5/22. */ +@ChannelHandler.Sharable public class EchoClientHandle extends SimpleChannelInboundHandler{ public String Message; public static List list =new ArrayList<>(); - @Override +// @Override +// protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { +// System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); +// } protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { - System.out.println("客端接受到的数据是" + byteBuf.toString(CharsetUtil.UTF_8)); + System.out.println("客端接受到的数据是channelRead0" + byteBuf.toString(CharsetUtil.UTF_8)); } @Override @@ -34,6 +39,12 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buf = (ByteBuf) msg; - System.out.println("客端接受到的数据是" + buf.toString(CharsetUtil.UTF_8)); + System.out.println("客端接受到的数据是channelRead" + buf.toString(CharsetUtil.UTF_8)); + } + + @Override + protected void messageReceived(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { + System.out.println("客端接受到的数据是messageReceived" + byteBuf.toString(CharsetUtil.UTF_8)); + } } diff --git a/src/main/java/OperationTest/IntAndChar.java b/src/main/java/OperationTest/IntAndChar.java new file mode 100644 index 0000000..cafc139 --- /dev/null +++ b/src/main/java/OperationTest/IntAndChar.java @@ -0,0 +1,14 @@ +package OperationTest; + +/** + * @author szh + * @create 2018-06-08 23:30 + **/ +public class IntAndChar { + public static void main(String[] args) { + char c='C'; + System.out.println(90 - c); + String s ="qwert"; + System.out.println(s.substring(0, 2)); + } +} diff --git a/src/main/java/PECS/PECSTest.java b/src/main/java/PECS/PECSTest.java new file mode 100644 index 0000000..e0cb0cd --- /dev/null +++ b/src/main/java/PECS/PECSTest.java @@ -0,0 +1,25 @@ +package PECS; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author szh + * @create 2018-06-01 11:17 + **/ +public class PECSTest { + private void t(){ + List list =new ArrayList<>(); + B b = new B(); + A a =new A(); + } +} + +class A{ + +} +class B extends A{ + public void b(){ + System.out.println("b"); + } +} \ No newline at end of file diff --git a/src/main/java/SFVideoDowland/CssVideo/CssVideo.java b/src/main/java/SFVideoDowland/CssVideo/CssVideo.java new file mode 100644 index 0000000..ea115a9 --- /dev/null +++ b/src/main/java/SFVideoDowland/CssVideo/CssVideo.java @@ -0,0 +1,109 @@ +package SFVideoDowland.CssVideo; + +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * @author szh + * @create 2018-05-24 19:21 + **/ +public class CssVideo { + protected static void main(String[] args) { + start(); + } + private static void start(){ + CloseableHttpClient httpClient = HttpClients.createDefault(); + int i=18; +// while (i<290){ + + + try { + HttpGet httpGet=null; + if(i<10){ + httpGet = new HttpGet("https://media.video.segmentfault.com/eab963VTCl4LPZ4y8phbYaCjKqg=/lgOR6NwUEuGWs5MuNnHEW67PeDzu/00000"+String.valueOf(i)+".ts"); + }else if(i<100){ + httpGet = new HttpGet("https://media.video.segmentfault.com/eab963VTCl4LPZ4y8phbYaCjKqg=/lgOR6NwUEuGWs5MuNnHEW67PeDzu/0000"+String.valueOf(i)+".ts"); + }else{ + httpGet = new HttpGet("https://media.video.segmentfault.com/eab963VTCl4LPZ4y8phbYaCjKqg=/lgOR6NwUEuGWs5MuNnHEW67PeDzu/000"+String.valueOf(i)+".ts"); + } + +// httpGet.setHeader("accept-ranges", "bytes6"); +// httpGet.setHeader("access-control-allow-origin", "*"); +// httpGet.setHeader("access-control-expose-headers", "X-Log, X-Reqid"); +// httpGet.setHeader("access-control-max-age", "2592000"); +// httpGet.setHeader("age", "0"); +// httpGet.setHeader("cache-control", "max-age=2592000"); +// httpGet.setHeader("content-disposition", "inline; filename=\"000001.ts\"; filename*=utf-8' '000001.ts"); //TODO +// httpGet.setHeader("content-length", "558172"); +// httpGet.setHeader("content-transfer-encoding", "tbinary"); +// httpGet.setHeader("date", "video/mp2t"); +// httpGet.setHeader("content-type", "Thu, 24 May 2018 11:05:04 GMT"); +// httpGet.setHeader("etag", "FunorSPF5uS7h3Tn4lxYCLZu0zGv"); +// httpGet.setHeader("expires", "Sat, 23 Jun 2018 11:05:04 GMT"); +// httpGet.setHeader("expires", "Sat, 23 Jun 2018 11:05:04 GMT"); +// httpGet.setHeader("last-modified", "Tue, 02 Jan 2018 06:50:51 GMT"); +// httpGet.setHeader("server", "marco/2.2"); +// httpGet.setHeader("status", "200"); +// httpGet.setHeader("via", "T.11.-, V.mix-gd-can-005, T.69.N, M.cun-hb-wuh-069"); +// httpGet.setHeader("x-log", "mc.g/404;rs12_12.sel/not found;rs11_12.sel;rwro.get:1;RS.dbs:1;RS:1;mc.s;mc.g;IO:33"); +// httpGet.setHeader("x-m-log", "QNM:xs446;QNM3:23"); +// httpGet.setHeader("x-m-reqid", "1RkAACcY3UsWOygV"); +// httpGet.setHeader("x-qiniu-zone", "1"); +// httpGet.setHeader("x-qnm-cache", "Hit"); +// httpGet.setHeader("x-reqid", "q1QAAK99xfjqEiYV"); +// httpGet.setHeader("x-request-id", "36e9b5c2525194a6147b248e0cf2be26"); +// httpGet.setHeader("x-slice-complete-length", "558172"); +// httpGet.setHeader("x-slice-etag", "T.11.-, V.mix-gd-can-005, T.69.N, M.cun-hb-wuh-069"); +// httpGet.setHeader("x-slice-size", "FunorSPF5uS7h3Tn4lxYCLZu0zGv"); +// httpGet.setHeader("x-source", "C/200"); +// httpGet.setHeader("x-svr", "IO"); + httpGet.setHeader("Origin", "https://segmentfault.com"); + httpGet.setHeader("Referer", "https://segmentfault.com/l/1500000012666812/play"); + httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"); + CloseableHttpResponse response = httpClient.execute(httpGet); + try { + HttpEntity httpEntity = response.getEntity(); + if (httpClient != null) { + InputStream inputStream = httpEntity.getContent(); + File file = new File("D:\\JavaBasis\\cookies\\0000"+String.valueOf(i)+".ts"); + FileOutputStream fileout = new FileOutputStream(file); + byte[] bytes = new byte[1024]; + int len; + while ((len = inputStream.read(bytes)) != -1) { +// String s = new String(bytes, 0, len); + fileout.write(bytes, 0, len); + fileout.flush(); + } + fileout.close(); + inputStream.close(); + } + +// int len =0; +// while ((len=inputStream.read()) !=-1){ +// +// + } catch (Exception e) { + e.printStackTrace(); + } + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } +// i++; +// } + } + public void te(){ + + } +} diff --git a/src/main/java/SFVideoDowland/CssVideo/ProtectTest.java b/src/main/java/SFVideoDowland/CssVideo/ProtectTest.java new file mode 100644 index 0000000..4466387 --- /dev/null +++ b/src/main/java/SFVideoDowland/CssVideo/ProtectTest.java @@ -0,0 +1,15 @@ +package SFVideoDowland.CssVideo; + +/** + * @author szh + * @create 2018-05-24 23:31 + **/ +public class ProtectTest { + protected int i; + protected void protectMethod(){ + + } + public void publicMethod(){ + + } +} diff --git a/src/main/java/SetAndMap/TreeSetAndTreeMap/PojoTest.java b/src/main/java/SetAndMap/TreeSetAndTreeMap/PojoTest.java new file mode 100644 index 0000000..dcd53f3 --- /dev/null +++ b/src/main/java/SetAndMap/TreeSetAndTreeMap/PojoTest.java @@ -0,0 +1,35 @@ +package SetAndMap.TreeSetAndTreeMap; + + +/** + * @author szh + * @create 2018-05-24 17:03 + **/ +public class PojoTest { + private int id; + private String name; + + public PojoTest() { + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public PojoTest(int id, String name) { + this.id = id; + this.name = name; + } +} diff --git a/src/main/java/SetAndMap/TreeSetAndTreeMap/ProT.java b/src/main/java/SetAndMap/TreeSetAndTreeMap/ProT.java new file mode 100644 index 0000000..6786a0f --- /dev/null +++ b/src/main/java/SetAndMap/TreeSetAndTreeMap/ProT.java @@ -0,0 +1,14 @@ +package SetAndMap.TreeSetAndTreeMap; + +import SFVideoDowland.CssVideo.ProtectTest; + +/** + * @author szh + * @create 2018-05-24 23:32 + **/ +public class ProT extends ProtectTest{ + public static void main(String[] args) { + ProtectTest protectTest =new ProtectTest(); + protectTest.publicMethod(); + } +} diff --git a/src/main/java/SetAndMap/TreeSetAndTreeMap/TestTreeSet.java b/src/main/java/SetAndMap/TreeSetAndTreeMap/TestTreeSet.java new file mode 100644 index 0000000..d59f57a --- /dev/null +++ b/src/main/java/SetAndMap/TreeSetAndTreeMap/TestTreeSet.java @@ -0,0 +1,130 @@ +package SetAndMap.TreeSetAndTreeMap; + +import com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream; +import org.junit.Test; +import sun.reflect.generics.tree.Tree; + +import java.util.*; + +/** + * TreeSet的测试类 + * + * @author szh + * @create 2018-05-24 15:53 + **/ +public class TestTreeSet{ + + + private static void construct(){ + Comparator comparator =new Comparator() { + @Override + public int compare(String o1, String o2) { + if(o1.toCharArray()[0] >o2.toCharArray()[0]){ + return -1; + }else if(o1.toCharArray()[0] == o2.toCharArray()[0]){ + return 0; + }else{ + return 1; + } + } + }; + TreeSet treeSet =new TreeSet<>(comparator); + List list =new ArrayList<>(); + list.add("a"); + list.add("d"); + list.add("b"); + treeSet.addAll(list); + Iterator iterator =treeSet.iterator(); + while (iterator.hasNext()){ + System.out.println(iterator.next()); + } + Comparator comparator1 = (Comparator) treeSet.comparator(); + TreeSet treeSet1 =new TreeSet<>(comparator1); + treeSet1.add("c"); + treeSet1.add("g"); + treeSet1.add("a"); + Iterator iterator1 =treeSet1.iterator(); + while (iterator1.hasNext()){ + System.out.println(iterator1.next()); + } +// TreeSet treeSet1 =treeSet.comparator(); +// Iterator iterator2=treeSet1.iterator(); +// while (iterator2.hasNext()){ +// System.out.println(iterator.next()); +// } + } + + private static void compareWithCpmparator(){ + Stack stack =new Stack<>(); + TreeSet treeSet =new TreeSet<>(); + List list =new ArrayList<>(); + list.add("a"); + list.add("d"); + list.add("b"); + treeSet.addAll(list); + Iterator iterator =treeSet.iterator(); + while (iterator.hasNext()){ + System.out.println(iterator.next()); + } + Comparator comparator1 = (Comparator) treeSet.comparator(); + if (comparator1 == null){ + System.out.println("comparator1是空"); + }else { + System.out.println("comparator1不是空"); + } + } + + private static void com(){ + TreeSet treeSet =new TreeSet<>(); + treeSet.add(new PojoTest(1,"a")); + treeSet.add(new PojoTest(2,"b")); + treeSet.add(new PojoTest(3,"c")); + Iterator iterator =treeSet.iterator(); + while (iterator.hasNext()){ + System.out.println(iterator.next().getName()); + } + } + public static void main(String[] args) { +// construct(); +// compareWithCpmparator(); + com(); + } + + @Test + public void calPoints() { + String[] ops=new String[]{"5","-2","4","C","D","9","+","+"}; + Stack stack =new Stack<>(); + int total=0; + for(String s : ops ){ + if(s.equals("C")){ + total = total-stack.peek(); + stack.pop(); +// stack.push(total); + }else if(s.equals("D")){ + int num =stack.peek(); + num =num *2; + total+=num; + stack.push(num); + }else if(s.equals("+")){ + int str1=stack.pop(); + int str2 =stack.pop(); + int num =str1+str2; + stack.push(str2); + stack.push(str1); + total =total+str1+str2; + stack.push(num); + }else{ + total+=Integer.valueOf(s); + stack.push(Integer.valueOf(s)); + } + + } + if(stack.size() <=1){ +// return Integer.valueOf(stack.pop()); + System.out.println(stack.pop()); + } + System.out.println(total); + // return Integer.valueOf(stack.pop())+Integer.valueOf(stack.pop()); + } + +} diff --git a/src/main/java/StringTest/SplitTest.java b/src/main/java/StringTest/SplitTest.java new file mode 100644 index 0000000..29218c9 --- /dev/null +++ b/src/main/java/StringTest/SplitTest.java @@ -0,0 +1,17 @@ +package StringTest; + +/** + * @author szh + * @create 2018-05-30 22:07 + **/ +public class SplitTest { + public static void main(String[] args) { + String s ="Iam qwe"; + String[] s1=s.split(" "); +// System.out.println(s.substring(1)); + System.out.println(s.substring(0, 1)); +// for( String s2 :s1){ +// System.out.println(s2); +// } + } +} diff --git a/src/main/java/T/AbstractTest.java b/src/main/java/T/AbstractTest.java new file mode 100644 index 0000000..3209d66 --- /dev/null +++ b/src/main/java/T/AbstractTest.java @@ -0,0 +1,49 @@ +package T; + +/** + * @author szh + * @create 2018-05-28 0:10 + **/ +public abstract class AbstractTest { + public void methodWithBody(){ + System.out.println("body"); + } + public abstract void methodWithoutBody(); + protected void protectWithBody(){ + System.out.println("protectBody"); + } + protected abstract void ProtectWithoutBody(); + private void privateWithBody(){ + System.out.println("protectBody"); + } + abstract void defaultWithOutMethod(); + void defaultWithBody(){ + + } + public int i; + protected int pi; + private int privatei; + int defaulti; + + public static void main(String[] args) { + AbstractTest abstractTest =new AbstractTest() { + @Override + public void methodWithoutBody() { + + } + + @Override + protected void ProtectWithoutBody() { + + } + + @Override + void defaultWithOutMethod() { + + } + }; + } + + + +} diff --git a/src/main/java/T/ExceptionTest.java b/src/main/java/T/ExceptionTest.java new file mode 100644 index 0000000..babcf4f --- /dev/null +++ b/src/main/java/T/ExceptionTest.java @@ -0,0 +1,15 @@ +package T; + +/** + * @author szh + * @create 2018-05-28 22:50 + **/ +public class ExceptionTest { + private void test(){ + try{ + + }catch (Error e){ + e.printStackTrace(); + } + } +} diff --git a/src/main/java/T/InaAnTest.class b/src/main/java/T/InaAnTest.class new file mode 100644 index 0000000..9f832f2 Binary files /dev/null and b/src/main/java/T/InaAnTest.class differ diff --git a/src/main/java/T/InaAnTest.java b/src/main/java/T/InaAnTest.java new file mode 100644 index 0000000..bf25f2f --- /dev/null +++ b/src/main/java/T/InaAnTest.java @@ -0,0 +1,13 @@ +package T; + +/** + * @author szh + * @create 2018-05-31 0:29 + **/ +public class InaAnTest { + int a; + { + a=0; + System.out.println(a); + } +} diff --git a/src/main/java/T/IntTest.class b/src/main/java/T/IntTest.class new file mode 100644 index 0000000..ed9f744 Binary files /dev/null and b/src/main/java/T/IntTest.class differ diff --git a/src/main/java/T/IntTest.java b/src/main/java/T/IntTest.java new file mode 100644 index 0000000..dc068a4 --- /dev/null +++ b/src/main/java/T/IntTest.java @@ -0,0 +1,20 @@ +package T; + +/** + * @author szh + * @create 2018-05-30 23:55 + **/ +public class IntTest { + { + System.out.println(this.a); + System.out.println("a"); + } + int a; + { + System.out.println("b"); + } + + public static void main(String[] args) { + new IntTest(); + } +} diff --git a/src/main/java/T/InterfaceTest.java b/src/main/java/T/InterfaceTest.java new file mode 100644 index 0000000..0a22250 --- /dev/null +++ b/src/main/java/T/InterfaceTest.java @@ -0,0 +1,16 @@ +package T; + +interface InterfaceTest { + default void say(){ + System.out.println(s); + } + public static void a(){ + + } + public abstract void s(); + int i=0; + public static int j =0; + public static final int m=0; + public int n=0; + String s =new String("1"); +} diff --git a/src/main/java/T/T2.java b/src/main/java/T/T2.java new file mode 100644 index 0000000..b46bc04 --- /dev/null +++ b/src/main/java/T/T2.java @@ -0,0 +1,113 @@ +package T; + +import org.junit.Test; + +import java.util.HashSet; +import java.util.Random; +import java.util.Set; +import java.util.UUID; + +/** + * c + * + * @author szh + * @create 2018-04-09 0:57 + **/ +public class T2 { +// @Test +// public void uniqueMorseRepresentations() { +// String[] words=new String[]{"gin", "zen", "gig", "msg"}; +// String[] s1 =new String[]{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; +// Set set =new HashSet<>(); +// for(int i =0 ;i=0 ;j--) +// if(array[j] > array[j+1]){ +// int temp =array[j+1]; +// array[j+1]=array[j]; +// array[j]=temp; +// } +// } +// for( int i :array){ +// System.out.println(i); +// } +// } +// @Test +// public void maopaoSortTest(){ +// int[] array =new int[]{2,4,5,7,1,3,6,8,9,0}; +// for(int i =0 ;iarray[j]){ +// int temp =array[j]; +// array[j]=array[i]; +// array[i]=temp; +// } +// } +// } +// for(int i : array){ +// System.out.println(i); +// } +// } +// +// @Test + public void quickSortTest(int[] array , int head ,int end ){ +// int[] array =new int[]{2,4,5,7,1,3,6,8,9,0}; + if(head >= end || array == null || array.length <1){ + return; + } + int i=head; + int j=end; + int mid =array[(head + end) /2]; + while(i <= j){ + while (array[i] < mid){ + i++; + } + while (array[j] > mid){ + j--; + } + if(i <= j){ + int temp =array[i]; + array[i] =array[j]; + array[j]=temp; + ++i; + --j; +// }else if(i == j){ +// ++i; + } + } + quickSortTest(array,head,j); + quickSortTest(array,i,end); + } + + public static void main(String[] args) { + int[] array =new int[]{2,4,5,7,1,3,6,8,9,0}; + new T2().quickSortTest(array,0,array.length-1); + for(int i :array){ + System.out.println(i); + } + + } + @Test + public void te(){ + UUID uuid = UUID.randomUUID(); + System.out.println(uuid); + } + +} diff --git a/src/main/java/T/TestT.java b/src/main/java/T/TestT.java new file mode 100644 index 0000000..aea3352 --- /dev/null +++ b/src/main/java/T/TestT.java @@ -0,0 +1,47 @@ +package T; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * 测试泛型的一些例子 + * + * @author szh + * @create 2018-04-07 21:14 + **/ +public class TestT { + public static void main(String[] args) { + new TestT().selfDividingNumbers(1, 22); + } + + public List selfDividingNumbers(int left, int right) { + List list = new ArrayList<>(); + for (; left <= right; left++) { + int[] temp = StirngToIntaray(String.valueOf(left)); + boolean flag = true; + for (int i = 0; i < temp.length; i++) { + if (temp[i] == 0){ + continue; + } + if (left % temp[i] != 0) { + flag = false; + } + } + if (flag) { + list.add(left); + } + } + return list; + } + + public int[] StirngToIntaray(String s) { + int[] result = new int[s.length()]; + char[] c = s.toCharArray(); + for (int i = 0; i < s.length(); i++) { + result[i] = Integer.parseInt(Character.toString(c[i])); + } + return result; + } +} diff --git a/src/main/java/Thread/Bank/system/BankSystem.java b/src/main/java/Thread/Bank/system/BankSystem.java index b9345e7..acf44e4 100644 --- a/src/main/java/Thread/Bank/system/BankSystem.java +++ b/src/main/java/Thread/Bank/system/BankSystem.java @@ -13,7 +13,8 @@ public void doSpend() { if (Store.queue.isEmpty()) { executor.shutdownNow(); } else { - executor.execute(new ServiceWindows(Store.queue.poll())); // 执行操作任务 +// executor.execute(new ServiceWindows(Store.queue.poll())); // 执行操作任务 + executor.execute(new PopWindows()); // 执行操作任务 } } } diff --git a/src/main/java/Thread/Bank/system/InitBank.java b/src/main/java/Thread/Bank/system/InitBank.java index 3ee7dc7..a288e02 100644 --- a/src/main/java/Thread/Bank/system/InitBank.java +++ b/src/main/java/Thread/Bank/system/InitBank.java @@ -30,7 +30,8 @@ private void init(){ while (!Store.queue.isEmpty()){ // System.out.println("队列是否为空+!"+!Store.queue.isEmpty()); // bankSystem.doSpend(); - this.executorService.execute(new ServiceWindows(Store.queue.poll())); +// this.executorService.execute(new ServiceWindows(Store.queue.poll())); + this.executorService.execute(new PopWindows()); } // System.out.println("已经执行到这里了"); diff --git a/src/main/java/Thread/elevator/EevatorControll.java b/src/main/java/Thread/elevator/EevatorControll.java index 26ce6e9..fc8e4a7 100644 --- a/src/main/java/Thread/elevator/EevatorControll.java +++ b/src/main/java/Thread/elevator/EevatorControll.java @@ -1,7 +1,5 @@ package Thread.elevator; -import org.junit.Test; - import java.util.ArrayList; import java.util.List; import java.util.Scanner; diff --git a/src/main/java/httpgrab/Grab.java b/src/main/java/httpgrab/Grab.java index 883603e..cdc1517 100644 --- a/src/main/java/httpgrab/Grab.java +++ b/src/main/java/httpgrab/Grab.java @@ -50,19 +50,6 @@ public void sengRe() { InputStream inputStream = httpEntity.getContent(); readFormServer(inputStream); } - //lastact - //oldtopics - //sid -// for(int i=0;i iterator =set.iterator(); -// while(iterator.hasNext()){ -// System.out.println(iterator.next()); -// } } public void RequestPhoto(String tid) { @@ -184,7 +118,6 @@ public void RequestPhoto(String tid) { CloseableHttpClient httpClient = HttpClients.createDefault(); try { str = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8)); -// System.out.println(url + "---------------downloadPhotoRequest"); HttpGet httpGet = new HttpGet("http://bbs.zhiyoo.com/forum.php" + "?" + str); httpGet.setHeader("Cookie", readCookie("D:\\JavaBasis\\cookies\\downloadcookies.txt")); httpGet.setHeader("Refer", "http://bbs.zhiyoo.com/tforum-98-1192-1.html"); @@ -216,20 +149,11 @@ public void RequestPhoto(String tid) { } } - /* - 获取点击分类后的页面 - */ - public void sortTidGet() { - - } - /* 请求图片地址获取图片然后保存 */ public void SavePhoto(InputStream inputStream) throws IOException { -// File file =new File(fileName); DataInputStream dataInputStream = new DataInputStream(inputStream); -// FileOutputStream fileOutputStream= new FileOutputStream(file); byte[] bytes = new byte[1024]; int len = 0; Pattern pattern = null; @@ -250,9 +174,6 @@ public void SavePhoto(InputStream inputStream) throws IOException { if (!set.contains(newSteing)) set.add(newSteing); } -// fileOutputStream.write(bytes,0,len); -// fileOutputStream.flush(); - } showSet(); } @@ -261,11 +182,6 @@ public void SavePhoto(InputStream inputStream) throws IOException { 测试Set */ public void showSet() { -// Iterator iterator =set.iterator(); -// while (iterator.hasNext()) -// { -// System.out.println(iterator.next()+"--------set"); -// } Iterator iterator = set.iterator(); while (iterator.hasNext()) { String s = iterator.next(); @@ -277,15 +193,8 @@ public void showSet() { } public void downloadPhotoRequest(String url, String fileName) { -// List params = new ArrayList(); -// params.add(new BasicNameValuePair("mod", "")); -// params.add(new BasicNameValuePair("tid", "")); -// params.add(new BasicNameValuePair("extra", "")); -// String str = null; CloseableHttpClient httpClient = HttpClients.createDefault(); try { -// str = EntityUtils.toString(new UrlEncodedFormEntity(params, Consts.UTF_8)); -// System.out.println(url + "---------------downloadPhotoRequest"); HttpGet httpGet = new HttpGet(url); httpGet.setHeader("Cookie", readCookie("D:\\JavaBasis\\cookies\\downloadcookies.txt")); httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"); @@ -320,16 +229,7 @@ public void download(String fileName, InputStream inputStream) throws IOExceptio while ((len = dataInputStream.read(bytes)) != -1) { fileOutputStream.write(bytes, 0, len); fileOutputStream.flush(); -// showSet(); } } -// @Test -// public void Stringte() -// { -// String s ="http://attach.zhiyoo.com/forum/201607/08/201044yr9d7earyjdafm48.jpg file=http://attach.zhiyoo.com/forum/201607/08/201044yr9d7earyjdafm48.jpg"; -// System.out.println(s.indexOf(".jpg", 0)); -// System.out.println(s.substring(0, s.indexOf(".jpg", 0)+4)); -// System.out.println(s); -// } } diff --git a/src/main/java/maxwellTest/IndexTest.java b/src/main/java/maxwellTest/IndexTest.java new file mode 100644 index 0000000..95e7819 --- /dev/null +++ b/src/main/java/maxwellTest/IndexTest.java @@ -0,0 +1,23 @@ +package maxwellTest; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 关于列表按照索引插入 + * + * @author szh + * @create 2018-09-02 13:37 + **/ +public class IndexTest { + public static void main(String[] args) { + List list =new ArrayList<>(); + list.add(2,2); + Map map =new HashMap<>(); + for(int i : map.values()){ + + } + } +} diff --git a/src/main/java/operation/ScaleTest.java b/src/main/java/operation/ScaleTest.java new file mode 100644 index 0000000..af28612 --- /dev/null +++ b/src/main/java/operation/ScaleTest.java @@ -0,0 +1,28 @@ +package operation; + +import org.junit.Test; + +/** + * @author szh + * @create 2018-05-31 17:32 + **/ +public class ScaleTest { + public static void main(String[] args) { + System.out.println(Integer.toBinaryString(10)) ; + System.out.println(Integer.toBinaryString(10 >> 1)); +// System.out.println(5 ^ 10); + + } + @Test + public void hasAlternatingBits() { + int n=6; + int m= n ^ (n >>1); + if(n == 1){ + System.out.println(true); + } + if(m == n+(n/2) && m /2 !=0){ + System.out.println(true); + } + System.out.println(false); + } +} diff --git a/src/main/java/operation/XORTest.java b/src/main/java/operation/XORTest.java new file mode 100644 index 0000000..5857ee1 --- /dev/null +++ b/src/main/java/operation/XORTest.java @@ -0,0 +1,25 @@ +package operation; + +import org.junit.Test; + +public class XORTest { + @Test + public void main1() { + char c1 ='a'; + char c2='b'; + System.out.println(c1 ^ c2); + } + public int numJewelsInStones(String J, String S) { + char[] c1= J.toCharArray(); + char[] c2 =S.toCharArray(); + int total=0; + for(int i =0 ;i JavasistTest: main() +@enduml \ No newline at end of file diff --git a/src/main/java/reflec/aop/cglibtest/AOPSEQ.puml b/src/main/java/reflec/aop/cglibtest/AOPSEQ.puml new file mode 100644 index 0000000..c5c1eb1 --- /dev/null +++ b/src/main/java/reflec/aop/cglibtest/AOPSEQ.puml @@ -0,0 +1,11 @@ +@startuml +CGLIBProxy -> ProxyUtil: new() +ProxyUtil --> Reflect: new() +Reflect --> Reflect: getAnnotationClass() +Reflect --> ProxyUtil: return reflect +ProxyUtil --> CGLIBProxy: return proxyutil +CGLIBProxy --> Enhancer : getProxy() +Enhancer --> CGLIBProxy : return enhancer +CGLIBProxy --> ProxyUtil : generateEntity(ProxyEntity proxyEntity) +CGLIBProxy --> ProxyUtil : doAfter(ProxyEntity proxyEntity,Map map) +@enduml \ No newline at end of file diff --git a/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java b/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java index d286573..b3a9416 100644 --- a/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java +++ b/src/main/java/reflec/aop/cglibtest/CGLIBProxy.java @@ -19,38 +19,15 @@ public CGLIBProxy(Object target) throws ClassNotFoundException { } public T getProxy(){ -// Enhancer enhancer =new Enhancer(); -// enhancer.setSuperclass(this.target.getClass()); -// enhancer.setCallback(this); -// return (T) enhancer.create(); return (T) new Enhancer().create(this.target.getClass(),this); } public T getProxy(Class clazz){ -// Enhancer enhancer =new Enhancer(); -// enhancer.setSuperclass(this.target.getClass()); -// enhancer.setCallback(this); -// return (T) enhancer.create(); return (T) new Enhancer().create(this.target.getClass(),this); } @Override public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { -// System.out.println("---------before"); -// Object result =proxy.invokeSuper(obj, args); -//// System.out.println(obj.toString()); -//// System.out.println(args.toString()); -// System.out.println("------------after"); -// return result; - ProxyEntity proxyEntity =new ProxyEntity(proxy,this.target.getClass(),obj,method,args); return proxyUtil.generateEntity(proxyEntity); - } - //反射调用 - public void before(){ - - } - //反射调用 - public void after(){ - } } diff --git a/src/main/java/reflec/aop/cglibtest/CglibTest.java b/src/main/java/reflec/aop/cglibtest/CglibTest.java index afae31f..9a1d9a9 100644 --- a/src/main/java/reflec/aop/cglibtest/CglibTest.java +++ b/src/main/java/reflec/aop/cglibtest/CglibTest.java @@ -8,6 +8,6 @@ public class CglibTest { public static void main(String args[]) throws ClassNotFoundException { Music music = new Music(); CGLIBProxy cglibProxy = new CGLIBProxy(music); - ((Music)cglibProxy.getProxy()).sing("ceshi de "); + ((Music)cglibProxy.getProxy()).sing("正在唱歌"); } } diff --git a/src/main/java/reflec/aop/cglibtest/ProxyUtil.java b/src/main/java/reflec/aop/cglibtest/ProxyUtil.java index 7910f84..4d8a720 100644 --- a/src/main/java/reflec/aop/cglibtest/ProxyUtil.java +++ b/src/main/java/reflec/aop/cglibtest/ProxyUtil.java @@ -11,11 +11,6 @@ * Created by szh on 2017/4/22. */ public class ProxyUtil { - // ProxyEntity proxyEntity; -// -// public ProxyUtil(ProxyEntity proxyEntity) { -// this.proxyEntity = proxyEntity; -// } /* 加载出所有的before注解 生成invokesuper方法 @@ -34,27 +29,20 @@ public void getMethod(String name) { //该方法负责代理 public Object generateEntity(ProxyEntity proxyEntity) throws Throwable { -// System.out.println("测试before注解的方法"); // -// Map methodMap =reflect.getMap(); -// for(Map.Entry map :methodMap.entrySet() ){ -// if(map.getValue().equals(proxyEntity.getClazz().toString().substring())) -// } -// System.out.println(proxyEntity.getMethodProxy().toString()); String proxyMethodValue = proxyEntity.getMethod().toString().substring(proxyEntity.getMethod().toString().lastIndexOf(" ") + 1, proxyEntity.getMethod().toString().indexOf("(")); -// System.out.println(proxyMethodValue); //reflec.aop.cglibtest.Music.sing Map methodMap = reflect.getMap(); for (Map.Entry map : methodMap.entrySet()) { if (map.getValue().equals(proxyMethodValue)) { String[] str = mapKeyDivision(map.getKey()); if (str[2].equals("before")) { - Class clazz = Class.forName(str[1], false, Thread.currentThread().getContextClassLoader()); // 加载该类 + /* 加载该类 */ + Class clazz = Class.forName(str[1], false, Thread.currentThread().getContextClassLoader()); Method method = clazz.getDeclaredMethod(str[0]); - method.invoke(clazz.newInstance(), null); // 这一步需要原始的类 + /* 这一步需要原始的类 */ + method.invoke(clazz.newInstance(), null); } } } -// System.out.println(proxyEntity.getClazz().toString().subSequence(6,proxyEntity.getClazz().toString().length())); - //在这里是因为无法很好解决后置通知 return doAfter(proxyEntity,methodMap); } private Object doAfter(ProxyEntity proxyEntity,Map map) throws Throwable { @@ -74,7 +62,6 @@ private Object doAfter(ProxyEntity proxyEntity,Map map) throws T } private String[] mapKeyDivision(String value) { -// String value="beforeSing-reflec.aop.cglibtest.Player-before"; String[] str = new String[10]; str[0] = value.substring(0, value.indexOf("-")); str[1] = value.substring(value.indexOf("-") + 1, value.lastIndexOf("-")); diff --git a/src/main/java/reflec/aop/cglibtest/Reflect.java b/src/main/java/reflec/aop/cglibtest/Reflect.java index 39d7c68..51d4dc8 100644 --- a/src/main/java/reflec/aop/cglibtest/Reflect.java +++ b/src/main/java/reflec/aop/cglibtest/Reflect.java @@ -35,24 +35,13 @@ public void getAnnotationClass() throws ClassNotFoundException { Before before =method.getAnnotation(Before.class); // 获取注解 ,在这里如果是clazz.getAnnotation()获取的是类注解 String beforeValue=before.value(); map.put(method.getName()+ "-"+clazzName+"-"+"before",beforeValue.substring(0,beforeValue.length()-2)); // 存入的是方法名和注解名 -// System.out.println(method.getName()+ "-"+clazzName+"-"+"before"); //输出结果 beforeSing-reflec.aop.cglibtest.Player -// System.out.println(beforeValue.substring(0,beforeValue.length()-2)+"------------------beforeValue"); } if (method.isAnnotationPresent(After.class)) { After after =method.getAnnotation(After.class); // 获取注解 ,在这里如果是clazz.getAnnotation()获取的是类注解 String afterValue=after.value(); map.put(method.getName()+ "-"+clazzName+"-"+"after",afterValue.substring(0,afterValue.length()-2)); -// System.out.println(afterValue); } } } } -// public static void main(String args[]) throws ClassNotFoundException { -//// getAnnotationClass(); -// } -// private void divisionValue(String name) throws ClassNotFoundException { -// String headStr=name.substring(0,name.lastIndexOf(".")); -// String endStr=name.substring(name.lastIndexOf(".")+1,name.length()); -//// map.put(headStr,endStr); // 存入以防止 -// } } diff --git a/src/main/java/reflec/aop/test/BeforeEat.java b/src/main/java/reflec/aop/test/BeforeEat.java index fe29a30..1a3b8d7 100644 --- a/src/main/java/reflec/aop/test/BeforeEat.java +++ b/src/main/java/reflec/aop/test/BeforeEat.java @@ -11,11 +11,11 @@ public class BeforeEat { @Before("reflec.aop.test.Eat.startEat()") public void beforeStart() { - System.out.println("开始吃饭前的准备"); + System.out.println("吃饭前的准备"); } @After("reflec.aop.test.Eat.startEat()") public void afterEat() { - System.out.println("吃饭完毕以后"); + System.out.println("吃完之后的离场"); } } diff --git a/src/main/java/reflec/aop/test/Eat.java b/src/main/java/reflec/aop/test/Eat.java index f34e862..5850839 100644 --- a/src/main/java/reflec/aop/test/Eat.java +++ b/src/main/java/reflec/aop/test/Eat.java @@ -8,5 +8,4 @@ public class Eat { public void startEat(){ System.out.println("开始吃饭"); } - }