All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.thirdteeth.immutables.pcollections.encodings.PCollectionsPBagEncoding Maven / Gradle / Ivy

There is a newer version: 0.1.4
Show newest version
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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy