当前位置: 首页>>代码示例>>Java>>正文


Java ArrayDeque.offer方法代码示例

本文整理汇总了Java中java.util.ArrayDeque.offer方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayDeque.offer方法的具体用法?Java ArrayDeque.offer怎么用?Java ArrayDeque.offer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.ArrayDeque的用法示例。


在下文中一共展示了ArrayDeque.offer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: arrayDequeStuff

import java.util.ArrayDeque; //导入方法依赖的package包/类
static void arrayDequeStuff() {
  ArrayDeque<Object> d = new ArrayDeque<>();
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.add(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.addFirst(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.addLast(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.offerFirst(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.offerLast(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.offer(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.push(null);
  // BUG: Diagnostic contains: passing @Nullable parameter 'null' where @NonNull is required
  d.toArray(null);
  // this should be fine
  d.toArray();
}
 
开发者ID:uber,项目名称:NullAway,代码行数:22,代码来源:NullAwayNativeModels.java

示例2: postCompleteWithRequest

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Test
public void postCompleteWithRequest() {
    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {
        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    };

    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();

    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);

    ts.assertResult(1);
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:21,代码来源:QueueDrainHelperTest.java

示例3: postCompleteCancelled

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Test
public void postCompleteCancelled() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {
        @Override
        public boolean getAsBoolean() throws Exception {
            return ts.isCancelled();
        }
    };

    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();
    ts.cancel();

    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);

    ts.assertEmpty();
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:22,代码来源:QueueDrainHelperTest.java

示例4: postCompleteCancelledAfterOne

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Test
public void postCompleteCancelledAfterOne() {
    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            cancel();
        }
    };
    ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
    AtomicLong state = new AtomicLong();
    BooleanSupplier isCancelled = new BooleanSupplier() {
        @Override
        public boolean getAsBoolean() throws Exception {
            return ts.isCancelled();
        }
    };

    ts.onSubscribe(new BooleanSubscription());
    queue.offer(1);
    state.getAndIncrement();

    QueueDrainHelper.postComplete(ts, queue, state, isCancelled);

    ts.assertValue(1).assertNoErrors().assertNotComplete();
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:27,代码来源:QueueDrainHelperTest.java

示例5: suspend

import java.util.ArrayDeque; //导入方法依赖的package包/类
public SuspendedContextChanges suspend(FacesContext facesContext)
{
  if (_stack == null)
  {
    _LOG.fine("Stack with no changes has been suspended");
    return new SuspendedContextChangesImpl(new ArrayDeque<ComponentContextChange>(0));
  }

  ArrayDeque<ComponentContextChange> q = new ArrayDeque<ComponentContextChange>(_stack.size());
  for (ComponentContextChange change : _stack)
  {
    change.suspend(facesContext);
    q.offer(change);
  }

  _stack = null;

  if (_LOG.isFine())
  {
    _LOG.fine("Component change stack has been suspended. Number of suspended changes: {0}",
      new Object[] { q.size() });
  }

  return new SuspendedContextChangesImpl(q);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:ComponentContextManagerImpl.java

示例6: onNext

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public final void onNext(T item) {
    T dropped = null;
    synchronized (this) {
        ArrayDeque<T> q = this.queue;
        if (q.size() == capacity) {
            if (dropNewest) {
                dropped = q.pollLast();
            } else {
                dropped = q.pollFirst();
            }
        }
        q.offer(item);
    }
    if (dropped != null) {
        try {
            onDrop.accept(dropped);
        } catch (Throwable ex) {
            upstream.cancel();
            onError(ex);
            return;
        }
    }
    drain();
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:26,代码来源:FolyamOnBackpressureBufferDrop.java

示例7: levelOrder1

import java.util.ArrayDeque; //导入方法依赖的package包/类
void levelOrder1(BinaryTreeNode btn) {
	BinaryTreeNode root = btn;
	ArrayDeque<BinaryTreeNode> queue = new ArrayDeque<BinaryTreeNode>();
	if (root == null)
		return;
	//使用offer和poll优于add和remove之处在于它们返回值可以判断成功与否,而不抛出异常
	queue.offer(root);
	while (queue.isEmpty() != true) {
		root = queue.poll();
		printNode(root);
		if (root.leftNode != null)
			queue.offer(root.leftNode);
		if (root.rightNode != null)
			queue.offer(root.rightNode);
	}
}
 
开发者ID:selfconzrr,项目名称:Tree_learning,代码行数:17,代码来源:binaryTree.java

示例8: main

import java.util.ArrayDeque; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    final String stringPath = "files/Files-and-Streams" ;
    File file = new File(stringPath);
    PrintWriter writer = new PrintWriter("files/output08.txt");

    ArrayDeque<File> queue = new ArrayDeque<>();

    queue.offer(file);
    int counter = 1;
    while (!queue.isEmpty()){
        File currentDir = queue.poll();

        File[] nestedFiles = currentDir.listFiles();
        for (File nestedFile : nestedFiles) {
            if(nestedFile.isDirectory()){
                queue.offer(nestedFile);
                counter++;
            }
        }
        System.out.println(currentDir.getName());
        writer.println(currentDir.getName());
    }
    System.out.println(counter + " folders");
    writer.println(counter + " folders");
    writer.close();
}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:27,代码来源:p08_NestedFolders.java

示例9: completeRequestRace

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Test
public void completeRequestRace() {
    for (int i = 0; i < 500; i++) {
        final TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
        final ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
        final AtomicLong state = new AtomicLong();
        final BooleanSupplier isCancelled = new BooleanSupplier() {
            @Override
            public boolean getAsBoolean() throws Exception {
                return false;
            }
        };

        ts.onSubscribe(new BooleanSubscription());
        queue.offer(1);

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                QueueDrainHelper.postCompleteRequest(1, ts, queue, state, isCancelled);
            }
        };

        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                QueueDrainHelper.postComplete(ts, queue, state, isCancelled);
            }
        };

        TestCommonHelper.race(r1, r2);

        ts.assertResult(1);
    }
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:36,代码来源:QueueDrainHelperTest.java

示例10: main

import java.util.ArrayDeque; //导入方法依赖的package包/类
public static void main(String[] args) {

    ArrayDeque<Integer> ad = new ArrayDeque<>();
    
    // add element of array
    ad.add(3);
    ad.add(4);        
    System.out.println("Add Element. content: " + ad.toString());
    
    // add element to its first (head) & last (tail) index
    ad.addFirst(1);
    ad.addLast(5);
    System.out.println("AddFirst & AddLast. content: "+ ad.toString());
   
    // offers are similar to adds
    ad.offer(6);
    ad.offer(7);
    ad.offerFirst(0);
    ad.offerLast(8);
    System.out.println("Offers. content: " + ad.toString());
    System.out.println("Current size: " + ad.size());
    
    // peekFirst, peek, getFirst data
    System.out.println("Peek First data is " + ad.peekFirst());
    System.out.println("Peek data is " + ad.peek());
    System.out.println("GetFirst is " + ad.getFirst());
    
    // peekLast, getLast data
    System.out.println("Peek Last data is " + ad.peekLast());
    System.out.println("GetLast is " + ad.getLast());
    
    // polls, get data & remove from queue
    System.out.println("PollFirst data is " + ad.pollFirst() + ", content: " + ad.toString() );
    System.out.println("Poll data is " + ad.poll()+ ", content: " + ad.toString());
    System.out.println("PollLast data is " + ad.pollLast() + ", content: " + ad.toString());                
}
 
开发者ID:mkdika,项目名称:learnjava8,代码行数:37,代码来源:TestArrayDeque.java

示例11: onNext

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public void onNext(T item) {
    ArrayDeque<T> q = this.queue;
    if (q.size() == n) {
        actual.onNext(q.poll());
    }
    q.offer(item);
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:9,代码来源:FolyamSkipLast.java

示例12: tryOnNext

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public boolean tryOnNext(T item) {
    ArrayDeque<T> q = this.queue;
    boolean b = true;
    if (q.size() == n) {
        b = actual.tryOnNext(q.poll());
    }
    q.offer(item);
    return b;
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:11,代码来源:FolyamSkipLast.java

示例13: onNext

import java.util.ArrayDeque; //导入方法依赖的package包/类
@Override
public final void onNext(T item) {
    ArrayDeque<T> q = this.queue;
    if (q.size() == n) {
        q.poll();
    }
    q.offer(item);
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:9,代码来源:FolyamTakeLast.java

示例14: testOfferNull

import java.util.ArrayDeque; //导入方法依赖的package包/类
/**
 * offer(null) throws NPE
 */
public void testOfferNull() {
    ArrayDeque q = new ArrayDeque();
    try {
        q.offer(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ArrayDequeTest.java

示例15: partialSuspend

import java.util.ArrayDeque; //导入方法依赖的package包/类
public SuspendedContextChanges partialSuspend(
  FacesContext    facesContext,
  SuspendCallback callback)
{
  if (_stack == null)
  {
    _LOG.fine("Stack with no changes has been partially suspended");
    return new SuspendedContextChangesImpl(new ArrayDeque<ComponentContextChange>(0));
  }

  ArrayDeque<ComponentContextChange> q = new ArrayDeque<ComponentContextChange>(_stack.size());
  for (Iterator<ComponentContextChange> iter = _stack.iterator();
       iter.hasNext(); )
  {
    ComponentContextChange change = iter.next();
    SuspendCallback.SuspendResult result = callback.getSuspendResult(change);

    if (result == SuspendCallback.SuspendResult.STOP)
    {
      break;
    }

    iter.remove();
    change.suspend(facesContext);
    q.offer(change);

    if (result == SuspendCallback.SuspendResult.STOP_AFTER_CURRENT)
    {
      break;
    }
  }

  if (_LOG.isFine())
  {
    _LOG.fine("Component change stack has been partially suspended. " +
              "Number of suspended changes: {0}. New stack size: {1}",
      new Object[] { q.size(), _stack.size() });
  }

  if (_stack.isEmpty())
  {
    _stack = null;
  }

  return new SuspendedContextChangesImpl(q);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:47,代码来源:ComponentContextManagerImpl.java


注:本文中的java.util.ArrayDeque.offer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。