Java Code Examples for java.util.Deque#toArray()
The following examples show how to use
java.util.Deque#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: InternalSpelExpressionParser.java From spring-analysis-note with MIT License | 6 votes |
/** * Eat an identifier, possibly qualified (meaning that it is dotted). * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { Deque<SpelNodeImpl> qualifiedIdPieces = new ArrayDeque<>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); if (node.kind != TokenKind.DOT) { qualifiedIdPieces.add(new Identifier(node.stringValue(), node.startPos, node.endPos)); } node = peekToken(); } if (qualifiedIdPieces.isEmpty()) { if (node == null) { throw internalException( this.expressionString.length(), SpelMessage.OOD); } throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase()); } return new QualifiedIdentifier(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition(), qualifiedIdPieces.toArray(new SpelNodeImpl[0])); }
Example 2
Source File: InternalSpelExpressionParser.java From java-technology-stack with MIT License | 6 votes |
/** * Eat an identifier, possibly qualified (meaning that it is dotted). * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { Deque<SpelNodeImpl> qualifiedIdPieces = new ArrayDeque<>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); if (node.kind != TokenKind.DOT) { qualifiedIdPieces.add(new Identifier(node.stringValue(), toPos(node))); } node = peekToken(); } if (qualifiedIdPieces.isEmpty()) { if (node == null) { throw internalException( this.expressionString.length(), SpelMessage.OOD); } throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase()); } int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition()); return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[0])); }
Example 3
Source File: NullAwayNativeModels.java From NullAway with MIT License | 6 votes |
static void dequeStuff() { Deque<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); }
Example 4
Source File: DebugCommand.java From linstor-server with GNU General Public License v3.0 | 5 votes |
private String[] toLinesArray(byte[] text) { Deque<String> debugOutLines = new LinkedList<>(); int offset = 0; for (int idx = 0; idx < text.length; ++idx) { if (text[idx] == '\n') { debugOutLines.add(new String(text, offset, idx - offset)); offset = idx + 1; } } String[] strArray = new String[debugOutLines.size()]; return debugOutLines.toArray(strArray); }
Example 5
Source File: ClassLoaderSupport.java From netbeans with Apache License 2.0 | 5 votes |
@NonNull private static URL[] getRootURLs(@NonNull final ClassPath cp) { final List<ClassPath.Entry> entries = cp.entries(); final Deque<URL> res = new ArrayDeque<>(entries.size()); for (ClassPath.Entry e : entries) { res.offer(e.getURL()); } return res.toArray(new URL[res.size()]); }
Example 6
Source File: ToolBox.java From privacy-friendly-netmonitor with GNU General Public License v3.0 | 5 votes |
public static int searchByteArray(byte[] input, byte[] searchedFor) { //convert byte[] to Byte[] Byte[] searchedForB = new Byte[searchedFor.length]; for (int x = 0; x < searchedFor.length; x++) { searchedForB[x] = searchedFor[x]; } int idx = -1; //search: Deque<Byte> q = new ArrayDeque<>(input.length); for (int i = 0; i < input.length; i++) { if (q.size() == searchedForB.length) { //here I can check Byte[] cur = q.toArray(new Byte[]{}); if (Arrays.equals(cur, searchedForB)) { //found! idx = i - searchedForB.length; break; } else { //not found q.pop(); q.addLast(input[i]); } } else { q.addLast(input[i]); } } if (Const.IS_DEBUG && idx != -1) Log.d(Const.LOG_TAG, ToolBox.printHexBinary(searchedFor) + " found at position " + idx); return idx; }
Example 7
Source File: CheckedConfig.java From night-config with GNU Lesser General Public License v3.0 | 5 votes |
private void recursiveCheck(Deque<String> path, Object value) { if (value instanceof Config) { for (Config.Entry entry : ((Config)value).entries()) { path.addLast(entry.getKey()); recursiveCheck(path, entry.getValue()); path.removeLast(); } } else { String[] arr = (String[])path.toArray(); checker.checkUpdate(StandardAttributes.VALUE, arr, value, value); } }
Example 8
Source File: ObjectTrees.java From JglTF with MIT License | 5 votes |
/** * Create a <code>TreePath</code> by going up from the given node until * the root node is reached * * @param node The node * @return The tree path */ static TreePath createPath(TreeNode node) { Deque<TreeNode> list = new LinkedList<TreeNode>(); TreeNode current = node; while (current != null) { list.addFirst(current); current = current.getParent(); } return new TreePath(list.toArray(new TreeNode[0])); }
Example 9
Source File: PathFromRoot.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private QName @NonNull [] loadQNames() { final Deque<QName> tmp = new ArrayDeque<>(); for (QName qname : path.getPathTowardsRoot()) { tmp.addFirst(qname); } final QName[] result = tmp.toArray(EMPTY_QNAMES); // We do not care about atomicity here QNAMES.setRelease(this, result); return result; }
Example 10
Source File: OfdpaGroupHandlerUtility.java From onos with Apache License 2.0 | 5 votes |
/** * Returns a list of all indices in the allActiveKeys list (that represents * a group) if the list element (a bucket or group-chain) has treatments * that match the given outport and label. * * @param allActiveKeys the representation of the group * @param groupService groups service for querying group information * @param deviceId the device id for the device that contains the group * @param portToMatch the port to match in the group buckets * @param labelToMatch the MPLS label-id to match in the group buckets * @return a list of indexes in the allActiveKeys list where the list element * has treatments that match the given portToMatch and labelToMatch. * Could be empty if no list elements were found to match the given * port and label. */ public static List<Integer> existingPortAndLabel( List<Deque<GroupKey>> allActiveKeys, GroupService groupService, DeviceId deviceId, PortNumber portToMatch, int labelToMatch) { List<Integer> indices = new ArrayList<>(); int index = 0; for (Deque<GroupKey> keyChain : allActiveKeys) { GroupKey ifaceGroupKey = keyChain.peekLast(); Group ifaceGroup = groupService.getGroup(deviceId, ifaceGroupKey); if (ifaceGroup != null && !ifaceGroup.buckets().buckets().isEmpty()) { PortNumber portNumber = readOutPortFromTreatment( ifaceGroup.buckets().buckets().iterator().next().treatment()); if (portNumber != null && portNumber.equals(portToMatch)) { // check for label in the 2nd group of this chain GroupKey secondKey = (GroupKey) keyChain.toArray()[1]; Group secondGroup = groupService.getGroup(deviceId, secondKey); if (secondGroup != null && !secondGroup.buckets().buckets().isEmpty()) { int label = readLabelFromTreatment( secondGroup.buckets().buckets() .iterator().next().treatment()); if (label == labelToMatch) { indices.add(index); } } } } index++; } return indices; }
Example 11
Source File: ConfigSpec.java From night-config with GNU Lesser General Public License v3.0 | 4 votes |
private static void correct(Config spec, Config target, Deque<String> pathStack, CorrectionListener listener, boolean rmUnspecEntries, boolean rmUnspecAttr) { // First step: remove the unspecified entries, if keepUnspecifiedEntries is false if (rmUnspecEntries) { removeUnspecified(spec, target); } // Second step: fix the incorrect entries and add the missing ones for (Entry specEntry : spec.entries()) { final String specKey = specEntry.getKey(); final Object specValue = specEntry.getValue(); final String[] localPath = single(specKey); final String[] fullPath = pathStack.toArray(single(null)); // provision 1 slot final Config.Entry actual = target.getEntry(localPath); pathStack.addLast(specKey); Config subTarget = null; if (actual == null) { // Missing entry subTarget = correctMissing(target, specValue, listener, localPath, fullPath); } else if (specValue instanceof Config && !(actual.getValue() instanceof Config)) { // Incompatible entry: expected a configuration subTarget = correctIncompatible(target, actual, listener, fullPath); } else { // Expected entry, let's check all its attributes (including its value) Iterator<? extends Attribute<?>> it = actual.attributes().iterator(); while (it.hasNext()) { Attribute<?> entry = it.next(); correctAttribute(it, specEntry, entry, listener, fullPath, rmUnspecAttr); } } // Correct recursively if (subTarget != null) { Config subSpec = (Config)specValue; correct(subSpec, subTarget, pathStack, listener, rmUnspecEntries, rmUnspecAttr); } pathStack.removeLast(); } }
Example 12
Source File: OfdpaGroupHandlerUtility.java From onos with Apache License 2.0 | 4 votes |
/** * Get indices to remove comparing next group with next objective. * * @param allActiveKeys the representation of the group * @param nextObjective the next objective to verify * @param groupService groups service for querying group information * @param deviceId the device id for the device that contains the group * @return a list of indexes in the allActiveKeys to remove. */ public static List<Integer> indicesToRemoveFromNextGroup(List<Deque<GroupKey>> allActiveKeys, NextObjective nextObjective, GroupService groupService, DeviceId deviceId) { List<Integer> indicesToRemove = Lists.newArrayList(); int index = 0; // Iterate over the chain in the next data for (Deque<GroupKey> keyChain : allActiveKeys) { // Valid chain should have at least two elements if (keyChain.size() >= 2) { // Get last group (l2if) and retrieve port number GroupKey ifaceGroupKey = keyChain.peekLast(); Group ifaceGroup = groupService.getGroup(deviceId, ifaceGroupKey); if (ifaceGroup != null && !ifaceGroup.buckets().buckets().isEmpty()) { PortNumber portNumber = readOutPortFromTreatment( ifaceGroup.buckets().buckets().iterator().next().treatment()); // If there is not a port number continue if (portNumber != null) { // check for label in the 2nd group of this chain GroupKey secondKey = (GroupKey) keyChain.toArray()[1]; Group secondGroup = groupService.getGroup(deviceId, secondKey); // If there is not a second group or there are no buckets continue if (secondGroup != null && !secondGroup.buckets().buckets().isEmpty()) { // Get label or -1 int label = readLabelFromTreatment( secondGroup.buckets().buckets() .iterator().next().treatment()); // Iterate over the next treatments looking for the port and the label boolean matches = false; for (TrafficTreatment t : nextObjective.next()) { PortNumber tPort = readOutPortFromTreatment(t); int tLabel = readLabelFromTreatment(t); if (tPort != null && tPort.equals(portNumber) && tLabel == label) { // We found it, exit matches = true; break; } } // Not found, we have to remove it if (!matches) { indicesToRemove.add(index); } } } } } index++; } return indicesToRemove; }