Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including
all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and
Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.remoting3.remote;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
/**
* Lock-free concurrent integer-indexed hash map.
*
* @param the value type
*
* @author David M. Lloyd
*/
final class IntIndexHashMap extends AbstractCollection implements IntIndexMap {
private static final int DEFAULT_INITIAL_CAPACITY = 512;
private static final int MAXIMUM_CAPACITY = 1 << 30;
private static final float DEFAULT_LOAD_FACTOR = 0.60f;
/** A row which has been resized into the new view. */
private static final Object[] RESIZED = new Object[0];
/** A non-existent table entry (as opposed to a {@code null} value). */
private static final Object NONEXISTENT = new Object();
private final IntIndexer super V> indexer;
private final Equaller super V> ve;
private volatile Table table;
private final float loadFactor;
private final int initialCapacity;
@SuppressWarnings("unchecked")
private static final AtomicIntegerFieldUpdater
sizeUpdater = AtomicIntegerFieldUpdater.newUpdater(Table.class, "size");
@SuppressWarnings("unchecked")
private static final AtomicReferenceFieldUpdater tableUpdater = AtomicReferenceFieldUpdater.newUpdater(IntIndexHashMap.class, Table.class, "table");
/**
* Construct a new instance.
*
* @param indexer the key indexer
* @param valueEqualler the value equaller
* @param initialCapacity the initial capacity
* @param loadFactor the load factor
*/
IntIndexHashMap(IntIndexer super V> indexer, Equaller super V> valueEqualler, int initialCapacity, float loadFactor) {
if (valueEqualler == null) {
throw new IllegalArgumentException("valueEqualler is null");
}
this.indexer = indexer;
ve = valueEqualler;
if (initialCapacity < 0) {
throw new IllegalArgumentException("Initial capacity must be > 0");
}
if (initialCapacity > MAXIMUM_CAPACITY) {
initialCapacity = MAXIMUM_CAPACITY;
}
if (loadFactor <= 0.0 || Float.isNaN(loadFactor) || loadFactor >= 1.0) {
throw new IllegalArgumentException("Load factor must be between 0.0f and 1.0f");
}
int capacity = 1;
while (capacity < initialCapacity) {
capacity <<= 1;
}
this.loadFactor = loadFactor;
this.initialCapacity = capacity;
final Table table = new Table(capacity, loadFactor);
tableUpdater.set(this, table);
}
/**
* Construct a new instance.
*
* @param indexer the key indexer
* @param valueEqualler the value equaller
*/
IntIndexHashMap(IntIndexer super V> indexer, Equaller super V> valueEqualler) {
this(indexer, valueEqualler, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
}
/**
* Construct a new instance.
*
* @param indexer the key indexer
* @param initialCapacity the initial capacity
* @param loadFactor the load factor
*/
IntIndexHashMap(IntIndexer super V> indexer, int initialCapacity, final float loadFactor) {
this(indexer, Equaller.DEFAULT, initialCapacity, loadFactor);
}
/**
* Construct a new instance.
*
* @param indexer the key indexer
* @param loadFactor the load factor
*/
IntIndexHashMap(IntIndexer super V> indexer, final float loadFactor) {
this(indexer, DEFAULT_INITIAL_CAPACITY, loadFactor);
}
/**
* Construct a new instance.
*
* @param indexer the key indexer
* @param initialCapacity the initial capacity
*/
IntIndexHashMap(IntIndexer super V> indexer, final int initialCapacity) {
this(indexer, initialCapacity, DEFAULT_LOAD_FACTOR);
}
/**
* Construct a new instance.
*
* @param indexer the key indexer
*/
IntIndexHashMap(IntIndexer super V> indexer) {
this(indexer, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
}
public V putIfAbsent(final V value) {
final V result = doPut(value, true, table);
return result == NONEXISTENT ? null : result;
}
public V removeKey(final int index) {
final V result = doRemove(index, table);
return result == NONEXISTENT ? null : result;
}
@SuppressWarnings({ "unchecked" })
public boolean remove(final Object value) {
return doRemove((V) value, table);
}
public boolean containsKey(final int index) {
return doGet(table, index) != NONEXISTENT;
}
public V get(final int index) {
final V result = doGet(table, index);
return result == NONEXISTENT ? null : result;
}
public V put(final V value) {
final V result = doPut(value, false, table);
return result == NONEXISTENT ? null : result;
}
public V replace(final V value) {
final V result = doReplace(value, table);
return result == NONEXISTENT ? null : result;
}
public boolean replace(final V oldValue, final V newValue) {
if (indexer.getKey(oldValue) != indexer.getKey(newValue)) {
throw new IllegalArgumentException("Can only replace with value which has the same key");
}
return doReplace(oldValue, newValue, table);
}
public int getKey(final V argument) {
return indexer.getKey(argument);
}
public boolean add(final V v) {
return doPut(v, true, table) == NONEXISTENT;
}
public T[] toArray(final T[] a) {
final ArrayList list = new ArrayList(size());
for (V item : this) {
list.add(item);
}
return list.toArray(a);
}
public Object[] toArray() {
final ArrayList