Skip to content

Commit

Permalink
add set builder utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Podgursky committed Oct 14, 2018
1 parent 4bbcc65 commit 9d31ede
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/main/java/com/liveramp/commons/collections/set/SetBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.liveramp.commons.collections.set;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

import com.google.common.collect.Sets;

public class SetBuilder<V> {

private Set<V> set;

public SetBuilder() {
this(Sets.<V>newHashSet());
}

public SetBuilder(Set<V> set) {
this.set = Sets.newHashSet(set);
}

public SetBuilder<V> add(V value) {
set.add(value);
return this;
}

public SetBuilder<V> add(V... values) {
Collections.addAll(set, values);
return this;
}

public SetBuilder<V> addAll(Collection<? extends V> other) {
set.addAll(other);
return this;
}

public Set<V> get() {
return set;
}

public Set<V> asUnmodifiableSet() {
return Collections.unmodifiableSet(set);
}
}

0 comments on commit 9d31ede

Please sign in to comment.