首页

关于openspaces源码包ConcurrentHashSet自定义类集实现Set接口

标签:openspaces,ConcurrentHashSet,自定义类集,Set     发布时间:2018-05-27   

一、前言

关于gs-openspaces源码包org.openspaces.core.util.ConcurrentHashSet自定义实现并发类集类,通过java.util.concurrent.ConcurrentHashMap并发Map实现,详情参见源码说明。

二、源码说明

package org.openspaces.core.util;@b@@b@import java.util.Collection;@b@import java.util.Iterator;@b@import java.util.Set;@b@import java.util.concurrent.ConcurrentHashMap;@b@@b@public class ConcurrentHashSet<E>@b@  implements Set<E>@b@{@b@  private final ConcurrentHashMap<E, Object> map;@b@  private static final Object PRESENT = new Object();@b@@b@  public ConcurrentHashSet()@b@  {@b@    this.map = new ConcurrentHashMap();@b@  }@b@@b@  public Iterator<E> iterator()@b@  {@b@    return this.map.keySet().iterator();@b@  }@b@@b@  public int size()@b@  {@b@    return this.map.size();@b@  }@b@@b@  public boolean isEmpty()@b@  {@b@    return this.map.isEmpty();@b@  }@b@@b@  public boolean contains(Object o)@b@  {@b@    if (o == null)@b@      return false;@b@@b@    return this.map.containsKey(o);@b@  }@b@@b@  public boolean add(E o)@b@  {@b@    if (o == null)@b@      return false;@b@@b@    return (this.map.put(o, PRESENT) == null);@b@  }@b@@b@  public boolean remove(Object o)@b@  {@b@    if (o == null)@b@      return false;@b@@b@    return (this.map.remove(o) == PRESENT);@b@  }@b@@b@  public void clear()@b@  {@b@    this.map.clear();@b@  }@b@@b@  public boolean addAll(Collection<? extends E> c)@b@  {@b@    throw new UnsupportedOperationException();@b@  }@b@@b@  public boolean containsAll(Collection<?> c)@b@  {@b@    throw new UnsupportedOperationException();@b@  }@b@@b@  public boolean removeAll(Collection<?> c)@b@  {@b@    throw new UnsupportedOperationException();@b@  }@b@@b@  public boolean retainAll(Collection<?> c)@b@  {@b@    throw new UnsupportedOperationException();@b@  }@b@@b@  public Object[] toArray()@b@  {@b@    throw new UnsupportedOperationException();@b@  }@b@@b@  public <T> T[] toArray(T[] a)@b@  {@b@    throw new UnsupportedOperationException();@b@  }@b@}