Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return immutable Set for a Collection #974

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 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,16 @@ 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