Skip to content

Commit 5ed5803

Browse files
author
jossc
committed
1.添加数据结构
1 parent 4d395c6 commit 5ed5803

10 files changed

Lines changed: 311 additions & 2 deletions

File tree

src/main/java/com/basics/dynamicAgecy/CglibProxy.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.basics.dynamicAgecy;
22

33
import com.basics.agency.PerformanceMonior;
4-
import net.sf.cglib.proxy.Callback;
54
import net.sf.cglib.proxy.Enhancer;
65
import net.sf.cglib.proxy.MethodInterceptor;
76
import net.sf.cglib.proxy.MethodProxy;
@@ -24,11 +23,11 @@ public Object getProxy(Class clazz) {
2423
return enhancer.create();
2524
}
2625

26+
@Override
2727
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
2828
PerformanceMonior.begin(o.getClass().getName()+"."+method.getName());
2929
Object result = methodProxy.invokeSuper(o, objects);
3030
PerformanceMonior.end();
31-
3231
Object proxyObject = getProxy(this.getClass());
3332
return result;
3433
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.concurrent.cache;
2+
3+
/**
4+
* @ClassName LhsPadding
5+
* @Author chenzhuo
6+
* @Version 1.0
7+
* @Date 2019/12/9 7:51 下午
8+
**/
9+
public class LhsPadding {
10+
11+
protected long p1, p2, p3, p4, p5, p6, p7;
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.concurrent.cache;
2+
3+
/**
4+
* @ClassName RhsPadding
5+
* @Author chenzhuo
6+
* @Version 1.0
7+
* @Date 2019/12/9 7:52 下午
8+
**/
9+
public class RhsPadding extends Value {
10+
11+
protected long p9, p10, p11, p12, p13, p14, p15;
12+
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.concurrent.cache;
2+
3+
import sun.util.resources.ga.LocaleNames_ga;
4+
5+
import java.util.concurrent.RecursiveTask;
6+
7+
/**
8+
* @ClassName RunTask
9+
* @Author chenzhuo
10+
* @Version 1.0
11+
* @Date 2019/12/9 9:08 下午
12+
**/
13+
public class RunTask<T> extends RecursiveTask<T> {
14+
15+
private long start;
16+
17+
private long end;
18+
19+
private static final long THRESHOLD = 2;
20+
21+
public RunTask(long start, long end) {
22+
this.start = start;
23+
this.end = end;
24+
}
25+
26+
@Override
27+
protected T compute() {
28+
long threshold = start - end;
29+
Long sum = 0L;
30+
if (threshold < THRESHOLD) {
31+
for (long l = start; l < end; l++) {
32+
sum = sum + 1;
33+
}
34+
return (T) sum;
35+
}
36+
return null;
37+
}
38+
39+
40+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.concurrent.cache;
2+
3+
/**
4+
* @ClassName Value
5+
* @Author chenzhuo
6+
* @Version 1.0
7+
* @Date 2019/12/9 7:51 下午
8+
**/
9+
public class Value extends LhsPadding {
10+
11+
protected volatile long value;
12+
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.concurrent.thread.forkjoin;
2+
3+
import java.util.concurrent.ForkJoinPool;
4+
import java.util.concurrent.ForkJoinTask;
5+
6+
/**
7+
* @ClassName ForkJoinTest
8+
* @Author chenzhuo
9+
* @Version 1.0
10+
* @Date 2019/12/9 7:28 下午
11+
**/
12+
public class ForkJoinTest {
13+
14+
public static void main(String[] args) {
15+
ForkJoinPool joinPool = new ForkJoinPool();
16+
/*ForkJoinTask forkJoinTask =
17+
joinPool.execute(forkJoinTask);
18+
forkJoinTask.get();
19+
*/
20+
21+
}
22+
}

src/main/java/com/datastructure/package-info.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
* @Description 数据结构相关
33
* 1.线性结构
44
* a.数组
5+
*
56
* b.arrayList
67
* c.linkList
8+
*
79
* d.queue
810
* 1.单向队列
911
* 2.循环单向队列
1012
* 3.双向队列
1113
* 4.循环双想队列
14+
* e.stack 栈
15+
* {@link com.datastructure.stack.StackArray}
16+
* 可以扩展的栈 {@link com.datastructure.stack.StackCapacityArray}
17+
*
18+
*
19+
*
1220
*
1321
* @Date 2019/5/31 14:57
1422
* @author by chenzhuo
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.datastructure.queue;
2+
3+
/**
4+
* 顺序队列
5+
*
6+
* @ClassName ArrayQueue
7+
* @Author chenzhuo
8+
* @Version 1.0
9+
* @Date 2019/12/11 12:53 下午
10+
**/
11+
public class ArrayQueue {
12+
13+
private String[] items;
14+
15+
private int n = 0;
16+
17+
/**
18+
* 头部指针
19+
*/
20+
private int head = 0;
21+
22+
/**
23+
* 尾部指针
24+
*/
25+
private int tail = 0;
26+
27+
28+
public ArrayQueue(int n) {
29+
this.n = n;
30+
items = new String[n];
31+
}
32+
33+
/**
34+
* 入队列
35+
*
36+
* @param item
37+
* @return
38+
*/
39+
public boolean enqueue(String item) {
40+
if (tail == n) {
41+
return false;
42+
}
43+
items[tail] = item;
44+
++tail;
45+
return true;
46+
}
47+
48+
public boolean enqueueUpdate(String item) {
49+
if (tail == n) {
50+
if (head == 0) {
51+
return false;
52+
}
53+
/**
54+
* 进行数据前移
55+
*/
56+
for (int i = head; i < tail; i++) {
57+
items[i - head] = items[i];
58+
}
59+
tail -= head;
60+
head = 0;
61+
}
62+
63+
items[tail] = item;
64+
++tail;
65+
return true;
66+
}
67+
68+
/**
69+
* 出队列
70+
*
71+
* @return
72+
*/
73+
public String dequeue() {
74+
if (head == tail) {
75+
return null;
76+
}
77+
String ret = items[head];
78+
++head;
79+
return ret;
80+
}
81+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.datastructure.queue;
2+
3+
/**
4+
* 链表队列
5+
*
6+
* @ClassName LinkQueue
7+
* @Author chenzhuo
8+
* @Version 1.0
9+
* @Date 2019/12/15 8:52 下午
10+
**/
11+
public class LinkQueue<T> {
12+
13+
private Node<T> head = null;
14+
15+
private Node<T> tail = null;
16+
17+
public void enqueue(String value) {
18+
if (tail == null) {
19+
Node<T> newNode = new Node<T>(value, null);
20+
head = newNode;
21+
tail = newNode;
22+
} else {
23+
tail.next = new Node<T>(value, null);
24+
tail = tail.next;
25+
}
26+
}
27+
28+
public String dequeue() {
29+
if (head == null) {
30+
return null;
31+
}
32+
33+
String value = head.data;
34+
head = head.next;
35+
if (head == null) {
36+
tail = null;
37+
}
38+
return value;
39+
}
40+
41+
42+
private static class Node<T> {
43+
44+
private String data;
45+
46+
private Node<T> next;
47+
48+
public Node(String data, Node<T> next) {
49+
this.data = data;
50+
this.next = next;
51+
}
52+
53+
public String getData() {
54+
return data;
55+
}
56+
}
57+
58+
public static void main(String[] args) {
59+
LinkQueue<String> linkQueue =new LinkQueue<>();
60+
linkQueue.enqueue("hhhh");
61+
linkQueue.enqueue("hhhh1");
62+
linkQueue.enqueue("hhhh2");
63+
linkQueue.enqueue("hhhh3");
64+
linkQueue.dequeue();
65+
}
66+
67+
}
68+
69+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.datastructure.stack;
2+
3+
/**
4+
* 用栈实现浏览器 前进后退功能
5+
*
6+
* @ClassName BrowserStack
7+
* @Author chenzhuo
8+
* @Version 1.0
9+
* @Date 2019/12/9 12:56 下午
10+
**/
11+
public class BrowserStack {
12+
13+
public static void main(String[] args) {
14+
/*
15+
StackCapacityArray<String> old = new StackCapacityArray<String>();
16+
17+
StackCapacityArray<String> newStack = new StackCapacityArray<String>();*/
18+
}
19+
20+
21+
/**
22+
* 上一步
23+
* 根据index判断是否由上一步
24+
* 如果有上一步就返回上一步的index
25+
* 如果没有就返回当前index
26+
*
27+
* @param index 索引标记
28+
*/
29+
public String nextValue(int index, StackCapacityArray<String> old, StackCapacityArray<String> newStack) {
30+
if (index < 0) {
31+
throw new RuntimeException("index must greater than 0");
32+
}
33+
String nextValue = old.get(index - 1);
34+
newStack.addElement(nextValue);
35+
return nextValue;
36+
}
37+
38+
39+
/**
40+
* 下一步
41+
* 根据index 判断是否有下一步
42+
* 如果有下一步就返回下一步,
43+
* 如果没有就返回当前index
44+
*
45+
* @param index
46+
*/
47+
public void pre(int index, StackCapacityArray<String> old, StackCapacityArray<String> newStack) {
48+
if (index < 0) {
49+
throw new RuntimeException("index must greater than 0");
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)