Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Collection;

import java.util.Iterator;
import java.util.List;

import java.util.Map;

import java.util.Set;

public class Main {
    /**
     *  Adds all elements of the <code>src</code> collections to <code>dest</code>,
     *  returning <code>dest</code>. This is typically used when you need to combine
     *  collections temporarily for a method argument.
     *
     *  @since 1.0.7
     */
    public static <T> List<T> combine(List<T> dest, Collection<T>... src) {
        for (Collection<T> cc : src) {
            dest.addAll(cc);
        }
        return dest;
    }

    /**
     *  Adds all elements of the <code>src</code> collections to <code>dest</code>,
     *  returning <code>dest</code>. This is typically used when you need to combine
     *  collections temporarily for a method argument.
     *
     *  @since 1.0.7
     */
    public static <T> Set<T> combine(Set<T> dest, Collection<T>... src) {
        for (Collection<T> cc : src) {
            dest.addAll(cc);
        }
        return dest;
    }

    /**
     *  Adds all elements of the <code>src</code> collections to <code>dest</code>,
     *  returning <code>dest</code>. This is typically used when you need to combine
     *  collections temporarily for a method argument.
     *  <p>
     *  Note: source maps are added in order; if the same keys are present in multiple
     *  sources, the last one wins.
     *
     *  @since 1.0.7
     */
    public static <K, V> Map<K, V> combine(Map<K, V> dest, Map<K, V>... src) {
        for (Map<K, V> cc : src) {
            dest.putAll(cc);
        }
        return dest;
    }

    /**
     *  Appends an arbitrary number of explicit elements to an existing collection.
     *  Primarily useful when writing testcases.
     */
    public static <T> void addAll(Collection<T> coll, T... elems) {
        for (T elem : elems)
            coll.add(elem);
    }

    /**
     *  Appends the values returned by an iterator to the passed collection.
     */
    public static <T> void addAll(Collection<T> coll, Iterator<T> src) {
        while (src.hasNext())
            coll.add(src.next());
    }

    /**
     *  Appends the contents of an iterable object to the passed collection.
     */
    public static <T> void addAll(Collection<T> coll, Iterable<T> src) {
        addAll(coll, src.iterator());
    }
}