Skip to content

Commit 124ed37

Browse files
Copilotbrunoborges
andcommitted
Add 105 proof files across all pattern categories
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 2f4ad65 commit 124ed37

File tree

104 files changed

+1843
-0
lines changed

Some content is hidden

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

104 files changed

+1843
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.*;
2+
import java.util.stream.*;
3+
import static java.util.stream.Collectors.*;
4+
5+
/// Proof: collectors-teeing
6+
/// Source: content/collections/collectors-teeing.yaml
7+
record Item(String name, double price) {}
8+
record Stats(long count, double total) {}
9+
10+
void main() {
11+
var items = List.of(new Item("a", 10.0), new Item("b", 20.0));
12+
var result = items.stream().collect(
13+
Collectors.teeing(
14+
Collectors.counting(),
15+
Collectors.summingDouble(Item::price),
16+
Stats::new
17+
)
18+
);
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.util.*;
2+
3+
/// Proof: copying-collections-immutably
4+
/// Source: content/collections/copying-collections-immutably.yaml
5+
void main() {
6+
List<String> original = new ArrayList<>(List.of("a", "b", "c"));
7+
List<String> copy =
8+
List.copyOf(original);
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.util.*;
2+
3+
/// Proof: immutable-list-creation
4+
/// Source: content/collections/immutable-list-creation.yaml
5+
void main() {
6+
List<String> list =
7+
List.of("a", "b", "c");
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.util.*;
2+
3+
/// Proof: immutable-map-creation
4+
/// Source: content/collections/immutable-map-creation.yaml
5+
void main() {
6+
Map<String, Integer> map =
7+
Map.of("a", 1, "b", 2, "c", 3);
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.util.*;
2+
3+
/// Proof: immutable-set-creation
4+
/// Source: content/collections/immutable-set-creation.yaml
5+
void main() {
6+
Set<String> set =
7+
Set.of("a", "b", "c");
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java.util.*;
2+
3+
/// Proof: map-entry-factory
4+
/// Source: content/collections/map-entry-factory.yaml
5+
void main() {
6+
var e = Map.entry("key", 42);
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.util.*;
2+
3+
/// Proof: reverse-list-iteration
4+
/// Source: content/collections/reverse-list-iteration.yaml
5+
void main() {
6+
List<String> list = List.of("a", "b", "c");
7+
for (String element : list.reversed()) {
8+
System.out.println(element);
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.util.*;
2+
3+
/// Proof: sequenced-collections
4+
/// Source: content/collections/sequenced-collections.yaml
5+
void main() {
6+
List<String> list = new ArrayList<>(List.of("a", "b", "c"));
7+
var last = list.getLast();
8+
var first = list.getFirst();
9+
var reversed = list.reversed();
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.*;
2+
import java.util.stream.*;
3+
4+
/// Proof: stream-toarray-typed
5+
/// Source: content/collections/stream-toarray-typed.yaml
6+
List<String> getNames() {
7+
return List.of("Alice", "Bob", "Charlie", "Dave");
8+
}
9+
10+
void main() {
11+
String[] arr = getNames().stream()
12+
.filter(n -> n.length() > 3)
13+
.toArray(String[]::new);
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.util.*;
2+
import java.util.stream.*;
3+
4+
/// Proof: unmodifiable-collectors
5+
/// Source: content/collections/unmodifiable-collectors.yaml
6+
void main() {
7+
Stream<String> stream = Stream.of("a", "b", "c");
8+
List<String> list = stream.toList();
9+
}

0 commit comments

Comments
 (0)