Java Code Examples for java.util.Queue#toArray()
The following examples show how to use
java.util.Queue#toArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpensteckTelemetryViewMessageHandler.java From onos with Apache License 2.0 | 6 votes |
private void populateMetrics(ChartModel cm, Queue<FlowInfo> flowInfoQ) { FlowInfo[] flowInfos = flowInfoQ.toArray(new FlowInfo[flowInfoQ.size()]); SimpleDateFormat form = new SimpleDateFormat(CHART_TIME_FORMAT); int timeOffset = 0; Integer dataPointCount = PERIOD_OPTION_MAP.get(currentPeriod); if (dataPointCount != null) { timeOffset = flowInfos.length - (int) dataPointCount; if (timeOffset < 0) { timeOffset = 0; } } for (int idx = timeOffset; idx < flowInfos.length; idx++) { Map<String, Object> local = Maps.newHashMap(); local.put(LABEL, form.format(new Date(flowInfos[idx].statsInfo().fstPktArrTime()))); local.put(STAT_CURR_ACC_PACKET, flowInfos[idx].statsInfo().currAccPkts()); local.put(STAT_PREV_ACC_PACKET, flowInfos[idx].statsInfo().prevAccPkts()); local.put(STAT_CURR_ACC_BYTE, flowInfos[idx].statsInfo().currAccBytes()); local.put(STAT_PREV_ACC_BYTE, flowInfos[idx].statsInfo().prevAccBytes()); local.put(STAT_ERROR_PACKET, flowInfos[idx].statsInfo().errorPkts()); local.put(STAT_DROP_PACKET, flowInfos[idx].statsInfo().dropPkts()); populateMetric(cm.addDataPoint(flowInfos[idx].uniqueFlowInfoKey()), local); } }
Example 2
Source File: DaemonStarter.java From neoscada with Eclipse Public License 1.0 | 6 votes |
public static void main ( final String[] args ) throws Exception { if ( args.length == 0 ) { throw new RuntimeException ( "syntax: DaemonStarter <daemon class name>" ); } final Queue<String> argList = new LinkedList<String> (); argList.addAll ( Arrays.asList ( args ) ); new DaemonStarter ( Class.forName ( argList.poll () ), argList.toArray ( new String[0] ) ); while ( true ) { Thread.sleep ( 1000 ); } }
Example 3
Source File: ConcurrentEvictingQueueGeneralTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void toArray() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(5); Object[] objects = queue.toArray(); assertThat(objects.length).isEqualTo(0); queue.add(1); assertThat(queue.toArray()).containsExactly(1); queue.clear(); queue.addAll(asList(1, 2, 3, 4, 5)); assertThat(queue.toArray()).containsExactly(1, 2, 3, 4, 5); queue.clear(); assertThat(queue).isEmpty(); queue.addAll(asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); assertThat(queue.toArray()).containsExactly(5, 6, 7, 8, 9); queue.clear(); assertThat(queue).isEmpty(); }
Example 4
Source File: J2SEDeployActionProvider.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String[] getSupportedActions() { final Set<NativeBundleType> nbts = NativeBundleType.getSupported(); final Queue<String> res = new ArrayDeque<>(nbts.size()); for (NativeBundleType nbt : nbts) { res.add(nbt.getCommand()); } return res.toArray(new String[res.size()]); }
Example 5
Source File: SessionConversationAttributeStore.java From website with GNU Affero General Public License v3.0 | 5 votes |
/** * @param request * @param queue * @param attributeName */ private void pruneQueueIfNeeded(WebRequest request, Queue<String> queue, String attributeName) { // now check to see if we have hit the limit of conversations for the // command name. if (queue.size() > getNumConversationsToKeep()) { if (_logger.isDebugEnabled()) { for (Object str : queue.toArray()) { _logger.debug("pruneQueueIfNeeded - (" + attributeName + ") queue entry (" + str + " " + new java.util.Date(Long.parseLong((String)str))); } } // grab the next item to be removed. String conversationId = queue.peek(); if (conversationId != null) { _logger.debug("pruneQueueIfNeeded - (" + attributeName + ") removed (" + conversationId + " " + new java.util.Date( Long.parseLong(conversationId))); // remove the reference object from the session. removeEntityFromSession(request, attributeName, conversationId); } } }
Example 6
Source File: ExceptionCollector.java From vibur-dbcp with Apache License 2.0 | 5 votes |
/** * Returns an array of all SQL exceptions collected by {@link #addException}. This method will be * called when a pooled Connection is closed, in order to determine whether the underlying (raw) * JDBC Connection also needs to be closed. */ final SQLException[] getExceptions() { Queue<SQLException> ex = exceptions; if (ex == null) { return NO_EXCEPTIONS; } return ex.toArray(NO_EXCEPTIONS); }
Example 7
Source File: ConcurrentEvictingQueueGeneralTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void toPreAllocatedArray() throws Exception { Queue<Integer> queue = new ConcurrentEvictingQueue<>(5); Integer[] emptyArray = queue.toArray(new Integer[]{}); assertThat(emptyArray.length).isEqualTo(0); queue.add(1); assertThat(queue.toArray()).containsExactly(1); queue.clear(); queue.addAll(asList(1, 2, 3, 4, 5)); Integer[] first = new Integer[5]; queue.toArray(first); assertThat(first).containsExactly(1, 2, 3, 4, 5); Integer[] second = new Integer[7]; queue.toArray(second); assertThat(second).containsExactly(1, 2, 3, 4, 5, null, null); Integer[] third = new Integer[2]; Integer[] thirdResult = queue.toArray(third); assertThat(third).containsExactly(null, null); assertThat(thirdResult).containsExactly(1, 2, 3, 4, 5); queue.clear(); assertThat(queue).isEmpty(); queue.addAll(asList(1, 2, 3, 4, 5, 6, 7, 8, 9)); Integer[] fourth = {11, 22, 33, 44, 55, 66, 77, 88}; assertThat(queue.toArray(fourth)).containsExactly(5, 6, 7, 8, 9, 66, 77, 88); queue.clear(); assertThat(queue).isEmpty(); }
Example 8
Source File: QueuesOneQueueTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void oneQueueWithOneElementShouldConvertToArrayAndPutNullMarkerAndReuseInputArrayWhenPassedLargerArray() { Queue<Integer> q = oneQueueWithTestElement(TEST_ELEMENT); //and Integer[] passedArray = {1, 2, 3}; //given Integer[] convertedArray = q.toArray(passedArray); //then assertThat(convertedArray) .hasSize(3) .startsWith(TEST_ELEMENT, null, 3) .isSameAs(passedArray); }
Example 9
Source File: QueuesOneQueueTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void emptyOneQueueShouldConvertToArrayAndPutNullMarkerAndReuseInputArrayWhenPassedLargerArray() { //given Queue<Integer> q = emptyOneQueue(); //and Integer[] passedArray = {1, 2, 3}; //when Integer[] convertedArray = q.toArray(passedArray); //then assertThat(convertedArray) .hasSize(3) .startsWith(null, 2, 3) .isSameAs(passedArray); }
Example 10
Source File: QueuesOneQueueTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void oneQueueWithOneElementShouldConvertToArrayAndReuseInputArrayWhenPassedOneLengthArray() { Queue<Integer> q = oneQueueWithTestElement(TEST_ELEMENT); //and Integer[] passedArray = new Integer[1]; //when Integer[] convertedArray = q.toArray(passedArray); //then assertThat(convertedArray) .containsExactly(TEST_ELEMENT) .isSameAs(passedArray); }
Example 11
Source File: QueuesOneQueueTest.java From reactor-core with Apache License 2.0 | 5 votes |
@Test public void emptyOneQueueShouldConvertToArrayAndPutNullMarkerAndReuseInputArrayOnWhenPassedOneLengthArray() { Queue<Integer> q = emptyOneQueue(); //and Integer[] passedArray = new Integer[1]; //when Integer[] convertedArray = q.toArray(passedArray); //then assertThat(convertedArray) .containsExactly((Integer)null) .isSameAs(passedArray); }
Example 12
Source File: CircularBufferTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void resizeOnce(int capacity) { int nextNumberToPut = 0; Queue<Integer> referenceQueue = new ArrayBlockingQueue<>(capacity); CircularBuffer<Integer> buffer = new CircularBuffer<>(capacity); // Fill full, so the next add will wrap for (int i = 0; i < capacity; i++, nextNumberToPut++) { buffer.add(nextNumberToPut); referenceQueue.add(nextNumberToPut); } int gets = r.nextInt(capacity); // [0, capacity) for (int i = 0; i < gets; i++) { referenceQueue.poll(); buffer.remove(); } int puts = r.nextInt(gets + 1); // [0, gets] for (int i = 0; i < puts; i++, nextNumberToPut++) { buffer.add(nextNumberToPut); referenceQueue.add(nextNumberToPut); } Integer[] expected = referenceQueue.toArray(new Integer[0]); buffer.resize(expected.length); assertEquals(buffer.elements, expected); }
Example 13
Source File: WhiteBox.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void checkIterationSanity(Queue q) { if (rnd.nextBoolean()) return; int size = q.size(); Object[] a = q.toArray(); Object[] b = new Object[size+2]; Arrays.fill(b, Boolean.TRUE); Object[] c = q.toArray(b); assertEquals(a.length, size); assertSame(b, c); assertNull(b[size]); assertSame(b[size+1], Boolean.TRUE); assertEquals(q.toString(), Arrays.toString(a)); Integer[] xx = null, yy = null; if (size > 0) { xx = new Integer[size - 1]; Arrays.fill(xx, 42); yy = ((Queue<Integer>)q).toArray(xx); for (Integer zz : xx) assertEquals(42, (int) zz); } Iterator it = q.iterator(); for (int i = 0; i < size; i++) { if (rnd.nextBoolean()) assertTrue(it.hasNext()); Object x = it.next(); assertSame(x, a[i]); assertSame(x, b[i]); if (xx != null) assertSame(x, yy[i]); } if (rnd.nextBoolean()) assertTrue(!it.hasNext()); }
Example 14
Source File: GhidraFileChooserTest.java From ghidra with Apache License 2.0 | 5 votes |
private String getChooserJob() { Worker worker = (Worker) getInstanceField("worker", chooser); ConcurrentQ<?, ?> cq = (ConcurrentQ<?, ?>) getInstanceField("concurrentQ", worker); Queue<?> q = (Queue<?>) getInstanceField("queue", cq); Object[] jobs = q.toArray(); return Arrays.toString(jobs); }
Example 15
Source File: SingleConsumerQueueTest.java From caffeine with Apache License 2.0 | 4 votes |
@Test(dataProvider = "empty,singleton,populated") public void toArray(Queue<Integer> queue) { Object[] expect = new ArrayList<>(queue).toArray(); Object[] actual = queue.toArray(); assertThat(actual, queue.isEmpty() ? emptyArray() : arrayContaining(expect)); }
Example 16
Source File: SingleConsumerQueueTest.java From caffeine with Apache License 2.0 | 4 votes |
@Test(dataProvider = "empty,singleton,populated") public void toTypedArray(Queue<Integer> queue) { Integer[] expect = new ArrayList<>(queue).toArray(new Integer[] {}); Integer[] actual = queue.toArray(new Integer[] {}); assertThat(actual, queue.isEmpty() ? emptyArray() : arrayContaining(expect)); }
Example 17
Source File: OpensteckTelemetryViewMessageHandler.java From onos with Apache License 2.0 | 4 votes |
private FlowInfo getLatestFlowInfo(Queue<FlowInfo> flowInfoQ) { FlowInfo[] flowInfos = flowInfoQ.toArray(new FlowInfo[flowInfoQ.size()]); return flowInfos[flowInfos.length - 1]; }