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

tk.hongkailiu.test.app.helper.CollectionHelperImpl Maven / Gradle / Ivy

The newest version!
package tk.hongkailiu.test.app.helper;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;

import java.util.List;

public class CollectionHelperImpl implements CollectionHelper {

    private static volatile CollectionHelperImpl helper;

    private CollectionHelperImpl() {
        super();
    }

    public static CollectionHelper getInstance() {
        CollectionHelperImpl result = helper;
        if (result == null) {
            synchronized (CollectionHelperImpl.class) {
                result = helper;
                if (result == null) {
                    helper = result = new CollectionHelperImpl();
                }
            }
        }
        return result;
    }

    @Override public  List removeDuplicate(List list) {
        return ImmutableSet.copyOf(list).asList();
    }

    @Override public  boolean elementsEqual(Iterable i1, Iterable i2) {
        return Iterables.elementsEqual(i1, i2);
    }

    @Override public  boolean isOrdered(Iterable> iterable) {
        return Ordering.natural().isOrdered(iterable);
    }

    @Override public  List reverse(List list) {
        return Lists.reverse(list);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy