Skip to content

Commit

Permalink
Return immutable Set for a Collection
Browse files Browse the repository at this point in the history
Fixes jwtk#965
  • Loading branch information
atanasg authored Oct 31, 2024
1 parent 2ad964a commit 9b80d15
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions api/src/main/java/io/jsonwebtoken/lang/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,13 @@ public static <T> List<T> of(T... elements) {
/**
* Returns the specified collection as a {@link Set} instance.
*
* @param c the collection to represent as a set
* @param c the collection to be converted
* @param <T> collection element type
* @return a type-safe immutable {@code Set} containing the specified collection elements.
* @return a type-safe immutable {@code Set} containing the specified collection elements.
* @since 0.12.0
*/
public static <T> Set<T> asSet(Collection<T> c) {
if (c instanceof Set) {
return (Set<T>) c;
}
if (isEmpty(c)) {
return java.util.Collections.emptySet();
}
return java.util.Collections.unmodifiableSet(new LinkedHashSet<>(c));
return java.util.Collections.unmodifiableSet(new LinkedHashSet<T>(c));
}

/**
Expand Down

0 comments on commit 9b80d15

Please sign in to comment.