Java 8 AtomicIntegerArray - 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 AtomicIntegerArray class.

This code example shows how to use the following methods:set
        JSON json = (JSON) JSON.parse(text);
        Assert.assertEquals("[214748364812,2147483648123]", json.toJSONString());
    } 
 
    public void test_AtomicIntegerArray() throws Exception {
        AtomicIntegerArray array = new AtomicIntegerArray(3);
        array.set(0, 1);
        array.set(1, 2);
        array.set(2, 3);
        String text = JSON.toJSONString(array);
        Assert.assertEquals("[1,2,3]", text);
    } 
 
    public void test_AtomicLongArray() throws Exception {
        AtomicLongArray array = new AtomicLongArray(3);
        array.set(0, 1);
        array.set(1, 2);
        array.set(2, 3);
        String text = JSON.toJSONString(array);
        Assert.assertEquals("[1,2,3]", text);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get
		return length(); 
	} 
 
	@Override 
	public int get(int i) {
		return store.get(i);
	} 
 
	@Override 
	public int set(int i, int newValue) throws PaletteFullException {
		return store.getAndSet(i, newValue);
	} 
 
	@Override 
	public boolean compareAndSet(int i, int expect, int update) throws PaletteFullException {
		return store.compareAndSet(i, expect, update);
	} 
 
	@Override 
	public boolean isPaletteMaxSize() { 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get
	 * @param index to lookup 
	 * @return live value 
	 */ 
	@LiveRead 
	public short getLive(int index) {
		int packed = live.get(index >> 1);
		if ((index & 0x1) == 0) {
			return unpackZero(packed);
		} else { 
			return unpackOne(packed);
		} 
	} 
 
	/** 
	 * Sets the value for the next snapshot 
	 * 
	 * @param index to set at 
	 * @param value to set to 
	 * @return the old value 
	 */ 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get
	public final int get(int i) {
		if (fullWidth) {
			return array.get(i);
		} 
 
		return unPack(array.get(getIndex(i)), getSubIndex(i));
	} 
 
	/** 
	 * Sets an element to the given value 
	 * 
	 * @param i the index 
	 * @param newValue the new value 
	 */ 
	public final void set(int i, int newValue) {
		if (fullWidth) {
			array.set(i, newValue);
			return; 
		} 
 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get
		short[] array = getArray();
		return Arrays.toString(array);
	} 
 
	private int getPacked(int index) {
		return backingArray.get(index >> 1);
	} 
 
	private static boolean isEven(int index) {
		return (index & 1) == 0;
	} 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:incrementAndGet, length
		totalTimeNS.addAndGet(durationNS);
		int durationMS = (int)(durationNS / 1000000L);
		// round to bucket interval 
		int bucket = durationMS / bucketSizeMS;
		 
		int maxTime = responseTimeArray.length() - 1;
		responseTimeArray.incrementAndGet((bucket >= 0 && bucket < maxTime) ? bucket : maxTime);
		if(c == 1)
		{ 
			// make sure in the window between fetch count 
			// and here, we don't overwrite any changes 
			minTimeNS.compareAndSet(0L, durationNS);
			maxTimeNS.compareAndSet(0L, durationNS);
		} 
		else 
		{ 
			// No point in looping here, if we miss a sample then I don't think 
			// it's the end of the world. The compareAndSet just makes sure 
			// it either works correctly or not at all 
			long min = minTimeNS.get();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:compareAndSet, get
	 *  
	 * @return <code>true</code> if lock otherwise false. 
	 * @throws TransactionException incase the lock is hold by other thread. 
	 */ 
	public static boolean lock( int lockIndex, byte[] contextLocks) throws TransactionException{
		final int lock = locks.get(lockIndex); 
		final int selfLockIndex = lockIndex>>>DIVIDE_8;
		final byte selfLockByte = contextLocks[selfLockIndex];
		final byte selfLockBit = (byte)(1 << (lockIndex & MODULE_8));
		 
		if( (lock & LOCK) != 0){  //is already locked?
			if( (selfLockByte & selfLockBit) != 0) // check for self locking
				return false; 
			throw FAILURE_EXCEPTION; 
		} 
 
		boolean isLocked = locks.compareAndSet(lockIndex, lock, lock | LOCK);
		 
		if( !isLocked)
			throw FAILURE_EXCEPTION;

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
	public AtomicShortIntDirectBackingArray(int length, int[] initial) {
		super(length);
		if (initial.length != length) {
			throw new IllegalArgumentException("The length of the initialization array must match the given length");
		} 
		store = new AtomicIntegerArray(initial);
		width = AtomicShortIntPaletteBackingArray.roundUpWidth(length - 1);
	} 
 
	@Override 
	public int width() { 
		return width;
	} 
 
	@Override 
	public int getPaletteSize() { 
		return length(); 
	} 
 
	@Override 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
	public void initialize(Configuration conf) throws ServiceException {
		_keyhash = new ConcurrentHashMap<Object, LockKey>();
        _objhash = new ConcurrentHashMap<Object, Object>();
        _count = new AtomicInteger(0);
        _ixCount = new AtomicInteger(0);
        _xCountPagePerHeight = new AtomicIntegerArray(10);
        _xCountNodePerHeight = new AtomicIntegerArray(10);
        _xCountNodePerRange = new AtomicIntegerArray(10);
        _collisionCount = new AtomicInteger(0);
        _left = 0;
        _right = 0;
        _buf = new StringBuffer();
	} 
 
// instance methods /////////////////////////////////////////////////////// 
 
    public void lock(Object keyid, Object objid, int mode) {
        try { 
        	//System.out.println("Locker.lock "+ 
        	//		keyid.toString()+", " 
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get
		} 
	} 
 
	public static int checkLock(int hash, int id) throws TransactionException {
		assert hash <= MASK;
		int lock = locks.get(hash);
		if ((lock & LOCK) != 0) {
			if ((lock & IDMASK) != id) {
				// Already locked by other thread 
				throw FAILURE_EXCEPTION;
			} else { 
				// We already own this lock 
				return -1; 
			} 
		} 
 
		// Return old timestamp (lock bit is not set) 
		return lock;
	} 
 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 AtomicIntegerArray Methods: