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

org.onlab.util.GuavaCollectors Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
/*
 * Copyright 2015-present Open Networking Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.onlab.util;

import java.util.stream.Collector;
import java.util.stream.Collector.Characteristics;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

/**
 * Implementations of {@link Collector} that implement various useful reduction
 * operations, such as accumulating elements into Guava collections.
 */
public final class GuavaCollectors {

    /**
     * Returns a {@code Collector} that accumulates the input elements into a
     * new ImmutableSet.
     *
     * @param  type
     * @return a {@code Collector} which collects all the input elements into a
     * {@code ImmutableSet}
     *
     * @deprecated in 1.11.0 consider using {@link ImmutableSet#toImmutableSet()} instead.
     */
    @Deprecated
    public static  Collector, ImmutableSet> toImmutableSet() {
        return Collector.of(ImmutableSet.Builder::new,
                            ImmutableSet.Builder::add,
                            (s, r) -> s.addAll(r.build()),
                            ImmutableSet.Builder::build,
                            Characteristics.UNORDERED);
    }

    /**
     * Returns a {@code Collector} that accumulates the input elements into a
     * new ImmutableList.
     *
     * @param  type
     * @return a {@code Collector} which collects all the input elements into a
     * {@code ImmutableList}, in encounter order
     *
     * @deprecated in 1.11.0 consider using {@link ImmutableList#toImmutableList()} instead.
     */
    @Deprecated
    public static  Collector, ImmutableList> toImmutableList() {
        return Collector.of(ImmutableList.Builder::new,
                            ImmutableList.Builder::add,
                            (s, r) -> s.addAll(r.build()),
                            ImmutableList.Builder::build);
    }

    private GuavaCollectors() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy