Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 7e9eba9

Browse files
authored
Merge pull request #223 from google/sorted.set
Add support for SortedSet properties
2 parents 1122b87 + ccfa75c commit 7e9eba9

14 files changed

+1866
-310
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ nulls.
329329
List<String> descendants();
330330
```
331331

332-
A <code>[List][]</code>, <code>[Set][]</code> or <code>[Multiset][]</code>
332+
A <code>[List][]</code>, <code>[Set][]</code>, <code>[SortedSet][]</code> or <code>[Multiset][]</code>
333333
property called 'descendants' would generate:
334334

335335
| Method | Description |
@@ -340,6 +340,7 @@ property called 'descendants' would generate:
340340
| `mutateDescendants(​Consumer<‌.‌.‌.‌<String>> mutator)` | *Java 8+* Invokes the [Consumer] `mutator` with the collection of descendants. (The mutator takes a list, set or map as appropriate.) Throws a NullPointerException if `mutator` is null. As `mutator` is a void consumer, any value returned from a lambda will be ignored, so be careful not to call pure functions like [stream()] expecting the returned collection to replace the existing collection. |
341341
| `clearDescendants()` | Removes all elements from the collection of descendants, leaving it empty. |
342342
| `descendants()` | Returns an unmodifiable view of the collection of descendants. Changes to the collection held by the builder will be reflected in the view. |
343+
| `setComparatorForDescendants(​Comparator<? super String> comparator)` | *SortedSet only* A protected method that sets the [comparator] to keep the set elements ordered by. Must be called before any other accessor method for this property. Defaults to the [natural ordering] of the set's elements. |
343344

344345
```java
345346
/** Returns a map of favourite albums by year. **/
@@ -387,13 +388,16 @@ personBuilder
387388
.mutateDescendants(Collections::sort);
388389
```
389390

391+
[Comparator]: https://docs.oracle.com/javase/8/docs/api/java/util/Comparator.html
390392
[List]: http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html
391393
[Set]: http://docs.oracle.com/javase/tutorial/collections/interfaces/set.html
394+
[SortedSet]: http://docs.oracle.com/javase/8/docs/api/java/util/SortedSet.html
392395
[Spliterator]: https://docs.oracle.com/javase/8/docs/api/java/util/Spliterator.html
393396
[Stream]: https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html
394397
[Multiset]: https://github.com/google/guava/wiki/NewCollectionTypesExplained#multiset
395398
[Map]: http://docs.oracle.com/javase/tutorial/collections/interfaces/map.html
396399
[Multimap]: https://github.com/google/guava/wiki/NewCollectionTypesExplained#multimap
400+
[natural ordering]: https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html
397401
[sort]: http://docs.oracle.com/javase/8/docs/api/java/util/Collections.html#sort-java.util.List-
398402
[stream()]: https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html#stream--
399403
[subList]: http://docs.oracle.com/javase/8/docs/api/java/util/List.html#subList-int-int-

config/checkstyle/checkstyle.xml

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ https://github.com/google/auto/blob/0c06a2345f71f053714d37bb6549d3460c999f2d/che
1919
<property name="file" value="${config_loc}/suppressions.xml"/>
2020
</module>
2121

22+
<!-- Allow targetted suppression with @SuppressWarnings annotation -->
23+
<module name="SuppressWarningsFilter"/>
24+
2225
<!--module name="NewlineAtEndOfFile"/-->
2326
<module name="FileLength"/>
2427
<module name="FileTabCharacter"/>
@@ -150,5 +153,6 @@ https://github.com/google/auto/blob/0c06a2345f71f053714d37bb6549d3460c999f2d/che
150153

151154
<!-- Enable suppression -->
152155
<module name="FileContentsHolder"/>
156+
<module name="SuppressWarningsHolder"/>
153157
</module>
154158
</module>

src/main/java/org/inferred/freebuilder/processor/Analyser.java

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public static class CannotGenerateCodeException extends Exception { }
103103
new NullablePropertyFactory(), // Must be first, as no other factory supports nulls
104104
new ListPropertyFactory(),
105105
new SetPropertyFactory(),
106+
new SortedSetPropertyFactory(),
106107
new MapPropertyFactory(),
107108
new MultisetPropertyFactory(),
108109
new ListMultimapPropertyFactory(),

src/main/java/org/inferred/freebuilder/processor/BuilderMethods.java

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public static String removeAllMethod(Property property) {
6161
return "removeAll" + property.getCapitalizedName();
6262
}
6363

64+
public static String setComparatorMethod(Property property) {
65+
return "setComparatorFor" + property.getCapitalizedName();
66+
}
67+
6468
public static String setCountMethod(Property property) {
6569
return "setCountOf" + property.getCapitalizedName();
6670
}

0 commit comments

Comments
 (0)