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

This code example shows how to use the following methods:get, set
    assertEquals(2, counter.get());
  } 
 
  @Test 
  public void testAndHavingSpec () { 
    AtomicInteger counter = new AtomicInteger(0);
    AndHavingSpec spec = new AndHavingSpec(ImmutableList.of(
      (HavingSpec)new CountingHavingSpec(counter, true),
      new CountingHavingSpec(counter, true),
      new CountingHavingSpec(counter, true),
      new CountingHavingSpec(counter, true)
    )); 
 
    spec.eval(ROW);
 
    assertEquals(4, counter.get());
 
    counter.set(0);
    spec = new AndHavingSpec(ImmutableList.of(
      (HavingSpec)new CountingHavingSpec(counter, false),

9
CodeRank
This code example shows how to use the following methods:
public class SizeBlockingQueue<E> extends AbstractQueue<E> implements BlockingQueue<E> {
 
    private final BlockingQueue<E> queue;
    private final int capacity;
 
    private final AtomicInteger size = new AtomicInteger();
 
    public SizeBlockingQueue(BlockingQueue<E> queue, int capacity) {
        assert capacity >= 0;
        this.queue = queue;
        this.capacity = capacity;
    } 
 
    @Override 
    public int size() { 
        return size.get();
    } 
 
    public int capacity() { 
        return this.capacity;
9
CodeRank
This code example shows how to use the following methods:incrementAndGet
    /** 
     * Increases the ref count, and returns <tt>true</tt> if it managed to 
     * actually increment it. 
     */ 
    public boolean increaseRefCount() { 
        return refCount.incrementAndGet() > 1;
    } 
 
    public void decreaseRefCount(boolean delete) {
        if (refCount.decrementAndGet() <= 0) {
            try { 
                raf.close();
                if (delete) {
                    file.delete();
                } 
            } catch (IOException e) {
                // ignore 
            } 
        } 
    } 
9
CodeRank
This code example shows how to use the following methods:get
		channel.send(new GenericMessage<String>("test1"));
	} 
 
	@Test
	public void testMultipleSelectorsAccept() { 
		final AtomicInteger counter = new AtomicInteger();
		MessageSelector selector1 = new TestMessageSelector(true, counter);
		MessageSelector selector2 = new TestMessageSelector(true, counter);
		MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector1, selector2);
		QueueChannel channel = new QueueChannel();
		channel.addInterceptor(interceptor);
		assertTrue(channel.send(new GenericMessage<String>("test1")));
		assertEquals(2, counter.get());
	} 
 
	@Test
	public void testMultipleSelectorsReject() { 
		boolean exceptionThrown = false;
		final AtomicInteger counter = new AtomicInteger();
		MessageSelector selector1 = new TestMessageSelector(true, counter);
8
CodeRank
This code example shows how to use the following methods:get, getAndSet
     * the count down reached zero with this fast forward call otherwise 
     * <code>false</code> 
     */ 
    public boolean fastForward() { 
        assert originalCount > 0;
        assert countDown.get() >= 0;
        return countDown.getAndSet(0) > 0;
    } 
     
    /** 
     * Returns <code>true</code> iff the count-down has reached zero. Otherwise <code>false</code> 
     */ 
    public boolean isCountedDown() { 
        assert countDown.get() >= 0;
        return countDown.get() == 0;
    } 
} 
8
CodeRank
This code example shows how to use the following methods:getAndIncrement
 
    private final int uniqueId;
    private final String setName;
 
    RealElement(String setName) {
        uniqueId = nextUniqueId.getAndIncrement();
        this.setName = setName;
    } 
 
    public String setName() {
        return setName;
    } 
 
    public int uniqueId() { 
        return uniqueId;
    } 
 
    public Class<? extends Annotation> annotationType() {
        return Element.class; 
    } 
8
CodeRank
This code example shows how to use the following methods:
 * local node. 
 */ 
 
public class VersionGenerator 
{ 
    private static final AtomicInteger version = new AtomicInteger(0);
 
    public static int getNextVersion() 
    { 
        return version.incrementAndGet();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:get, set
        client().admin().indices().prepareFlush().execute().actionGet(); 
        client().admin().indices().refresh(refreshRequest()).actionGet(); 
 
        String script = "org.elasticsearch.search.scriptfilter.ScriptFilterSearchTests.incrementScriptCounter() > 0";
 
        scriptCounter.set(0);
        logger.info("running script filter the first time"); 
        SearchResponse response = client().prepareSearch()
                .setQuery(filteredQuery(termQuery("test", "1"), scriptFilter(script).cache(true)))
                .execute().actionGet(); 
 
        assertThat(response.getHits().totalHits(), equalTo(1l));
        assertThat(scriptCounter.get(), equalTo(3));
 
        scriptCounter.set(0);
        logger.info("running script filter the second time"); 
        response = client().prepareSearch()
                .setQuery(filteredQuery(termQuery("test", "2"), scriptFilter(script).cache(true)))
                .execute().actionGet(); 
 

8
CodeRank
This code example shows how to use the following methods:
    // we maintain size separately because concurrent deque implementations typically have linear-time size() impls 
    final AtomicInteger size;
 
    public ConcurrentDequeRecycler(C<T> c, int maxSize) {
        super(c, ConcurrentCollections.<T>newDeque(), maxSize);
        this.size = new AtomicInteger();
    } 
 
    @Override 
    public void close() { 
        assert deque.size() == size.get();
        super.close(); 
        size.set(0);
    } 
 
    @Override 
    public V<T> obtain(int sizing) {
        final V<T> v = super.obtain(sizing);
        if (v.isRecycled()) {
            size.decrementAndGet();
8
CodeRank
This code example shows how to use the following methods:getAndIncrement
            AtomicInteger old = this.usage.putIfAbsent(id, count);
            if (old != null) {
                count = old;
            } 
        } 
        return count.getAndIncrement();
    } 
 
    @Override 
    public int decrementUsage(I id) {
        AtomicInteger count = this.usage.get(id);
        return (count != null) ? count.decrementAndGet() : 0;
    } 
 
    @Override 
    public int totalUsage() { 
        int total = 0;
        for (AtomicInteger count: this.usage.values()) {
            total += count.get();
        } 
8
CodeRank

Related Java 8 AtomicInteger Questions & Answers:

See Code Examples for Java 8 AtomicInteger Methods: