Java Code Examples for java.util.Deque#remove()
The following examples show how to use
java.util.Deque#remove() .
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: Solution.java From daily-coding-problems with Apache License 2.0 | 6 votes |
List<String> getTransformation(String from, String to) { Deque<List<String>> queue = new ArrayDeque<>(); Set<String> searched = new HashSet<>(); List<String> path = new ArrayList<>(); path.add(from); queue.offer(path); while (!queue.isEmpty()) { List<String> current = queue.remove(); String currentWord = current.get(current.size() - 1); if (currentWord.equals(to)) { return current; } List<String> transforms = graph.get(currentWord); for (String transform : transforms) { if (!current.contains(transform) && !searched.contains(transform)) { List<String> newPath = new ArrayList<>(current); newPath.add(transform); searched.add(transform); queue.offer(newPath); } } } return null; }
Example 2
Source File: Structurizer.java From immutables with Apache License 2.0 | 6 votes |
private static List<Term> parseReturnType(List<Term> signature) { if (signature.isEmpty()) { return ImmutableList.of(); } Deque<Term> terms = new ArrayDeque<>(signature); Term last = terms.removeLast(); if (!last.isWordOrNumber() || last.is("static")) { return ImmutableList.of(); } while (!terms.isEmpty()) { Term t = terms.peek(); if (t.is("<")) { removeTillMatching(terms, "<", ">"); } else if (modifiers.contains(t.toString())) { terms.remove(); } else { // it is possible that there are // no whitespace or comments already removeCommentsAndWhitespace(terms); return ImmutableList.copyOf(terms); } } return ImmutableList.of(); }
Example 3
Source File: FeatureManager.java From anomaly-detection with Apache License 2.0 | 6 votes |
private void updateUnprocessedFeatures( Optional<double[]> point, Deque<Entry<Long, double[]>> shingle, AnomalyDetector detector, long endTime, ActionListener<SinglePointFeatures> listener ) { if (point.isPresent()) { if (shingle.size() == shingleSize) { shingle.remove(); } shingle.add(new SimpleImmutableEntry<>(endTime, point.get())); getProcessedFeatures(shingle, detector, endTime, listener); } else { listener.onResponse(new SinglePointFeatures(Optional.empty(), Optional.empty())); } }
Example 4
Source File: Help.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void execute(Deque<String> options) throws UserSyntaxException, UserDataException { if (options.isEmpty()) { Command.displayHelp(); return; } ensureMaxArgumentCount(options, 1); String commandName = options.remove(); Command c = Command.valueOf(commandName); if (c == null) { throw new UserDataException("unknown command '" + commandName + "'"); } println(c.getTitle()); println(); c.displayUsage(System.out); }
Example 5
Source File: AbstractScriptRunner.java From sailfish-core with Apache License 2.0 | 5 votes |
private boolean tryToForceExecution(long id, List<Long> passive, Deque<Long> active) { if (passive.remove(id) || active.remove(id)) { active.addFirst(id); logger.info("Script {} moved to active queue", id); return true; } return false; }
Example 6
Source File: Types.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Traverse ancestors of the given type, in the same order as {@link #ancestors(Class, boolean)}, * applying the given function to each ancestor, and return the first non-null result, or null * if the function returns null for all ancestors. */ public static @Nullable <T, R> R findForAncestor(Class<T> type, Function<Class<? super T>, R> func) { Deque<Class<? super T>> queue = new ArrayDeque<>(); queue.add(type); while(!queue.isEmpty()) { final Class<? super T> t = queue.remove(); final R result = func.apply(t); if(result != null) return result; if(t.getSuperclass() != null) queue.add(t.getSuperclass()); Collections.addAll(queue, (Class<? super T>[]) t.getInterfaces()); } return null; }
Example 7
Source File: TimeoutsHealthIndicator.java From super-cloudops with Apache License 2.0 | 5 votes |
/** * Post process. * * @param wrap */ private void postPropertiesReset(TimesWrapper wrap) { Deque<Long> deque = this.records.get(wrap.getMetricsName()); if (deque != null && !deque.isEmpty()) { deque.remove(wrap.getMax()); } }
Example 8
Source File: Dispatcher.java From styT with Apache License 2.0 | 5 votes |
private <T> void finished(Deque<T> calls, T call, boolean promoteCalls) { int runningCallsCount; Runnable idleCallback; synchronized (this) { if (!calls.remove(call)) throw new AssertionError("Call wasn't in-flight!"); if (promoteCalls) promoteCalls(); runningCallsCount = runningCallsCount(); idleCallback = this.idleCallback; } if (runningCallsCount == 0 && idleCallback != null) { idleCallback.run(); } }
Example 9
Source File: AbstractNavigationStateRenderer.java From flow with Apache License 2.0 | 5 votes |
/** * Inform any {@link BeforeLeaveObserver}s in detaching element chain. * * @param beforeNavigation * navigation event sent to observers * @return result of observer events */ private Optional<Integer> executeBeforeLeaveNavigation( NavigationEvent event, BeforeLeaveEvent beforeNavigation) { Deque<BeforeLeaveHandler> leaveHandlers = getBeforeLeaveHandlers( beforeNavigation.getUI()); while (!leaveHandlers.isEmpty()) { BeforeLeaveHandler listener = leaveHandlers.remove(); listener.beforeLeave(beforeNavigation); validateBeforeEvent(beforeNavigation); Optional<Integer> result = handleTriggeredBeforeEvent(event, beforeNavigation); if (result.isPresent()) { return result; } if (beforeNavigation.isPostponed()) { postponed = Postpone.withLeaveObservers(leaveHandlers); ContinueNavigationAction currentAction = beforeNavigation .getContinueNavigationAction(); currentAction.setReferences(this, event); storeContinueNavigationAction(event.getUI(), currentAction); return Optional.of(HttpServletResponse.SC_OK); } } return Optional.empty(); }
Example 10
Source File: HistoryTreeClassic.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public HTNode readNode(Deque<Integer> queue) throws ClosedChannelException { /* Try to read the node from memory */ synchronized (fLatestBranch) { for (HTNode node : fLatestBranch) { if (queue.remove(node.getSequenceNumber())) { return node; } } } /* Read the node from disk */ return fTreeIO.readNode(queue); }
Example 11
Source File: Dispatcher.java From AndroidProjects with MIT License | 5 votes |
private <T> void finished(Deque<T> calls, T call, boolean promoteCalls) { int runningCallsCount; Runnable idleCallback; synchronized (this) { if (!calls.remove(call)) throw new AssertionError("Call wasn't in-flight!"); if (promoteCalls) promoteCalls(); runningCallsCount = runningCallsCount(); idleCallback = this.idleCallback; } if (runningCallsCount == 0 && idleCallback != null) { idleCallback.run(); } }
Example 12
Source File: Execute.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String... args) { Deque<String> argList = new LinkedList<>(Arrays.asList(args)); if (argList.isEmpty()) { System.out.println(); Command.displayHelp(); return; } String command = argList.remove(); for (Command c : Command.getCommands()) { if (c.getName().equals(command)) { try { c.execute(argList); } catch (IllegalArgumentException iae) { return; // already handled by command } catch (Throwable e) { System.out.println(); System.out.println(e.getMessage()); System.out.println(); } return; } } System.out.println(); System.out.println("Unknown command " + command + "."); System.out.println(); Command.displayHelp(); }
Example 13
Source File: Command.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
protected boolean acceptOption(Deque<String> options, String expected) throws UserSyntaxException { if (expected.equals(options.peek())) { if (options.size() < 2) { throw new UserSyntaxException("missing value for " + options.peek()); } options.remove(); return true; } return false; }
Example 14
Source File: EasikSettings.java From CQL with GNU Affero General Public License v3.0 | 5 votes |
/** * Adds the specified filename to the list of recent files. In addition to * adding the file to the file set, the file will be brought to the beginning of * the set (and removed first, if it already exists), and the set will be * trimmed to only contain 8 elements. * <p/> * You probably want to call updateRecentFilesMenu() on the main * ApplicationFrame to update the recent files list after calling this. * * @param filename recent file */ public void addRecentFile(final String filename) { final Deque<String> recent = (LinkedList<String>) getPropertyList("recent_files"); recent.remove(filename); recent.addFirst(filename); while (recent.size() > MAX_NUM_FILES) { recent.removeLast(); } setProperty("recent_files", recent); }
Example 15
Source File: Solution.java From daily-coding-problems with Apache License 2.0 | 5 votes |
String reverseWordsWithDelimiters(String sentence, Set<Character> delimiters) { if (sentence == null || sentence.isEmpty()) { return sentence; } Deque<String> stack = new ArrayDeque<>(); Deque<Character> queue = new ArrayDeque<>(); int start = -1; int end = -1; for (int index = 0; index < sentence.length(); index++) { if (delimiters.contains(sentence.charAt(index))) { queue.offer(sentence.charAt(index)); end = index - 1; if (start >= 0 && start < sentence.length() && end < sentence.length()) { stack.push(sentence.substring(start, index)); } start = index + 1; } else { if (start == -1) { start = index; } } } if (start >= 0 && start < sentence.length()) { stack.push(sentence.substring(start)); } String result = ""; while (!stack.isEmpty()) { String delimiter = ""; if (!queue.isEmpty()) { delimiter = queue.remove() + ""; } result += stack.pop() + delimiter; } return result; }
Example 16
Source File: Main.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String... args) { Deque<String> argList = new LinkedList<>(Arrays.asList(args)); if (argList.isEmpty()) { System.out.println(Command.title); System.out.println(); System.out.println("Before using this tool, you must have a recording file."); System.out.println("A file can be created by starting a recording from command line:"); System.out.println(); System.out.println(" java -XX:StartFlightRecording:filename=recording.jfr,duration=30s ... "); System.out.println(); System.out.println("A recording can also be started on already running Java Virtual Machine:"); System.out.println(); System.out.println(" jcmd (to list available pids)"); System.out.println(" jcmd <pid> JFR.start"); System.out.println(); System.out.println("Recording data can be dumped to file using the JFR.dump command:"); System.out.println(); System.out.println(" jcmd <pid> JFR.dump filename=recording.jfr"); System.out.println(); System.out.println("The contents of the recording can then be printed, for example:"); System.out.println(); System.out.println(" jfr print recording.jfr"); System.out.println(); System.out.println(" jfr print --events CPULoad,GarbageCollection recording.jfr"); System.out.println(); System.out.println(" jfr print --json --events CPULoad recording.jfr"); System.out.println(); System.out.println(" jfr print --categories \"GC,JVM,Java*\" recording.jfr"); System.out.println(); System.out.println(" jfr print --events \"jdk.*\" --stack-depth 64 recording.jfr"); System.out.println(); System.out.println(" jfr summary recording.jfr"); System.out.println(); System.out.println(" jfr metadata recording.jfr"); System.out.println(); System.out.println("For more information about available commands, use 'jfr help'"); System.exit(EXIT_OK); } String command = argList.remove(); for (Command c : Command.getCommands()) { if (c.matches(command)) { try { c.execute(argList); System.exit(EXIT_OK); } catch (UserDataException ude) { System.err.println("jfr " + c.getName() + ": " + ude.getMessage()); System.exit(EXIT_FAILED); } catch (UserSyntaxException use) { System.err.println("jfr " + c.getName() + ": " + use.getMessage()); System.err.println(); System.err.println("Usage:"); System.err.println(); c.displayUsage(System.err); System.exit(EXIT_WRONG_ARGUMENTS); } catch (Throwable e) { System.err.println("jfr " + c.getName() + ": unexpected internal error, " + e.getMessage()); e.printStackTrace(); System.exit(EXIT_FAILED); } } } System.err.println("jfr: unknown command '" + command + "'"); System.err.println(); System.err.println("List of available commands:"); System.err.println(); Command.displayAvailableCommands(System.err); System.exit(EXIT_WRONG_ARGUMENTS); }
Example 17
Source File: LabelBuilder.java From allure-java with Apache License 2.0 | 4 votes |
LabelBuilder(final Feature feature, final TestCase scenario, final Deque<PickleTag> tags) { final TagParser tagParser = new TagParser(feature, scenario); getScenarioLabels().add(createFeatureLabel(feature.getName())); getScenarioLabels().add(createStoryLabel(scenario.getName())); while (tags.peek() != null) { final PickleTag tag = tags.remove(); final String tagString = tag.getName(); if (tagString.contains(COMPOSITE_TAG_DELIMITER)) { final String[] tagParts = tagString.split(COMPOSITE_TAG_DELIMITER, 2); if (tagParts.length < 2 || Objects.isNull(tagParts[1]) || tagParts[1].isEmpty()) { // skip empty tags, e.g. '@tmsLink=', to avoid formatter errors continue; } final String tagKey = tagParts[0].toUpperCase(); final String tagValue = tagParts[1]; // Handle composite named links if (tagKey.startsWith(PLAIN_LINK + ".")) { tryHandleNamedLink(tagString); continue; } switch (tagKey) { case SEVERITY: getScenarioLabels().add(createSeverityLabel(tagValue.toLowerCase())); break; case TMS_LINK: getScenarioLinks().add(createTmsLink(tagValue)); break; case ISSUE_LINK: getScenarioLinks().add(createIssueLink(tagValue)); break; case PLAIN_LINK: getScenarioLinks().add(createLink(null, tagValue, tagValue, null)); break; default: LOGGER.warn("Composite tag {} is not supported. adding it as RAW", tagKey); getScenarioLabels().add(getTagLabel(tag)); break; } } else if (tagParser.isPureSeverityTag(tag)) { getScenarioLabels().add(createSeverityLabel(tagString.substring(1))); } else if (!tagParser.isResultTag(tag)) { getScenarioLabels().add(getTagLabel(tag)); } } getScenarioLabels().addAll(Arrays.asList( createHostLabel(), createThreadLabel(), createPackageLabel(feature.getName()), createSuiteLabel(feature.getName()), createTestClassLabel(scenario.getName()), createFrameworkLabel("cucumber2jvm"), createLanguageLabel("java") )); }
Example 18
Source File: Board.java From lizzie with GNU General Public License v3.0 | 4 votes |
private Stone markEmptyArea(Stone[] stones, int startx, int starty) { Stone[] shdwstones = stones.clone(); // Found will either be black or white, or dame if both are found in area Stone found = Stone.EMPTY; boolean lastup, lastdown; Queue<int[]> visitQ = new ArrayDeque<>(); visitQ.add(new int[] {startx, starty}); Deque<Integer> allPoints = new ArrayDeque<>(); // Check one line at the time, new lines added to visitQ while (!visitQ.isEmpty()) { int[] curpos = visitQ.remove(); int x = curpos[0]; int y = curpos[1]; if (!emptyOrCaptured(shdwstones, x, y)) { continue; } // Move all the way left while (x > 0 && emptyOrCaptured(shdwstones, x - 1, y)) { x--; } // Are we on the border, or do we have a stone to the left? if (x > 0 && shdwstones[getIndex(x - 1, y)] != found) { if (found == Stone.EMPTY) found = shdwstones[getIndex(x - 1, y)]; else found = Stone.DAME; } lastup = lastdown = false; while (x < boardWidth && emptyOrCaptured(shdwstones, x, y)) { // Check above if (y - 1 >= 0 && shdwstones[getIndex(x, y - 1)] != Stone.DAME) { if (emptyOrCaptured(shdwstones, x, y - 1)) { if (!lastup) visitQ.add(new int[] {x, y - 1}); lastup = true; } else { lastup = false; if (found != shdwstones[getIndex(x, y - 1)]) { if (found == Stone.EMPTY) { found = shdwstones[getIndex(x, y - 1)]; } else { found = Stone.DAME; } } } } // Check below if (y + 1 < boardHeight && shdwstones[getIndex(x, y + 1)] != Stone.DAME) { if (emptyOrCaptured(shdwstones, x, y + 1)) { if (!lastdown) { visitQ.add(new int[] {x, y + 1}); } lastdown = true; } else { lastdown = false; if (found != shdwstones[getIndex(x, y + 1)]) { if (found == Stone.EMPTY) { found = shdwstones[getIndex(x, y + 1)]; } else { found = Stone.DAME; } } } } // Add current stone to empty area and mark as visited if (shdwstones[getIndex(x, y)] == Stone.EMPTY) allPoints.add(getIndex(x, y)); // Use dame stone to mark as visited shdwstones[getIndex(x, y)] = Stone.DAME; x++; } // At this point x is at the edge of the board or on a stone if (x < boardWidth && shdwstones[getIndex(x, y)] != found) { if (found == Stone.EMPTY) found = shdwstones[getIndex(x, y)]; else found = Stone.DAME; } } // Finally mark all points as black or white captured if they were surronded by white or black if (found == Stone.WHITE) found = Stone.WHITE_POINT; else if (found == Stone.BLACK) found = Stone.BLACK_POINT; // else found == DAME and will be set as this. while (!allPoints.isEmpty()) { int idx = allPoints.remove(); stones[idx] = found; } return found; }
Example 19
Source File: LabelBuilder.java From allure-java with Apache License 2.0 | 4 votes |
LabelBuilder(final Feature feature, final TestCase scenario, final Deque<PickleTag> tags) { final TagParser tagParser = new TagParser(feature, scenario); while (tags.peek() != null) { final PickleTag tag = tags.remove(); final String tagString = tag.getName(); if (tagString.contains(COMPOSITE_TAG_DELIMITER)) { final String[] tagParts = tagString.split(COMPOSITE_TAG_DELIMITER, 2); if (tagParts.length < 2 || Objects.isNull(tagParts[1]) || tagParts[1].isEmpty()) { // skip empty tags, e.g. '@tmsLink=', to avoid formatter errors continue; } final String tagKey = tagParts[0].toUpperCase(); final String tagValue = tagParts[1]; // Handle composite named links if (tagKey.startsWith(PLAIN_LINK + ".")) { tryHandleNamedLink(tagString); continue; } switch (tagKey) { case SEVERITY: getScenarioLabels().add(ResultsUtils.createSeverityLabel(tagValue.toLowerCase())); break; case TMS_LINK: getScenarioLinks().add(ResultsUtils.createTmsLink(tagValue)); break; case ISSUE_LINK: getScenarioLinks().add(ResultsUtils.createIssueLink(tagValue)); break; case PLAIN_LINK: getScenarioLinks().add(ResultsUtils.createLink(null, tagValue, tagValue, null)); break; default: LOGGER.warn("Composite tag {} is not supported. adding it as RAW", tagKey); getScenarioLabels().add(getTagLabel(tag)); break; } } else if (tagParser.isPureSeverityTag(tag)) { getScenarioLabels().add(ResultsUtils.createSeverityLabel(tagString.substring(1))); } else if (!tagParser.isResultTag(tag)) { getScenarioLabels().add(getTagLabel(tag)); } } final String featureName = feature.getName(); final String uri = scenario.getUri(); getScenarioLabels().addAll(Arrays.asList( createHostLabel(), createThreadLabel(), createFeatureLabel(featureName), createStoryLabel(scenario.getName()), createSuiteLabel(featureName), createTestClassLabel(scenario.getName()), createFrameworkLabel("cucumber4jvm"), createLanguageLabel("java"), createLabel("gherkin_uri", uri) )); featurePackage(uri, featureName) .map(ResultsUtils::createPackageLabel) .ifPresent(getScenarioLabels()::add); }
Example 20
Source File: ArrangementUtilities.java From constellation with Apache License 2.0 | 4 votes |
/** * Returns a GraphTaxonomy, with each taxon representing the vertices in a * (weak) component. * <p> * This procedure is fundamentally linear, but may be slowed by construction * of reporting structures. It is implemented as a breadth-first traversal. * <p> * @param wg The graph to get the components from. * * @return a GraphTaxonomy, with each taxon representing the vertices in a * (weak) component. */ public static GraphTaxonomy getComponents(final GraphWriteMethods wg) { Map<Integer, Set<Integer>> components = new HashMap<>(); Map<Integer, Integer> nodeToComponent = new HashMap<>(); final int singletonsComponentID = -1; final int doubletsComponentID = -2; components.put(singletonsComponentID, new HashSet<>()); components.put(doubletsComponentID, new HashSet<>()); final BitSet potentials = vertexBits(wg); for (int vxID = potentials.nextSetBit(0); vxID >= 0; vxID = potentials.nextSetBit(vxID + 1)) { Set<Integer> component = new HashSet<>(); component.add(vxID); nodeToComponent.put(vxID, vxID); potentials.clear(vxID); if (wg.getVertexNeighbourCount(vxID) != 0) { Deque<Integer> neighbours = new LinkedList<>(); neighbours.add(vxID); while (!neighbours.isEmpty()) { final Integer nxID = neighbours.remove(); for (int i = 0; i < wg.getVertexNeighbourCount(nxID); i++) { final int nextNxID = wg.getVertexNeighbour(nxID, i); if (potentials.get(nextNxID)) { component.add(nextNxID); nodeToComponent.put(nextNxID, vxID); neighbours.add(nextNxID); potentials.clear(nextNxID); } } } } if (component.size() == 1) { components.get(singletonsComponentID).addAll(component); nodeToComponent.put(vxID, singletonsComponentID); } else if (component.size() == 2) { components.get(doubletsComponentID).addAll(component); for (int vert : component) { nodeToComponent.put(vert, doubletsComponentID); } } else { components.put(vxID, component); } } return new GraphTaxonomy(wg, components, nodeToComponent, singletonsComponentID, doubletsComponentID); }