Java Code Examples for java.util.ArrayDeque#toArray()
The following examples show how to use
java.util.ArrayDeque#toArray() .
These examples are extracted from open source projects.
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 Project: PoseidonX File: GroupView.java License: Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private IEvent[] convertToArray(Object eventOrDeque) { if (eventOrDeque == null) { return null; } if (eventOrDeque instanceof IEvent) { return new IEvent[] {(IEvent)eventOrDeque}; } ArrayDeque<IEvent> deque = (ArrayDeque<IEvent>)eventOrDeque; return deque.toArray(new IEvent[deque.size()]); }
Example 2
Source Project: NullAway File: NullAwayNativeModels.java License: MIT License | 6 votes |
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); Object[] o = null; // BUG: Diagnostic contains: passing @Nullable parameter 'o' where @NonNull is required d.toArray(o); // this should be fine d.toArray(); }
Example 3
Source Project: tigase-extension File: ClientStateIndicationTest.java License: GNU General Public License v3.0 | 6 votes |
@Test public void testMessagesToInactive() throws XMPPException, TigaseStringprepException { String recipient = "[email protected]"; JID recp1 = JID.jidInstanceNS(recipient + "/res1"); JID connId1 = JID.jidInstanceNS("[email protected]/recipient1-res1"); XMPPResourceConnection session1 = getSession(connId1, recp1); enableCSI(session1); ArrayDeque<Packet> results = new ArrayDeque<>(); Packet p = Packet.packetInstance("message", "[email protected]/res1", recp1.toString(), StanzaType.chat); p.setPacketTo(connId1); results.offer(p); Packet[] expected = results.toArray(new Packet[results.size()]); csi.filter(p, session1, null, results); Packet[] processed = results.toArray(new Packet[results.size()]); Assert.assertArrayEquals(expected, processed); }
Example 4
Source Project: tigase-extension File: ClientStateIndicationTest.java License: GNU General Public License v3.0 | 6 votes |
@Test public void testPresenceToInactive() throws XMPPException, TigaseStringprepException { String recipient = "[email protected]"; JID recp1 = JID.jidInstanceNS(recipient + "/res1"); JID connId1 = JID.jidInstanceNS("[email protected]lhost/recipient1-res1"); XMPPResourceConnection session1 = getSession(connId1, recp1); enableCSI(session1); ArrayDeque<Packet> results = new ArrayDeque<>(); Packet p = Packet.packetInstance("presence", "[email protected]/res1", recp1.toString(), StanzaType.available); p.setPacketTo(connId1); results.offer(p); Packet[] expected = new Packet[0]; csi.filter(p, session1, null, results); Packet[] processed = results.toArray(new Packet[results.size()]); Assert.assertArrayEquals(expected, processed); }
Example 5
Source Project: trufflesqueak File: ObjectGraphUtils.java License: MIT License | 5 votes |
@TruffleBoundary public static Object[] allInstancesOf(final SqueakImageContext image, final ClassObject classObj) { final ArrayDeque<AbstractSqueakObjectWithHash> result = new ArrayDeque<>(); final ObjectTracer pending = new ObjectTracer(image); AbstractSqueakObjectWithHash currentObject; while ((currentObject = pending.getNextPending()) != null) { if (currentObject.tryToMark(pending.getCurrentMarkingFlag())) { if (classObj == currentObject.getSqueakClass()) { result.add(currentObject); } pending.tracePointers(currentObject); } } return result.toArray(); }
Example 6
Source Project: openjdk-jdk9 File: ArrayDequeTest.java License: GNU General Public License v2.0 | 5 votes |
/** * toArray(null) throws NullPointerException */ public void testToArray_NullArg() { ArrayDeque l = new ArrayDeque(); l.add(new Object()); try { l.toArray(null); shouldThrow(); } catch (NullPointerException success) {} }
Example 7
Source Project: j2objc File: ArrayDequeTest.java License: Apache License 2.0 | 5 votes |
void checkToArray(ArrayDeque q) { int size = q.size(); Object[] o = q.toArray(); assertEquals(size, o.length); Iterator it = q.iterator(); for (int i = 0; i < size; i++) { Integer x = (Integer) it.next(); assertEquals((Integer)o[0] + i, (int) x); assertSame(o[i], x); } }
Example 8
Source Project: j2objc File: ArrayDequeTest.java License: Apache License 2.0 | 5 votes |
void checkToArray2(ArrayDeque q) { int size = q.size(); Integer[] a1 = (size == 0) ? null : new Integer[size - 1]; Integer[] a2 = new Integer[size]; Integer[] a3 = new Integer[size + 2]; if (size > 0) Arrays.fill(a1, 42); Arrays.fill(a2, 42); Arrays.fill(a3, 42); Integer[] b1 = (size == 0) ? null : (Integer[]) q.toArray(a1); Integer[] b2 = (Integer[]) q.toArray(a2); Integer[] b3 = (Integer[]) q.toArray(a3); assertSame(a2, b2); assertSame(a3, b3); Iterator it = q.iterator(); for (int i = 0; i < size; i++) { Integer x = (Integer) it.next(); assertSame(b1[i], x); assertEquals(b1[0] + i, (int) x); assertSame(b2[i], x); assertSame(b3[i], x); } assertNull(a3[size]); assertEquals(42, (int) a3[size + 1]); if (size > 0) { assertNotSame(a1, b1); assertEquals(size, b1.length); for (int i = 0; i < a1.length; i++) { assertEquals(42, (int) a1[i]); } } }
Example 9
Source Project: j2objc File: ArrayDequeTest.java License: Apache License 2.0 | 5 votes |
/** * toArray(null) throws NullPointerException */ public void testToArray_NullArg() { ArrayDeque l = new ArrayDeque(); l.add(new Object()); try { l.toArray(null); shouldThrow(); } catch (NullPointerException success) {} }
Example 10
Source Project: j2objc File: ArrayDequeTest.java License: Apache License 2.0 | 5 votes |
/** * toArray(incompatible array type) throws ArrayStoreException */ public void testToArray1_BadArg() { ArrayDeque l = new ArrayDeque(); l.add(new Integer(5)); try { l.toArray(new String[10]); shouldThrow(); } catch (ArrayStoreException success) {} }
Example 11
Source Project: querqy File: WordBreakCompoundRewriter.java License: Apache License 2.0 | 5 votes |
private void addCompounds(final ArrayDeque<Term> terms, final boolean reverse) throws IOException { final CombineSuggestion[] combinations = suggestCombination(reverse ? terms.descendingIterator() : terms.iterator()); if (combinations != null && combinations.length > 0) { final Term[] termArray; if (reverse) { termArray = new Term[terms.size()]; int i = terms.size() - 1; final Iterator<Term> termIterator = terms.descendingIterator(); while (termIterator.hasNext()) { termArray[i--] = termIterator.next(); } } else { termArray = terms.toArray(new Term[0]); } for (final CombineSuggestion suggestion : combinations) { // add compound to each sibling that is part of the compound to maintain mm logic Arrays.stream(suggestion.originalTermIndexes) .mapToObj(idx -> termArray[idx]) .forEach(sibling -> nodesToAdd.add( new Term(sibling.getParent(), sibling.getField(), suggestion.suggestion.string, true))); } } }
Example 12
Source Project: tigase-extension File: ClientStateIndicationTest.java License: GNU General Public License v3.0 | 5 votes |
@Test public void testFlushStopping() throws XMPPException, TigaseStringprepException { String recipient = "[email protected]"; JID recp1 = JID.jidInstanceNS(recipient + "/res1"); JID connId1 = JID.jidInstanceNS("[email protected]/recipient1-res1"); XMPPResourceConnection session1 = getSession(connId1, recp1); enableCSI(session1); ArrayDeque<Packet> results = new ArrayDeque<>(); Packet p = Packet.packetInstance("presence", "[email protected]/res1", recp1.toString(), StanzaType.available); p.setPacketTo(connId1); csi.filter(p, session1, null, results); results.clear(); Packet m = Packet.packetInstance("message", "[email protected]/res1", recp1.toString(), StanzaType.chat); m.getElement().addChild(new Element("received", new String[]{ "xmlns" }, new String[] { "urn:xmpp:receipts" })); m.setPacketTo(connId1); results.offer(m); csi.filter(m, session1, null, results); results.clear(); results.offer(m); results.clear(); csi.stopped(session1, results, new HashMap<>()); Packet[] processed = results.toArray(new Packet[results.size()]); Assert.assertEquals(0, processed.length); }
Example 13
Source Project: cloudhopper-commons File: ClassUtil.java License: Apache License 2.0 | 5 votes |
/** * Returns an array of class objects representing the entire class hierarchy * with the most-super class as the first element followed by all subclasses * in the order they are declared. This method does not include the generic * Object type in its list. If this class represents the Object type, this * method will return a zero-size array. */ public static Class<?>[] getClassHierarchy(Class<?> type) { ArrayDeque<Class<?>> classes = new ArrayDeque<Class<?>>(); // class to start our search from, we'll loop thru the entire class hierarchy Class<?> classType = type; // keep searching up until we reach an Object class type while (classType != null && !classType.equals(Object.class)) { // keep adding onto front classes.addFirst(classType); classType = classType.getSuperclass(); } return classes.toArray(new Class[0]); }
Example 14
Source Project: jlibs File: XPathParser.java License: Apache License 2.0 | 4 votes |
@SuppressWarnings({"unchecked"}) private void endLocationPath(int scope, ArrayDeque steps){ LocationPath path = new LocationPath(scope, steps.size()); steps.toArray(path.steps); push(LocationPathAnalyzer.simplify(path)); }
Example 15
Source Project: consulo File: FileTreeModel.java License: Apache License 2.0 | 4 votes |
private Object getUniqueID(TreePath path, Node node, ArrayDeque<? super String> deque) { deque.addFirst(node.getName()); Object object = path.getLastPathComponent(); TreePath parent = path.getParentPath(); return parent != null && object instanceof Node ? getUniqueID(parent, (Node)object, deque) : parent != null || object != state ? null : deque.toArray(); }