Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66788b3

Browse files
王俊杰王俊杰
王俊杰
authored and
王俊杰
committed
update code
1 parent 290d91d commit 66788b3

File tree

252 files changed

+265
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+265
-150
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@
77
*.iml
88
out
99
gen
10+
target/
11+
logs/
12+
*.class
13+
*.bak
14+
*.log*
-541 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dubboConsumer/target/classes/META-INF/dubbo/com.alibaba.dubbo.rpc.Filter

Lines changed: 0 additions & 1 deletion
This file was deleted.

dubboConsumer/target/classes/META-INF/services/com.wang.spiTest.Robot

Lines changed: 0 additions & 2 deletions
This file was deleted.

dubboConsumer/target/classes/application.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.
-885 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-665 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

dubboConsumer/target/classes/dubbo-consumer.properties

Lines changed: 0 additions & 3 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
-962 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

dubboProvider/target/classes/dubbo-provider.properties

Lines changed: 0 additions & 4 deletions
This file was deleted.
Binary file not shown.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package com.wang.code;
2+
3+
import java.util.ArrayList;
4+
import java.util.Iterator;
5+
import java.util.ListIterator;
6+
7+
public class IteratorDemo {
8+
9+
public static void main(String[] args) {
10+
/*
11+
* 一、前言
12+
* 迭代器是一个对象,它可以让你遍历一个容器并且有选择性的删除 容器 中的元素,而我们不需要知道 容器 的内部结构.
13+
* Java有两种原生的迭代器:Iterator和ListIterator, 其中 ListIterator继承自 Iterator.
14+
*
15+
* 二、Iterator接口
16+
17+
* Iterator 通常被称为轻量级对象,因为创建它的开销比较小.可以通过调用容器的 iterator()方法来获取它的Iterator.
18+
*
19+
* 下面是Iterator接口定义:
20+
*
21+
* public interface Iterator<E> {
22+
* boolean hasNext();
23+
*
24+
* E next();
25+
*
26+
* default void remove() {
27+
* throw new UnsupportedOperationException("remove");
28+
* }
29+
*
30+
* default void forEachRemaining(Consumer<? super E> action) {
31+
* Objects.requireNonNull(action);
32+
* while (hasNext())
33+
* action.accept(next());
34+
* }
35+
* }
36+
*
37+
* Java的 Iterator只能单向移动,它只能用来:
38+
* (1)使用容器的 iterator ()方法返回它的Iterator.Iterator将返回容器的第一个元素.
39+
* (2)使用next()方法返回容器的下一个元素.
40+
* (3)使用hasNext()方法检查容器中是否还有元素. 如果有,hasNext()方法返回 true.
41+
* (4)使用 remove()方法删除由 next()方法新近返回的元素.
42+
* 下面来看一个使用示例:
43+
*
44+
* 代码清单-2
45+
*
46+
*
47+
*/
48+
ArrayList<String> a = new ArrayList<>();
49+
a.add("aaa");
50+
a.add("bbb");
51+
a.add("ccc");
52+
System.out.println("Before iterate : " + a);
53+
Iterator<String> it = a.iterator();
54+
while (it.hasNext()) {
55+
String t = it.next();
56+
if ("bbb".equals(t)) {
57+
it.remove();
58+
}
59+
}
60+
System.out.println("After iterate : " + a);
61+
62+
/*
63+
* 三、ListIterator接口
64+
* ListIterator是一个功能更加强大的迭代器, 它只能用于各种List类型的访问。可以通过调用listIterator()方法产生一个指向List开始处的ListIterator, 还可以调用listIterator(n)方法创建一个一开始就指向列表索引为n的元素处的ListIterator.
65+
*
66+
* ListIterator接口定义如下:
67+
*
68+
* public interface ListIterator<E> extends Iterator<E> {
69+
* boolean hasNext();
70+
* E next();
71+
* boolean hasPrevious();
72+
* E previous();
73+
* int nextIndex();
74+
* int previousIndex();
75+
* void remove();
76+
* void set(E e);
77+
* void add(E e);
78+
* }
79+
* 由以上定义我们可以推出ListIterator可以:
80+
*
81+
* (1)双向移动.
82+
*
83+
* (2)产生相对于迭代器在列表中指向的当前位置的前一个和后一个元素的索引.
84+
*
85+
* (3)可以使用set()方法替换它访问过的最后一个元素.
86+
*
87+
* (4)可以使用add()方法在next()方法返回的元素之前或previous()方法返回的元素之后插入一个元素.
88+
*
89+
* 下面就简单演示所有这些功能:
90+
*
91+
* 代码清单-4
92+
*
93+
*/
94+
95+
ArrayList<String> a1 = new ArrayList<String>();
96+
a.add("aaa");
97+
a.add("bbb");
98+
a.add("ccc");
99+
System.out.println("Before iterate : " + a1);
100+
ListIterator<String> it1 = a1.listIterator();
101+
while (it.hasNext()) {
102+
System.out.println(it1.next() + ", " + it1.previousIndex() + ", " + it1.nextIndex());
103+
}
104+
while (it1.hasPrevious()) {
105+
System.out.print(it1.previous() + " ");
106+
}
107+
System.out.println();
108+
it1 = a1.listIterator(1);
109+
while (it1.hasNext()) {
110+
String t1 = it.next();
111+
if ("ccc".equals(t1)) {
112+
it1.set("nnn");
113+
} else {
114+
it1.add("kkk");
115+
}
116+
}
117+
System.out.println("After iterate : " + a);
118+
119+
120+
/* 输出结果如下:
121+
*
122+
*
123+
* Before iterate : [aaa, bbb, ccc]
124+
* aaa, 0, 1
125+
* bbb, 1, 2
126+
* ccc, 2, 3
127+
* ccc bbb aaa
128+
* After iterate : [aaa, bbb, kkk, nnn]
129+
*
130+
*
131+
* 四、Iterator使用场景
132+
* 在以下情况下可以使用Iterator接口代替for-each结构:
133+
*
134+
* (1)删除当前的元素.for-each结构隐藏了迭代器, 所以你不能调用remove()方法. 因此for-each结构无法用于过滤.
135+
* (2)并行地迭代多个集合.
136+
*
137+
* 下面的代码片段展示了如何使用一个迭代器来过滤任意一个集合——即遍历这个集合并删除指定元素.
138+
*
139+
* 代码清单-5
140+
*
141+
*
142+
* static void filter(Collection<?> c) {
143+
* for (Iterator<?> it = c.iterator(); it.hasNext(); )
144+
* if (!cond(it.next()))
145+
* it.remove();
146+
* }
147+
* 以上代码是多态的, 意味着它对任何集合都起作用, 而不用去考虑具体的实现.可见使用Java集合框架来编写多态的算法是多么的简单.
148+
*/
149+
150+
}
151+
}
152+
153+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.wang.code;
2+
3+
import java.io.*;
4+
5+
public class SerializableDemo {
6+
7+
public static class Person implements Serializable {
8+
9+
private static final long serialVersionUID = 1L;
10+
11+
public Person(Integer age, String name){
12+
this.age = age;
13+
this.name = name;
14+
}
15+
16+
private transient Integer age;
17+
private String name;
18+
19+
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
20+
inputStream.defaultReadObject();
21+
this.age = (Integer) inputStream.readObject();
22+
}
23+
24+
private void writeObject(ObjectOutputStream outputStream) throws IOException, ClassNotFoundException {
25+
outputStream.defaultWriteObject();
26+
this.age = 1000;
27+
outputStream.writeObject(this.age);
28+
}
29+
30+
public Integer getAge() {
31+
return age;
32+
}
33+
34+
public void setAge(Integer age) {
35+
this.age = age;
36+
}
37+
38+
public String getName() {
39+
return name;
40+
}
41+
42+
public void setName(String name) {
43+
this.name = name;
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return "age: " + age + " name: " + name;
49+
}
50+
}
51+
52+
public static void main(String[] args) throws IOException, ClassNotFoundException {
53+
// 写文件
54+
FileOutputStream fileOutputStream = new FileOutputStream("/Users/wangjunjie/Desktop/person.txt");
55+
ObjectOutputStream outputStream = new ObjectOutputStream(fileOutputStream);
56+
Person person = new Person(27, "wang");
57+
outputStream.writeObject(person);
58+
fileOutputStream.close();
59+
outputStream.close();
60+
61+
// 从文件中读取对象数据
62+
FileInputStream fileInputStream = new FileInputStream("/Users/wangjunjie/Desktop/person.txt");
63+
ObjectInputStream inputStream = new ObjectInputStream(fileInputStream);
64+
Person object = (Person) inputStream.readObject();
65+
fileInputStream.close();
66+
inputStream.close();
67+
68+
69+
System.out.println(object.toString());
70+
System.out.println(object == person);
71+
}
72+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.wang.code;
2+
3+
import java.io.ObjectInputStream;
4+
import java.lang.reflect.InvocationTargetException;
5+
import java.lang.reflect.Method;
6+
import java.util.*;
7+
import java.util.concurrent.ThreadLocalRandom;
8+
9+
10+
public class Test {
11+
12+
public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
13+
Class clz = ThreadLocalRandom.class;
14+
Method nextSecondarySeed = clz.getDeclaredMethod("nextSecondarySeed");
15+
nextSecondarySeed.setAccessible(true);
16+
17+
int i = 1;
18+
int j = 1;
19+
20+
for (int k=0; k<1000; k++){
21+
if (((int)nextSecondarySeed.invoke(clz) & 0x80000001) == 0){
22+
i++;
23+
} else {
24+
j++;
25+
}
26+
// System.out.println((int)nextSecondarySeed.invoke(clz) & 0x80000001);
27+
}
28+
29+
System.out.println(i);
30+
System.out.println(j);
31+
32+
33+
}
34+
35+
}
Binary file not shown.
-541 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-1.34 KB
Binary file not shown.
Binary file not shown.

kafkaConsumer/target/classes/application.properties

Lines changed: 0 additions & 4 deletions
This file was deleted.
-661 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-541 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

kafkaProvider/target/classes/application.properties

Lines changed: 0 additions & 6 deletions
This file was deleted.
-661 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

liaoxuefeng/target/classes/Club.class

-388 Bytes
Binary file not shown.
-409 Bytes
Binary file not shown.
-344 Bytes
Binary file not shown.
-1.31 KB
Binary file not shown.

liaoxuefeng/target/classes/set.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

liaoxuefeng/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

Whitespace-only changes.

liaoxuefeng/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

Lines changed: 0 additions & 1 deletion
This file was deleted.
-541 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-950 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

netty/target/classes/template/ws.html

Lines changed: 0 additions & 61 deletions
This file was deleted.
Binary file not shown.
-16 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
-7.03 KB
Binary file not shown.
-431 Bytes
Binary file not shown.
Binary file not shown.
-541 Bytes
Binary file not shown.
-999 Bytes
Binary file not shown.
-242 Bytes
Binary file not shown.
-728 Bytes
Binary file not shown.
Binary file not shown.
-473 Bytes
Binary file not shown.

springBoot/target/classes/META-INF/spring.factories

Lines changed: 0 additions & 2 deletions
This file was deleted.

springBoot/target/classes/application-test.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

springBoot/target/classes/application.properties

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)