get ConcurrentSkipListMap - Java java.util

Java examples for java.util:Map Creation

Description

get ConcurrentSkipListMap

Demo Code


//package com.java2s;
import java.util.Comparator;

import java.util.concurrent.ConcurrentSkipListMap;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getSkipListMap());
    }//  w ww.  jav a  2 s .  co m

    public static ConcurrentSkipListMap<Object, Object> getSkipListMap() {
        return new ConcurrentSkipListMap<Object, Object>(getComparator());
    }

    private static Comparator<Object> getComparator() {
        return new Comparator<Object>() {
            @SuppressWarnings("unchecked")
            @Override
            public int compare(final Object o1, final Object o2) {
                final Comparable<Object> c1 = (Comparable<Object>) o1;
                final Comparable<Object> c2 = (Comparable<Object>) o2;
                if (o1.getClass().equals(o2.getClass())) {
                    return c1.compareTo(c2);
                } else {
                    return c1.getClass().getName()
                            .compareTo(c2.getClass().getName());
                }
            }
        };
    }
}

Related Tutorials