Skip to content

Commit cdeacea

Browse files
committed
rename most of the chapters (again)
1 parent 507a49a commit cdeacea

21 files changed

+123
-11
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,33 @@ A guide to modern Java (Java 17)
44
## Content
55

66
0. [genesis.md](guide/chapter00-genesis.md)
7-
1. [basictypes.md](guide/chapter01-basictypes.md)
7+
1. [basic_types.md](guide/chapter01-basic_types.md)
88
2. [methods.md](guide/chapter02-methods.md)
9-
3. [jshellvsjava.md](guide/chapter03-jshellvsjava.md)
9+
3. [jshell_vs_java.md](guide/chapter03-jshell_vs_java.md)
1010
4. [numbers.md](guide/chapter04-numbers.md)
11-
5. [controlflow.md](guide/chapter05-controlflow.md)
11+
5. [control_flow.md](guide/chapter05-control_flow.md)
1212
6. [interface.md](guide/chapter07-interface.md)
1313
7. [lambda.md](guide/chapter08-lambda.md)
14-
8. [listandmap.md](guide/chapter09-listandmap.md)
15-
9. [stringformatting.md](guide/chapter10-stringformatting.md)
14+
8. [list_and_map.md](guide/chapter09-list_and_map.md)
15+
9. [string_formatting.md](guide/chapter10-string_formatting.md)
1616
10. [encapsulation.md](guide/chapter11-encapsulation.md)
1717
11. [equals_hashCode_toString.md](guide/chapter12-equals_hashCode_toString.md)
1818
12. [contract.md](guide/chapter13-contract.md)
1919
13. [modifable_vs_mutalble.md](guide/chapter13-modifable_vs_mutalble.md)
20-
14. [nullandoptional.md](guide/chapter14-nullandoptional.md)
20+
14. [null_and_optional.md](guide/chapter14-null_and_optional.md)
2121
15. [inheritance.md](guide/chapter15-inheritance.md)
2222
16. [exception.md](guide/chapter16-exception.md)
2323
17. [enum.md](guide/chapter17-enum.md)
24-
18. [internalclass.md](guide/chapter18-internalclass.md)
24+
18. [internal_classes.md](guide/chapter18-internal_classes.md)
2525
19. [implementing_interface.md](guide/chapter19-implementing_interface.md)
2626
20. [generics.md](guide/chapter20-generics.md)
2727
21. [wrapper.md](guide/chapter21-wrapper.md)
2828
22. [variance.md](guide/chapter22-variance.md)
29-
23. [stream.md](guide/chapter25-stream.md)
30-
24. [collector.md](guide/chapter26-collector.md)
31-
25. [datastructure.md](guide/chapter30-datastructure.md)
32-
26. [sort.md](guide/chapter31-sort.md)
29+
23. [limitation_of_generics.md](guide/chapter23-limitation_of_generics.md)
30+
24. [stream.md](guide/chapter25-stream.md)
31+
25. [collector.md](guide/chapter26-collector.md)
32+
26. [data_structure.md](guide/chapter30-data_structure.md)
33+
27. [sort.md](guide/chapter31-sort.md)
3334

3435

3536
## Using Java Shell (jshell)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

chapter13-contract.jsh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,37 @@
22
// then cut and paste the following lines to see how it works
33
// To exit jshell type /exit
44

5+
// # Contract
6+
7+
public enum UnitKind {
8+
MARINE(10), FLAME_THROWER(8)
9+
;
10+
private final int maxPower;
11+
12+
private UnitKind(int maxPower) {
13+
this.maxPower = maxPower;
14+
}
15+
}
16+
17+
public class MilitaryUnit {
18+
private final UnitKind kind;
19+
private final int power;
20+
private IntUnaryOperator bonus;
21+
22+
public MilitaryUnit(UnitKind kind, int power) {
23+
this.kind = Objects.requireNonNull(kind);
24+
if (power < 0 || power >= kind.maxPower) {
25+
throw new IllegalArgumentException("invalid power " + power);
26+
}
27+
this.power = power;
28+
this.bonus = x -> x;
29+
}
30+
31+
public void bonus(IntUnaryOperator bonus) {
32+
this.bonus = Objects.requireNonNull(bonus);
33+
}
34+
35+
public int fightingPower() {
36+
return Math.max(0, Math.min(unit.maxPower, bonus.applyAsInt(power)));
37+
}
38+
}
File renamed without changes.
File renamed without changes.

chapter23-limitation_of_generics.jsh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// To starts, run jshell --enable-preview which is a program able to interpret Java syntax
2+
// then cut and paste the following lines to see how it works
3+
// To exit jshell type /exit
4+
5+
6+
// # Limitations of generics
7+
8+
9+
// ## No reification
10+
11+
12+
13+
// ## Array of parameterized type
14+
15+
16+
// ### varargs
17+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

guide/chapter13-contract.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
11

2+
# Contract
3+
4+
```java
5+
public enum UnitKind {
6+
MARINE(10), FLAME_THROWER(8)
7+
;
8+
private final int maxPower;
9+
```
10+
11+
```java
12+
private UnitKind(int maxPower) {
13+
this.maxPower = maxPower;
14+
}
15+
}
16+
```
17+
18+
```java
19+
public class MilitaryUnit {
20+
private final UnitKind kind;
21+
private final int power;
22+
private IntUnaryOperator bonus;
23+
```
24+
25+
```java
26+
public MilitaryUnit(UnitKind kind, int power) {
27+
this.kind = Objects.requireNonNull(kind);
28+
if (power < 0 || power >= kind.maxPower) {
29+
throw new IllegalArgumentException("invalid power " + power);
30+
}
31+
this.power = power;
32+
this.bonus = x -> x;
33+
}
34+
```
35+
36+
```java
37+
public void bonus(IntUnaryOperator bonus) {
38+
this.bonus = Objects.requireNonNull(bonus);
39+
}
40+
```
41+
42+
```java
43+
public int fightingPower() {
44+
return Math.max(0, Math.min(unit.maxPower, bonus.applyAsInt(power)));
45+
}
46+
}
47+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
# Limitations of generics
4+
5+
6+
## No reification
7+
8+
9+
10+
## Array of parameterized type
11+
12+
13+
### varargs
14+
File renamed without changes.

0 commit comments

Comments
 (0)