Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import java.util.RandomAccess;

public class Main {
    public static <E> void swap(final List<E> list, final int i, final int j) {
        if (list instanceof RandomAccess) {
            list.set(i, list.set(j, list.get(i)));
        } else {
            final ListIterator<E> iterator = list.listIterator(i);
            iterator.set(list.set(j, iterator.next()));
        }
    }

    public static <V> void get(final Map<?, ? extends V> map, final Collection<? extends Object> keys,
            final Collection<? super V> values) {
        for (final Object key : keys) {
            if (!map.containsKey(key)) {
                continue;
            }

            final V value = map.get(key);
            values.add(value);
        }
    }

    public static <V> void get(final Map<?, ? extends V> map, final Collection<? super V> values,
            final Object... keys) {
        for (final Object key2 : keys) {
            final Object key = key2;
            if (!map.containsKey(key)) {
                continue;
            }

            final V value = map.get(key);
            values.add(value);
        }
    }
}