Java List Select selectDuplicateQualifiers( List elements)

Here you can find the source of selectDuplicateQualifiers( List elements)

Description

select Duplicate Qualifiers

License

Open Source License

Declaration

public static <T> Collection<T> selectDuplicateQualifiers(
            List<T> elements) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2013 Borland Software Corporation and others.
 * /*from  w  w w  . j  av a2s. c om*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *   
 * Contributors:
 *     Borland Software Corporation - initial API and implementation
 *     Christopher Gerking - bug 289982
 *     Alex Paperno - bugs 424584
 *******************************************************************************/

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;

import java.util.List;
import java.util.Set;

public class Main {
    public static <T> Collection<T> selectDuplicateQualifiers(
            List<T> elements) {
        Set<T> result = null;
        for (T nextQualifier : elements) {
            if (Collections.frequency(elements, nextQualifier) > 1) {
                if (result == null) {
                    result = new HashSet<T>(2);
                }

                result.add(nextQualifier);
            }
        }
        return (result != null) ? result : Collections.<T> emptySet();
    }
}

Related

  1. select(List list, List indices, List sel)
  2. select(List src, List indexes)
  3. selectElements(final List list, int start, int end)
  4. selectExactly(List original, int nb)
  5. selectFields(String[] fields, List fieldList, int allFieldsFrom, String separator)
  6. selectRandom(List list)