Skip to content

Commit 74060a2

Browse files
committed
coding guidelines: about collections
1 parent 3dcabef commit 74060a2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

coding-guidelines.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ We have a mix of Optional and allowing null values because GraphQL Java was orig
2525

2626
We are aiming to not use Optional moving forward in order to be consistent overall.
2727

28-
29-
3028
### Unit testing and dependencies
3129
All tests are written in [Spock](http://spockframework.org).
3230

@@ -80,7 +78,7 @@ Every public data class should be:
8078

8179
- Immutable
8280
- having a Builder class
83-
- having a transform method
81+
- having a `transform` method
8482

8583

8684
Every data class should be immutable and contain a `public static class Builder {..}` with a static factory method `newFoo` (not `newBuilder`).
@@ -91,3 +89,16 @@ The class should also contain a `public Foo transform(Consumer<Builder> builderC
9189

9290
Private classes should follow the same design, but they don't have to.
9391

92+
### Default Collections idiom
93+
94+
The default pattern for using Set, Map and List is:
95+
- List<Foo> fooList = new ArrayList<>();
96+
- Set<Foo> fooSet = new LinkedHashSet<>();
97+
- Map<Foo> fooMap = new LinkedHashMap<>();
98+
99+
By using the generic interface instead of using an implementation we are making sure we
100+
don't rely on anything impl specific.
101+
The default implementations for `Set` and `Map` should be the `LinkedHashSet` and `LinkedHashMap`
102+
because it offers stable iteration order.
103+
104+

0 commit comments

Comments
 (0)