當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。