ConcurrentSkipListSet api详解

本文通过单元测试详细探讨了Java并发集合ConcurrentSkipListSet的公共API用法。通过实际运行代码,作者初步掌握了该类的底层实现,并计划在深化理解后进一步完善内容。
摘要由CSDN通过智能技术生成

今天时间学习ConcurrentSkipListSet api,该类是JUC原子包中的类,通过单元测试代码把所有public api方法跑了一遍,大致了解了底层实现,初学乍练,有很多一知半解的地方,待后续有了深入理解再来补充

package test.java.util.concurrent;


import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
import org.junit.Test;

/**
 * ConcurrentSkipListSet的测试类
 *
 * @date 2020-07-09 00:21:55
 */
public class ConcurrentSkipListSetTest {
        /**
         *无参构造函数,使用ConcurrentSkipListMap的key
         * @Param
         */
        @Test
        public void testConstruct0()throws Exception{
                ConcurrentSkipListSet testObj=new ConcurrentSkipListSet();
                System.out.println(testObj.toString());
        }
        /**
         * 初始化comparator比较器通过构造函数,使用ConcurrentSkipListMap的key
         * @Param
         */
        @Test
        public void testConstruct1()throws Exception{
                Comparator comparator=((o1, o2) -> Integer.parseInt(o1.toString())+Integer.parseInt(o2.toString()));
                ConcurrentSkipListSet testObj=new ConcurrentSkipListSet(comparator);
                System.out.println(testObj.toString());
        }
        /**
         *初始化skipListSet,并将参数Collection中的值对放入新的skipListSet中,使用ConcurrentSkipListMap的key
         * @Param
         */
        @Test
        public void testConstruct2()throws Exception{
                Set<Integer> set=new HashSet<>();
                set.add(123);
                ConcurrentSkipListSet testObj=new ConcurrentSkipListSet(set);
                System.out.println(testObj.toString());
        }
        /**
         *通过sortedSet初始化ConcurrentSkipListSet,并将sortedSet中的元素放入新ConcurrentSkipListSet,使用ConcurrentSkipListMap的key
         * @Param
         */
        @Test
        public void testConstruct3()throws Exception{
                Set<Integer> sortedSet=new ConcurrentSkipListSet<>();
                sortedSet.add(1);
                sortedSet.add(2);
                sortedSet.add(4);
                sortedSet.add(3);

                ConcurrentSkipListSet testObj=new ConcurrentSkipListSet(sortedSet);
                System.out.println(testObj.toString());
        }
        /**
         * 浅拷贝
         * @Param
         */
        @Test
        public void testClone()throws Exception{
                ConcurrentSkipListSet testObj=new ConcurrentSkipListSet<>();
                testObj.add(213);
                ConcurrentSkipListSet set2=testObj.clone();
                System.out.println(testObj.hashCode());
                System.out.println(set2.hashCode());
        }
        /**
         * map中node数量
         * @Param
         */
        @Test
        public void testSize()throws Exception{
                ConcurrentSkipListSet<Integer> set=new ConcurrentSkipListSet<>();
                set.add
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值