Skip to content

Instantly share code, notes, and snippets.

@hkusu
Created June 28, 2017 15:16
Show Gist options
  • Save hkusu/9ac96230f5f51b9a2e4d7b7a24d10931 to your computer and use it in GitHub Desktop.
Save hkusu/9ac96230f5f51b9a2e4d7b7a24d10931 to your computer and use it in GitHub Desktop.
package io.github.hkusu.example.lib.type;
import android.support.annotation.NonNull;
import java.util.LinkedHashSet;
import java.util.Set;
public class ImmutableSet<T> {
private final Set<T> set = new LinkedHashSet<>();
private ImmutableSet(@NonNull Set<T> set) {
if (!set.isEmpty()) {
this.set.addAll(set);
}
}
public Set<T> snapshot() {
final LinkedHashSet<T> set = new LinkedHashSet<>();
if (!this.set.isEmpty()) {
set.addAll(this.set);
}
return set;
}
public static <T> ImmutableSet<T> of(@NonNull Set<T> set) {
return new ImmutableSet<>(set);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment