Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package io.github.hkusu.example.lib.type;
  2.  
  3. import android.support.annotation.NonNull;
  4.  
  5. import java.util.LinkedHashSet;
  6. import java.util.Set;
  7.  
  8. public class ImmutableSet<T> {
  9. private final Set<T> set = new LinkedHashSet<>();
  10.  
  11. private ImmutableSet(@NonNull Set<T> set) {
  12. if (!set.isEmpty()) {
  13. this.set.addAll(set);
  14. }
  15. }
  16.  
  17. public Set<T> snapshot() {
  18. final LinkedHashSet<T> set = new LinkedHashSet<>();
  19. if (!this.set.isEmpty()) {
  20. set.addAll(this.set);
  21. }
  22. return set;
  23. }
  24.  
  25. public static <T> ImmutableSet<T> of(@NonNull Set<T> set) {
  26. return new ImmutableSet<>(set);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement