List of usage examples for java.util Queue remove
E remove();
From source file:Main.java
public static void main(String[] args) { Queue<String> queue = new LinkedList<String>(); queue.offer("First"); queue.offer("Second"); queue.offer("Third"); queue.offer("Fourth"); queue.remove(); System.out.println(queue);/* www .j a va 2 s. c o m*/ }
From source file:Main.java
public static void main(String[] args) { Queue<String> queue = new LinkedList<String>(); queue.add("A"); queue.add("B"); queue.offer("C"); queue.offer("D"); System.out.println("remove: " + queue.remove()); System.out.println("element: " + queue.element()); System.out.println("poll: " + queue.poll()); System.out.println("peek: " + queue.peek()); }
From source file:CircularArrayQueueTest.java
public static void main(String[] args) { Queue<String> q = new CircularArrayQueue<String>(5); q.add("Amy"); q.add("Bob"); q.add("Carl"); q.add("Deedee"); q.add("Emile"); q.remove(); q.add("Fifi"); q.remove();/*from w w w . j a va2 s. c o m*/ for (String s : q) System.out.println(s); }
From source file:com.ok2c.lightmtp.examples.MailUserAgentExample.java
public static void main(final String[] args) throws Exception { String text1 = "From: root\r\n" + "To: testuser1\r\n" + "Subject: test message 1\r\n" + "\r\n" + "This is a short test message 1\r\n"; String text2 = "From: root\r\n" + "To: testuser1, testuser2\r\n" + "Subject: test message 2\r\n" + "\r\n" + "This is a short test message 2\r\n"; String text3 = "From: root\r\n" + "To: testuser1, testuser2, testuser3\r\n" + "Subject: test message 3\r\n" + "\r\n" + "This is a short test message 3\r\n"; List<DeliveryRequest> requests = new ArrayList<DeliveryRequest>(); requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1"), new ByteArraySource(text1.getBytes("US-ASCII")))); requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2"), new ByteArraySource(text2.getBytes("US-ASCII")))); requests.add(new BasicDeliveryRequest("root", Arrays.asList("testuser1", "testuser2", "testuser3"), new ByteArraySource(text3.getBytes("US-ASCII")))); MailUserAgent mua = new DefaultMailUserAgent(TransportType.SMTP, IOReactorConfig.DEFAULT); mua.start();/*from ww w . j a v a 2 s . c o m*/ try { InetSocketAddress address = new InetSocketAddress("localhost", 2525); Queue<Future<DeliveryResult>> queue = new LinkedList<Future<DeliveryResult>>(); for (DeliveryRequest request : requests) { queue.add(mua.deliver(new SessionEndpoint(address), 0, request, null)); } while (!queue.isEmpty()) { Future<DeliveryResult> future = queue.remove(); DeliveryResult result = future.get(); System.out.println("Delivery result: " + result); } } finally { mua.shutdown(); } }
From source file:Main.java
public static void main(String[] args) { Queue<String> queue = new LinkedList<>(); queue.add("Java"); // offer() will work the same as add() queue.offer("SQL"); queue.offer("CSS"); queue.offer("XML"); System.out.println("Queue: " + queue); // Let's remove elements until the queue is empty while (queue.peek() != null) { System.out.println("Head Element: " + queue.peek()); queue.remove(); System.out.println("Removed one element from Queue"); System.out.println("Queue: " + queue); }/* w w w . java 2 s.c om*/ System.out.println("queue.isEmpty(): " + queue.isEmpty()); System.out.println("queue.peek(): " + queue.peek()); System.out.println("queue.poll(): " + queue.poll()); try { String str = queue.element(); System.out.println("queue.element(): " + str); str = queue.remove(); System.out.println("queue.remove(): " + str); } catch (NoSuchElementException e) { System.out.println("queue.remove(): Queue is empty."); } }
From source file:ComparablePerson.java
public static void main(String[] args) { int initialCapacity = 5; Comparator<ComparablePerson> nameComparator = Comparator.comparing(ComparablePerson::getName); Queue<ComparablePerson> pq = new PriorityQueue<>(initialCapacity, nameComparator); pq.add(new ComparablePerson(1, "Oracle")); pq.add(new ComparablePerson(4, "XML")); pq.add(new ComparablePerson(2, "HTML")); pq.add(new ComparablePerson(3, "CSS")); pq.add(new ComparablePerson(4, "Java")); System.out.println("Priority queue: " + pq); while (pq.peek() != null) { System.out.println("Head Element: " + pq.peek()); pq.remove(); System.out.println("Removed one element from Queue"); System.out.println("Priority queue: " + pq); }//from w w w. j a va 2 s .c o m }
From source file:io.aos.protocol.http.httpcommon.FluentAsync.java
public static void main(String... args) throws Exception { // Use pool of two threads ExecutorService threadpool = Executors.newFixedThreadPool(2); Async async = Async.newInstance().use(threadpool); Request[] requests = new Request[] { Request.Get("http://www.google.com/"), Request.Get("http://www.yahoo.com/"), Request.Get("http://www.apache.com/"), Request.Get("http://www.apple.com/") }; Queue<Future<Content>> queue = new LinkedList<Future<Content>>(); // Execute requests asynchronously for (final Request request : requests) { Future<Content> future = async.execute(request, new FutureCallback<Content>() { public void failed(final Exception ex) { System.out.println(ex.getMessage() + ": " + request); }/*from www .j a va 2 s . co m*/ public void completed(final Content content) { System.out.println("Request completed: " + request); } public void cancelled() { } }); queue.add(future); } while (!queue.isEmpty()) { Future<Content> future = queue.remove(); try { future.get(); } catch (ExecutionException ex) { } } System.out.println("Done"); threadpool.shutdown(); }
From source file:interoperabilite.webservice.fluent.FluentAsync.java
public static void main(String[] args) throws Exception { // Use pool of two threads ExecutorService threadpool = Executors.newFixedThreadPool(2); Async async = Async.newInstance().use(threadpool); Request[] requests = new Request[] { Request.Get("http://www.google.com/"), Request.Get("http://www.yahoo.com/"), Request.Get("http://www.apache.com/"), Request.Get("http://www.apple.com/") }; Queue<Future<Content>> queue = new LinkedList<Future<Content>>(); // Execute requests asynchronously for (final Request request : requests) { Future<Content> future = async.execute(request, new FutureCallback<Content>() { @Override/*w ww . j a v a 2s .c om*/ public void failed(final Exception ex) { System.out.println(ex.getMessage() + ": " + request); } @Override public void completed(final Content content) { System.out.println("Request completed: " + request); } @Override public void cancelled() { } }); queue.add(future); } while (!queue.isEmpty()) { Future<Content> future = queue.remove(); try { future.get(); } catch (ExecutionException ex) { } } System.out.println("Done"); threadpool.shutdown(); }
From source file:Main.java
public static <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T> aClazz) { //Check class hierarchy for (Class<?> c = clazz; c != null; c = c.getSuperclass()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; }//from w w w . jav a 2s .c o m } //Check interfaces (breadth first) Queue<Class<?>> q = new LinkedList<Class<?>>(); q.add(clazz); while (!q.isEmpty()) { Class<?> c = q.remove(); if (c != null) { if (c.isInterface()) { T anno = c.getAnnotation(aClazz); if (anno != null) { return anno; } } else { q.add(c.getSuperclass()); } q.addAll(Arrays.asList(c.getInterfaces())); } } return null; }
From source file:org.apache.streams.util.ComponentUtils.java
public static String pollUntilStringNotEmpty(Queue queue) { String result = null;/*from w w w.j a v a 2 s .c o m*/ do { synchronized (ComponentUtils.class) { try { result = (String) queue.remove(); } catch (Exception e) { } } Thread.yield(); } while (result == null && !StringUtils.isNotEmpty(result)); return result; }