-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev-2.x' into renovate/jackson…
….version
- Loading branch information
Showing
39 changed files
with
523 additions
and
2,638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/org/opentripplanner/framework/collection/CollectionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.opentripplanner.framework.collection; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.SortedSet; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
|
||
public class CollectionUtils { | ||
|
||
/** | ||
* A null-safe version of toString() for a collections. | ||
* <p> | ||
* If the collection is {@code null} the given {@code nullText} is returned. | ||
* <p> | ||
* All elements are also converted to a sting using the {@code toString()} method or if | ||
* {@code null} to the given {@code nullText}. | ||
* <p> | ||
* If the collection is a set, but not a SortedSet then the elements are sorted. This is done | ||
* to return the elements in a deterministic manner, which is important if this is used in | ||
* for example a unit-test. | ||
* <p> | ||
* The final result string examples: {@code "[]", "[a]", "[a, b, c]"} | ||
*/ | ||
public static <T> String toString(@Nullable Collection<T> c, String nullText) { | ||
if (c == null) { | ||
return nullText; | ||
} | ||
var stream = c.stream().map(it -> it == null ? nullText : it.toString()); | ||
if (c instanceof Set && !(c instanceof SortedSet<T>)) { | ||
stream = stream.sorted(); | ||
} | ||
return stream.collect(Collectors.joining(", ", "[", "]")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.