You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/10/06 11:40:15 UTC

[isis] 01/02: ISIS-2441: _Sets: adds sorted set var-arg constructor

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch 2441-auditing
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 7126bafb5e7aa80b712cfe4e6bad4b156b511469
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Oct 6 11:44:44 2020 +0200

    ISIS-2441: _Sets: adds sorted set var-arg constructor
---
 .../apache/isis/commons/internal/collections/_Sets.java | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java b/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java
index b1bab18..5a12b56 100644
--- a/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java
+++ b/commons/src/main/java/org/apache/isis/commons/internal/collections/_Sets.java
@@ -98,6 +98,23 @@ public final class _Sets {
         return Stream.of(elements)
                 .collect(toUnmodifiable(LinkedHashSet::new)); // preserve order
     }
+    
+    /**
+     * Copies all elements into a new unmodifiable SortedSet (of natural order).
+     * @param elements
+     * @return non null
+     */
+    @SafeVarargs
+    public static <T> SortedSet<T> ofSorted(T ... elements) {
+        _With.requires(elements, "elements");// don't accept null as argument
+        if(elements.length==0) {
+            return Collections.emptySortedSet();
+        }
+        return Collections.unmodifiableSortedSet(
+                Stream.of(elements)
+                .collect(Collectors.toCollection(TreeSet::new))); // natural order
+    }
+    
 
     /**
      * Copies all elements from iterable into a new unmodifiable Set preserving iteration order.