org.thirdteeth.immutables.pcollections.encodings.PCollectionsPBagEncoding Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pcollections-encodings Show documentation
Show all versions of pcollections-encodings Show documentation
Immutables.org encodings for pcollections (Encodings)
package org.thirdteeth.immutables.pcollections.encodings;
import org.immutables.encode.Encoding;
import org.pcollections.HashTreePBag;
import org.pcollections.PBag;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
@Encoding
class PCollectionsPBagEncoding {
// Using a linked variant provides more predictable semantics for serialization
@Encoding.Impl
private PBag field = HashTreePBag.empty();
PCollectionsPBagEncoding() {
}
@Encoding.Builder
static final class Builder {
private PBag bag = HashTreePBag.empty();
Builder() {
}
@Encoding.Naming(standard = Encoding.StandardNaming.ADD)
@Encoding.Init
void add(final T element) {
this.bag = this.bag.plus(element);
}
@SafeVarargs
@Encoding.Naming(standard = Encoding.StandardNaming.ADD)
@Encoding.Init
final void addVarArgs(final T... elements) {
this.bag = this.bag.plusAll(Arrays.asList(elements));
}
@Encoding.Naming(standard = Encoding.StandardNaming.ADD_ALL)
@Encoding.Init
void addAll(final Collection element) {
this.bag = this.bag.plusAll(element);
}
@Encoding.Naming(value = "setJavaSet*")
@Encoding.Init
void setJavaSet(final Set in_set) {
this.bag = HashTreePBag.from(in_set);
}
@Encoding.Init
@Encoding.Copy
void set(final PBag elements) {
this.bag = elements;
}
@Encoding.Build
PBag build() {
return this.bag;
}
}
}