Java 8 ConcurrentMap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ConcurrentMap class.

This code example shows how to use the following methods: replace, containsKey, containsValue, get, isEmpty
 
		String testKey = new String("testKey");
		Object testValue1 = new Object(); 
		Object testValue2 = new Object(); 
 
		Assert.assertFalse(concurrentMap.containsKey(testKey));
		Assert.assertTrue(finalizeActions.isEmpty());
		Assert.assertNull(concurrentMap.put(testKey, testValue1));
		Assert.assertTrue(concurrentMap.containsKey(testKey));
		Assert.assertSame(testValue1, concurrentMap.get(testKey));
		Assert.assertTrue(concurrentMap.containsValue(testValue1));
		Assert.assertEquals(1, finalizeActions.size());
		Assert.assertSame(testValue1, concurrentMap.put(testKey, testValue2));
		Assert.assertTrue(concurrentMap.containsKey(testKey));
		Assert.assertSame(testValue2, concurrentMap.get(testKey));
		Assert.assertFalse(concurrentMap.containsValue(testValue1));
		Assert.assertTrue(concurrentMap.containsValue(testValue2));
		Assert.assertEquals(1, finalizeActions.size());
 
		Set<String> keySet = concurrentMap.keySet();

9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: get
        this.map = map;
    } 
 
    @Override 
    public T get(long key) {
        return map.get(key);
    } 
 
    @Override 
    public T remove(long key) {
        return map.remove(key);
    } 
 
    @Override 
    public T put(long key, T value) {
        return map.put(key, value);
    } 
 
    @Override 
    public T putIfAbsent(long key, T value) {
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: isEmpty
    private final static class KeyLock extends ReentrantLock {
        private final AtomicInteger count = new AtomicInteger(1);
    } 
 
    public boolean hasLockedKeys() { 
        return !map.isEmpty();
    } 
 
    /** 
     * A {@link KeyedLock} that allows to acquire a global lock that guarantees 
     * exclusive access to the resource the KeyedLock is guarding. 
     */ 
    public final static class GlobalLockable<T> extends KeyedLock<T> { 
 
        private final ReadWriteLock lock = new ReentrantReadWriteLock();
 
        @Override 
        public void acquire(T key) {
            boolean success = false;
            lock.readLock().lock();
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: putIfAbsent, get
	 * @return the {@code JAXBContext} 
	 * @throws HttpMessageConversionException in case of JAXB errors 
	 */ 
	protected final JAXBContext getJaxbContext(Class<?> clazz) {
		Assert.notNull(clazz, "'clazz' must not be null");
		JAXBContext jaxbContext = this.jaxbContexts.get(clazz);
		if (jaxbContext == null) {
			try { 
				jaxbContext = JAXBContext.newInstance(clazz);
				this.jaxbContexts.putIfAbsent(clazz, jaxbContext);
			} 
			catch (JAXBException ex) {
				throw new HttpMessageConversionException(
						"Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex);
			} 
		} 
		return jaxbContext;
	} 
 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: get
	private final Object lock = new Object(); 
 
 
	@Override 
	public Set<String> getSessionIds(String user) {
		Set<String> set = this.userSessionIds.get(user);
		return (set != null) ? set : Collections.<String>emptySet();
	} 
 
	@Override 
	public void registerSessionId(String user, String sessionId) {
		Assert.notNull(user, "User must not be null");
		Assert.notNull(sessionId, "Session ID must not be null");
		synchronized (this.lock) {
			Set<String> set = this.userSessionIds.get(user);
			if (set == null) { 
				set = new CopyOnWriteArraySet<String>(); 
				this.userSessionIds.put(user, set);
			} 
			set.add(sessionId); 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: putIfAbsent
        return map.put(key, value);
    } 
 
    @Override 
    public T putIfAbsent(long key, T value) {
        return map.putIfAbsent(key, value);
    } 
 
    // MAP DELEGATION 
 
    @Override 
    public boolean isEmpty() { 
        return map.isEmpty();
    } 
 
    @Override 
    public int size() { 
        return map.size();
    } 
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: containsKey, get, put
  public ValidationInfo validate() { 
    String path = myExecutablePathField.getText();
 
    boolean error;
 
    if (myValidateCache.containsKey(path)) {
      error = myValidateCache.get(path);
    } 
    else { 
      try { 
        if (StringUtil.isEmpty(path)) {
          return new ValidationInfo("Please select path to executable"); 
        } 
 
        new PhoneGapCommandLine(path, null).version();
        error = false;
      } 
      catch (Exception e) {
        error = true;
      } 

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: put
 
  @Override 
  public V put(K key, V value) {
    checkType(key);
    checkType(value);
    return map.put(key, value);
  } 
 
  @Override 
  public V remove(K key) {
    return copyIfRequired(map.remove(key));
  } 
 
  @Override 
  public void clear() { 
    map.clear();
  } 
 
  @Override 
  public int size() { 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: containsKey
        return map.size();
    } 
 
    @Override 
    public boolean contains(Object o) { 
        return map.containsKey(o);
    } 
 
    @Override 
    public boolean add(E o) {
        return map.putIfAbsent(o, Boolean.TRUE) == null;
    } 
 
    @Override 
    public boolean remove(Object o) { 
        return map.remove(o) != null;
    } 
 
    @Override 
    public void clear() { 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: putIfAbsent, remove, get, size
        this.accessQueue = ConcurrentDirectDeque.newInstance();
        this.maxEntries = maxEntries;
    } 
 
    public void add(K key, V newValue) {
        CacheEntry<K, V> value = cache.get(key);
        if (value == null) {
            long expires;
            if(maxAge == -1) {
                expires = -1;
            } else { 
                expires = System.currentTimeMillis() + maxAge;
            } 
            value = new CacheEntry<>(key, newValue, expires);
            CacheEntry result = cache.putIfAbsent(key, value);
            if (result != null) {
                value = result;
                value.setValue(newValue);
            } 
            bumpAccess(value);

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
See Code Examples for Java 8 ConcurrentMap Methods: