Java Iterator reduceSet(Iterator> values)

Here you can find the source of reduceSet(Iterator> values)

Description

A helper method for set MapReduce.

License

Open Source License

Parameter

Parameter Description
values the aggregated values associated with the key
T the type of the set

Return

the combined set

Declaration

static <T> Set<T> reduceSet(Iterator<Set<T>> values) 

Method Source Code

//package com.java2s;
/*//from  ww w  .j  a  v  a2 s.co m
 * Grakn - A Distributed Semantic Database
 * Copyright (C) 2016  Grakn Labs Limited
 *
 * Grakn is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Grakn is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Grakn. If not, see <http://www.gnu.org/licenses/gpl.txt>.
 */

import java.util.HashSet;
import java.util.Iterator;

import java.util.Set;

public class Main {
    /**
     * A helper method for set MapReduce. It simply combines sets into one set.
     *
     * @param values the aggregated values associated with the key
     * @param <T>    the type of the set
     * @return the combined set
     */
    static <T> Set<T> reduceSet(Iterator<Set<T>> values) {
        Set<T> set = new HashSet<>();
        while (values.hasNext()) {
            set.addAll(values.next());
        }
        return set;
    }
}

Related

  1. printIterator(Iterator i, String header)
  2. printIterator(Iterator> it)
  3. put(String key, Iterator value)
  4. putAllFromAll(Map map, Iterator> mapsIterator)
  5. read(Iterator it, E[] array)
  6. removeAll(Collection collection, Iterator itemsToRemove)
  7. removeObject(Object item, Iterator iter, boolean justFirst)
  8. removeOnNext(final Iterator iterator)
  9. removeValue(List args, int idx, Iterator it)