Skip to content

Commit 571a95b

Browse files
authored
Merge pull request onlyliuxin#578 from miniyk2012/master
java闭包+薪水支付案例+junit-v2
2 parents d18de2b + 611ccb3 commit 571a95b

File tree

100 files changed

+4043
-127
lines changed

Some content is hidden

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

100 files changed

+4043
-127
lines changed

students/812350401/src/main/java/com/coderising/mydp/composite/Rectangle.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ public class Rectangle implements Shape {
44

55
@Override
66
public void draw() {
7-
// TODO Auto-generated method stub
87
System.out.println("Rectangle");
98
}
109

students/812350401/src/main/java/com/coderising/mydp/composite/Square.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ public class Square implements Shape {
44

55
@Override
66
public void draw() {
7-
// TODO Auto-generated method stub
87
System.out.println("Square");
98
}
109

students/812350401/src/main/java/com/coderising/mydp/composite/Text.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ public class Text implements Shape {
44

55
@Override
66
public void draw() {
7-
// TODO Auto-generated method stub
87
System.out.println("Text");
98
}
109

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.coderising.myknowledgepoint.closure;
2+
3+
/**
4+
* Created by thomas_young on 27/8/2017.
5+
*/
6+
public class Milk {
7+
8+
public final static String name = "纯牛奶";//名称
9+
10+
private static int num = 16;//数量
11+
12+
public Milk()
13+
{
14+
System.out.println(name+":16/每箱");
15+
}
16+
17+
/**
18+
* 闭包
19+
* @return 返回一个喝牛奶的动作
20+
*/
21+
public Active HaveMeals()
22+
{
23+
return () -> {
24+
if(num == 0)
25+
{
26+
System.out.println("木有了,都被你丫喝完了.");
27+
return;
28+
}
29+
num--;
30+
System.out.println("喝掉一瓶牛奶");
31+
};
32+
}
33+
34+
/**
35+
* 获取剩余数量
36+
*/
37+
public void currentNum()
38+
{
39+
System.out.println(name+"剩余:"+num);
40+
}
41+
}
42+
43+
/**
44+
* 通用接口
45+
*/
46+
interface Active
47+
{
48+
void drink();
49+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.coderising.myknowledgepoint.closure;
2+
3+
/**
4+
* Created by thomas_young on 27/8/2017.
5+
*/
6+
public class Person {
7+
8+
public static void main(String[] args) {
9+
//买一箱牛奶
10+
Milk m = new Milk();
11+
12+
Active haveMeals = m.HaveMeals();
13+
14+
//没事喝一瓶
15+
haveMeals.drink();
16+
//有事喝一瓶
17+
haveMeals.drink();
18+
19+
//看看还剩多少?
20+
m.currentNum();
21+
m = null;
22+
haveMeals.drink(); // 闭包会导致资源不被回收
23+
haveMeals.drink();
24+
haveMeals.drink();
25+
haveMeals.drink();
26+
haveMeals.drink();
27+
haveMeals.drink();
28+
haveMeals.drink();
29+
haveMeals.drink();
30+
haveMeals.drink();
31+
haveMeals.drink();
32+
haveMeals.drink();
33+
haveMeals.drink();
34+
haveMeals.drink();
35+
haveMeals.drink();
36+
haveMeals.drink();
37+
haveMeals.drink();
38+
haveMeals.drink();
39+
}
40+
41+
}

students/812350401/src/main/java/com/coderising/myknowledgepoint/regex/Utils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public static String readAllFromResouce(String resourceName) {
1818

1919
return fileContentStr;
2020
} catch (IOException | URISyntaxException e) {
21-
// TODO Auto-generated catch block
2221
e.printStackTrace();
2322
}
2423

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
package com.coderising.myood.litejunit.liuxinv2;
2+
3+
/**
4+
* A set of assert methods.
5+
*/
6+
7+
public class Assert {
8+
/**
9+
* Protect constructor since it is a static only class
10+
*/
11+
protected Assert() {
12+
}
13+
/**
14+
* Asserts that a condition is true. If it isn't it throws
15+
* an AssertionFailedError with the given message.
16+
* @deprecated use assertTrue
17+
*/
18+
/*static public void assert(String message, boolean condition) {
19+
if (!condition)
20+
fail(message);
21+
}*/
22+
/**
23+
* Asserts that a condition is true. If it isn't it throws
24+
* an AssertionFailedError.
25+
* @deprecated use assertTrue
26+
*
27+
*/
28+
/*static public void assert(boolean condition) {
29+
assert(null, condition);
30+
}
31+
*/
32+
/**
33+
* Asserts that a condition is true. If it isn't it throws
34+
* an AssertionFailedError with the given message.
35+
*/
36+
static public void assertTrue(String message, boolean condition) {
37+
if (!condition)
38+
fail(message);
39+
}
40+
/**
41+
* Asserts that a condition is true. If it isn't it throws
42+
* an AssertionFailedError.
43+
*/
44+
static public void assertTrue(boolean condition) {
45+
assertTrue(null, condition);
46+
}
47+
/**
48+
* Fails a test with the given message.
49+
*/
50+
static public void fail(String message) {
51+
throw new AssertionFailedError(message);
52+
}
53+
/**
54+
* Fails a test with no message.
55+
*/
56+
static public void fail() {
57+
fail(null);
58+
}
59+
/**
60+
* Asserts that two objects are equal. If they are not
61+
* an AssertionFailedError is thrown.
62+
*/
63+
static public void assertEquals(String message, Object expected, Object actual) {
64+
if (expected == null && actual == null)
65+
return;
66+
if (expected != null && expected.equals(actual))
67+
return;
68+
failNotEquals(message, expected, actual);
69+
}
70+
/**
71+
* Asserts that two objects are equal. If they are not
72+
* an AssertionFailedError is thrown.
73+
*/
74+
static public void assertEquals(Object expected, Object actual) {
75+
assertEquals(null, expected, actual);
76+
}
77+
/**
78+
* Asserts that two doubles are equal concerning a delta. If the expected
79+
* value is infinity then the delta value is ignored.
80+
*/
81+
static public void assertEquals(String message, double expected, double actual, double delta) {
82+
// handle infinity specially since subtracting to infinite values gives NaN and the
83+
// the following test fails
84+
if (Double.isInfinite(expected)) {
85+
if (!(expected == actual))
86+
failNotEquals(message, new Double(expected), new Double(actual));
87+
} else if (!(Math.abs(expected-actual) <= delta)) // Because comparison with NaN always returns false
88+
failNotEquals(message, new Double(expected), new Double(actual));
89+
}
90+
/**
91+
* Asserts that two doubles are equal concerning a delta. If the expected
92+
* value is infinity then the delta value is ignored.
93+
*/
94+
static public void assertEquals(double expected, double actual, double delta) {
95+
assertEquals(null, expected, actual, delta);
96+
}
97+
/**
98+
* Asserts that two floats are equal concerning a delta. If the expected
99+
* value is infinity then the delta value is ignored.
100+
*/
101+
static public void assertEquals(String message, float expected, float actual, float delta) {
102+
// handle infinity specially since subtracting to infinite values gives NaN and the
103+
// the following test fails
104+
if (Float.isInfinite(expected)) {
105+
if (!(expected == actual))
106+
failNotEquals(message, new Float(expected), new Float(actual));
107+
} else if (!(Math.abs(expected-actual) <= delta))
108+
failNotEquals(message, new Float(expected), new Float(actual));
109+
}
110+
/**
111+
* Asserts that two floats are equal concerning a delta. If the expected
112+
* value is infinity then the delta value is ignored.
113+
*/
114+
static public void assertEquals(float expected, float actual, float delta) {
115+
assertEquals(null, expected, actual, delta);
116+
}
117+
/**
118+
* Asserts that two longs are equal.
119+
*/
120+
static public void assertEquals(String message, long expected, long actual) {
121+
assertEquals(message, new Long(expected), new Long(actual));
122+
}
123+
/**
124+
* Asserts that two longs are equal.
125+
*/
126+
static public void assertEquals(long expected, long actual) {
127+
assertEquals(null, expected, actual);
128+
}
129+
/**
130+
* Asserts that two booleans are equal.
131+
*/
132+
static public void assertEquals(String message, boolean expected, boolean actual) {
133+
assertEquals(message, new Boolean(expected), new Boolean(actual));
134+
}
135+
/**
136+
* Asserts that two booleans are equal.
137+
*/
138+
static public void assertEquals(boolean expected, boolean actual) {
139+
assertEquals(null, expected, actual);
140+
}
141+
/**
142+
* Asserts that two bytes are equal.
143+
*/
144+
static public void assertEquals(String message, byte expected, byte actual) {
145+
assertEquals(message, new Byte(expected), new Byte(actual));
146+
}
147+
/**
148+
* Asserts that two bytes are equal.
149+
*/
150+
static public void assertEquals(byte expected, byte actual) {
151+
assertEquals(null, expected, actual);
152+
}
153+
/**
154+
* Asserts that two chars are equal.
155+
*/
156+
static public void assertEquals(String message, char expected, char actual) {
157+
assertEquals(message, new Character(expected), new Character(actual));
158+
}
159+
/**
160+
* Asserts that two chars are equal.
161+
*/
162+
static public void assertEquals(char expected, char actual) {
163+
assertEquals(null, expected, actual);
164+
}
165+
/**
166+
* Asserts that two shorts are equal.
167+
*/
168+
static public void assertEquals(String message, short expected, short actual) {
169+
assertEquals(message, new Short(expected), new Short(actual));
170+
}
171+
/**
172+
* Asserts that two shorts are equal.
173+
*/
174+
static public void assertEquals(short expected, short actual) {
175+
assertEquals(null, expected, actual);
176+
}
177+
/**
178+
* Asserts that two ints are equal.
179+
*/
180+
static public void assertEquals(String message, int expected, int actual) {
181+
assertEquals(message, new Integer(expected), new Integer(actual));
182+
}
183+
/**
184+
* Asserts that two ints are equal.
185+
*/
186+
static public void assertEquals(int expected, int actual) {
187+
assertEquals(null, expected, actual);
188+
}
189+
/**
190+
* Asserts that an object isn't null.
191+
*/
192+
static public void assertNotNull(Object object) {
193+
assertNotNull(null, object);
194+
}
195+
/**
196+
* Asserts that an object isn't null.
197+
*/
198+
static public void assertNotNull(String message, Object object) {
199+
assertTrue(message, object != null);
200+
}
201+
/**
202+
* Asserts that an object is null.
203+
*/
204+
static public void assertNull(Object object) {
205+
assertNull(null, object);
206+
}
207+
/**
208+
* Asserts that an object is null.
209+
*/
210+
static public void assertNull(String message, Object object) {
211+
assertTrue(message, object == null);
212+
}
213+
/**
214+
* Asserts that two objects refer to the same object. If they are not
215+
* an AssertionFailedError is thrown.
216+
*/
217+
static public void assertSame(String message, Object expected, Object actual) {
218+
if (expected == actual)
219+
return;
220+
failNotSame(message, expected, actual);
221+
}
222+
/**
223+
* Asserts that two objects refer to the same object. If they are not
224+
* the same an AssertionFailedError is thrown.
225+
*/
226+
static public void assertSame(Object expected, Object actual) {
227+
assertSame(null, expected, actual);
228+
}
229+
230+
static private void failNotEquals(String message, Object expected, Object actual) {
231+
String formatted= "";
232+
if (message != null)
233+
formatted= message+" ";
234+
fail(formatted+"expected:<"+expected+"> but was:<"+actual+">");
235+
}
236+
237+
static private void failNotSame(String message, Object expected, Object actual) {
238+
String formatted= "";
239+
if (message != null)
240+
formatted= message+" ";
241+
fail(formatted+"expected same");
242+
}
243+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.coderising.myood.litejunit.liuxinv2;
2+
3+
/**
4+
* Thrown when an assertion failed.
5+
*/
6+
public class AssertionFailedError extends Error {
7+
8+
public AssertionFailedError () {
9+
}
10+
public AssertionFailedError (String message) {
11+
super (message);
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.coderising.myood.litejunit.liuxinv2;
2+
3+
/**
4+
* A <em>Protectable</em> can be run and can throw a Throwable.
5+
*
6+
* @see TestResult
7+
*/
8+
public interface Protectable {
9+
10+
/**
11+
* Run the the following method protected.
12+
*/
13+
public abstract void protect() throws Throwable;
14+
}

0 commit comments

Comments
 (0)