Created
June 28, 2017 15:16
-
-
Save hkusu/9ac96230f5f51b9a2e4d7b7a24d10931 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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