List of usage examples for java.util Deque pop
E pop();
From source file:org.polymap.rhei.form.batik.BatikFormContainer.java
@Override protected void updateEnabled() { if (pageBody == null || pageBody.isDisposed()) { return;//from w w w .j a va2s .c o m } Deque<Control> deque = new LinkedList(Collections.singleton(pageBody)); while (!deque.isEmpty()) { Control control = deque.pop(); String variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug("VARIANT: " + variant + " (" + control.getClass().getSimpleName() + ")"); // form fields if (variant == null || variant.equals(CSS_FORMFIELD) || variant.equals(CSS_FORMFIELD_DISABLED) || variant.equals(BaseFieldComposite.CUSTOM_VARIANT_VALUE)) { UIUtils.setVariant(control, enabled ? CSS_FORMFIELD : CSS_FORMFIELD_DISABLED); } // form else if (variant.equals(CSS_FORM) || variant.equals(CSS_FORM_DISABLED)) { UIUtils.setVariant(control, enabled ? CSS_FORM : CSS_FORM_DISABLED); } // // labeler Label // String labelVariant = (String)control.getData( WidgetUtil.CUSTOM_VARIANT ); // if (control instanceof Label // && (labelVariant.equals( CSS_FORMFIELD ) || labelVariant.equals( CSS_FORMFIELD_DISABLED ))) { // control.setFont( enabled // ? JFaceResources.getFontRegistry().get( JFaceResources.DEFAULT_FONT ) // : JFaceResources.getFontRegistry().getBold( JFaceResources.DEFAULT_FONT ) ); // // if (!enabled) { // control.setBackground( Graphics.getColor( 0xED, 0xEF, 0xF1 ) ); // } // } // Composite if (control instanceof Composite) { control.setEnabled(enabled); deque.addAll(Arrays.asList(((Composite) control).getChildren())); } variant = (String) control.getData(RWT.CUSTOM_VARIANT); log.debug(" -> " + variant + " (" + control.getClass().getSimpleName() + ")"); } }
From source file:org.rhq.core.pc.inventory.InventoryManager.java
private void syncDriftDefinitionsRecursively(Resource resource) { if (resource.getInventoryStatus() != InventoryStatus.COMMITTED) { return;//from w w w.j a v a 2 s . c om } Deque<Resource> resources = new LinkedList<Resource>(); resources.push(resource); Set<Integer> resourceIds = new HashSet<Integer>(); while (!resources.isEmpty()) { Resource r = resources.pop(); if (supportsDriftManagement(r)) { resourceIds.add(r.getId()); } for (Resource child : r.getChildResources()) { resources.push(child); } } DriftSyncManager driftSyncMgr = createDriftSyncManager(); driftSyncMgr.syncWithServer(resourceIds); }
From source file:org.roda.core.util.ZipUtility.java
public static void zip(File directory, ZipOutputStream zout) throws IOException { URI base = directory.toURI(); Deque<File> queue = new LinkedList<>(); queue.push(directory);/*from ww w . j a v a 2s.c o m*/ try { while (!queue.isEmpty()) { File dir = queue.pop(); for (File kid : dir.listFiles()) { String name = base.relativize(kid.toURI()).getPath(); if (kid.isDirectory()) { queue.push(kid); name = name.endsWith("/") ? name : name + "/"; zout.putNextEntry(new ZipEntry(name)); } else { zout.putNextEntry(new ZipEntry(name)); copy(kid, zout); zout.closeEntry(); } } } } finally { zout.close(); } }
From source file:org.talend.dataprep.transformation.actions.text.ExtractStringTokens.java
@Override public void compile(ActionContext context) { super.compile(context); if (context.getActionStatus() == ActionContext.ActionStatus.OK) { final String regex = context.getParameters().get(PARAMETER_REGEX); // Validate the regex, and put it in context once for all lines: // Check 1: not null or empty if (StringUtils.isEmpty(regex)) { LOGGER.debug("Empty pattern, action canceled"); context.setActionStatus(ActionContext.ActionStatus.CANCELED); return; }/*from www . j a v a2 s .co m*/ // Check 2: valid regex try { context.get(PATTERN, p -> Pattern.compile(regex)); } catch (PatternSyntaxException e) { LOGGER.debug("Invalid pattern {} --> {}, action canceled", regex, e.getMessage(), e); context.setActionStatus(ActionContext.ActionStatus.CANCELED); } // Create result column final Map<String, String> parameters = context.getParameters(); final String columnId = context.getColumnId(); // create the new columns int limit = parameters.get(MODE_PARAMETER).equals(MULTIPLE_COLUMNS_MODE) ? Integer.parseInt(parameters.get(LIMIT)) : 1; final RowMetadata rowMetadata = context.getRowMetadata(); final ColumnMetadata column = rowMetadata.getById(columnId); final List<String> newColumns = new ArrayList<>(); final Deque<String> lastColumnId = new ArrayDeque<>(); lastColumnId.push(columnId); for (int i = 0; i < limit; i++) { final int newColumnIndex = i + 1; newColumns.add(context.column(column.getName() + APPENDIX + i, r -> { final ColumnMetadata c = ColumnMetadata.Builder // .column() // .type(Type.STRING) // .computedId(StringUtils.EMPTY) // .name(column.getName() + APPENDIX + newColumnIndex) // .build(); lastColumnId.push(rowMetadata.insertAfter(lastColumnId.pop(), c)); return c; })); } } }
From source file:org.talend.dataprep.transformation.actions.text.Split.java
@Override public void compile(ActionContext context) { super.compile(context); if (context.getActionStatus() == ActionContext.ActionStatus.OK) { if (StringUtils.isEmpty(getSeparator(context))) { LOGGER.warn("Cannot split on an empty separator"); context.setActionStatus(ActionContext.ActionStatus.CANCELED); }// www. j av a 2 s .c o m // Create split columns final RowMetadata rowMetadata = context.getRowMetadata(); final String columnId = context.getColumnId(); final ColumnMetadata column = rowMetadata.getById(columnId); final Deque<String> lastColumnId = new ArrayDeque<>(); final Map<String, String> parameters = context.getParameters(); int limit = Integer.parseInt(parameters.get(LIMIT)); final List<String> newColumns = new ArrayList<>(); lastColumnId.push(columnId); for (int i = 0; i < limit; i++) { final int newColumnIndex = i + 1; newColumns.add(context.column(column.getName() + SPLIT_APPENDIX + i, r -> { final ColumnMetadata c = ColumnMetadata.Builder // .column() // .type(Type.STRING) // .computedId(StringUtils.EMPTY) // .name(column.getName() + SPLIT_APPENDIX + newColumnIndex) // .build(); lastColumnId.push(rowMetadata.insertAfter(lastColumnId.pop(), c)); return c; })); } context.get(NEW_COLUMNS_CONTEXT, p -> newColumns); // Save new column names for apply } }
From source file:org.talend.dataquality.semantic.recognizer.DefaultCategoryRecognizer.java
/** * For the discovery, if a category c matches with the data, * it means all the ancestor categories of c have to match too. * This method increments the ancestor categories of c. * //from w ww. java2 s . com * @param categories, the category result * @param id, the category ID of the matched category c * */ private void incrementAncestorsCategories(Set<String> categories, String id) { Deque<Pair<String, Integer>> catToSee = new ArrayDeque<>(); Set<String> catAlreadySeen = new HashSet<>(); catToSee.add(Pair.of(id, 0)); Pair<String, Integer> currentCategory; while (!catToSee.isEmpty()) { currentCategory = catToSee.pop(); DQCategory dqCategory = crm.getCategoryMetadataById(currentCategory.getLeft()); if (dqCategory != null && !CollectionUtils.isEmpty(dqCategory.getParents())) { int parentLevel = currentCategory.getRight() + 1; for (DQCategory parent : dqCategory.getParents()) { if (!catAlreadySeen.contains(parent.getId())) { catAlreadySeen.add(parent.getId()); catToSee.add(Pair.of(parent.getId(), parentLevel)); DQCategory meta = crm.getCategoryMetadataById(parent.getId()); if (meta != null) { incrementCategory(meta.getName(), meta.getLabel(), parentLevel); categories.add(meta.getName()); } } } } } }
From source file:org.talend.dataquality.semantic.statistics.SemanticQualityAnalyzer.java
/** * For the validation of a COMPOUND category, we only have to valid the leaves children categories. * This methods find the DICT children categories and the REGEX children categories. * /*from ww w.j av a 2s. c o m*/ * @param id, the category from we search the children * @return the DICT children categories and the REGEX children categories with a map. */ private Map<CategoryType, Set<DQCategory>> getChildrenCategories(String id) { Deque<String> catToSee = new ArrayDeque<>(); Set<String> catAlreadySeen = new HashSet<>(); Map<CategoryType, Set<DQCategory>> children = new HashMap<>(); children.put(CategoryType.REGEX, new HashSet<DQCategory>()); children.put(CategoryType.DICT, new HashSet<DQCategory>()); catToSee.add(id); String currentCategory; while (!catToSee.isEmpty()) { currentCategory = catToSee.pop(); DQCategory dqCategory = crm.getCategoryMetadataById(currentCategory); if (dqCategory != null) if (!CollectionUtils.isEmpty(dqCategory.getChildren())) { for (DQCategory child : dqCategory.getChildren()) { if (!catAlreadySeen.contains(child.getId())) { catAlreadySeen.add(child.getId()); catToSee.add(child.getId()); } } } else if (!currentCategory.equals(id)) { children.get(dqCategory.getType()).add(dqCategory); } } return children; }
From source file:org.teavm.flavour.templates.parsing.Parser.java
private void popVar(String name) { Deque<ValueType> stack = variables.get(name); if (stack != null) { stack.pop(); if (stack.isEmpty()) { variables.remove(stack);/*from www . j a v a 2s. c om*/ } } }
From source file:specminers.evaluation.MinedSpecsFilter.java
private boolean checkIfCatchSectionSwallowsException(String catchBlockStartLine) { int startIndex = this.lines.indexOf(catchBlockStartLine); // contains return, continue or does not throw. Deque<String> blocks = new LinkedList<>(); blocks.add(catchBlockStartLine);/* w w w . j av a 2 s.c o m*/ Deque<Integer> blockStartPositions = new LinkedList<>(); blockStartPositions.add(sourceCode.indexOf(catchBlockStartLine) + catchBlockStartLine.indexOf("{")); boolean throwFound = false; int currentBlockStart = blockStartPositions.peekFirst(); int currentIndexInFile = currentBlockStart; for (int i = startIndex; i < lines.size(); i++) { String line = lines.get(i); if (!blocks.isEmpty()) { if (line.contains("{") && i != startIndex) { blocks.add(line); blockStartPositions.add(sourceCode.indexOf(line.trim())); } if (line.contains("}") && line.indexOf("}") + currentIndexInFile > currentBlockStart) { blocks.pop(); currentBlockStart = blockStartPositions.pop(); } if (line.contains("return ") || line.contains("return;") || line.contains("continue;")) { return true; } if (line.contains("throw ")) { throwFound = true; } } currentIndexInFile += line.length(); } return !throwFound; }
From source file:specminers.evaluation.RandoopGeneratedTestParser.java
private void loadTestMethods() { this.testMethods = new LinkedList<>(); this.testMethodDetails = new HashMap<>(); String testMethodRegularExpressionDeclaration = "^public\\svoid\\stest(\\d+)\\(\\).+$"; Deque<String> openBraces = new ArrayDeque<>(); String currentMethod = null;//from ww w. jav a 2 s .c o m List<String> statementsBeforeTryCatch = null; String currentClass = ""; boolean foundTryCatchForCurrentTestMethod = false; String firstVarFound = ""; String varRegex = "var\\d+\\W"; Pattern p = Pattern.compile(varRegex); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (line.matches(testMethodRegularExpressionDeclaration)) { openBraces.add("{"); currentMethod = StringHelper.extractSingleValueWithRegex(line, testMethodRegularExpressionDeclaration, 1); statementsBeforeTryCatch = new LinkedList<>(); foundTryCatchForCurrentTestMethod = false; } else { if (currentMethod != null) { if (line.contains("try {")) { foundTryCatchForCurrentTestMethod = true; } if (!line.contains("if (debug) { System.out.println();")) { Matcher m = p.matcher(line); if (m.find()) { if (!foundTryCatchForCurrentTestMethod) { if (StringUtils.isEmpty(firstVarFound)) { firstVarFound = m.group(0).trim(); } if (line.contains(firstVarFound)) { if (line.contains(firstVarFound + " = new java.")) { int startIndex = line.indexOf("new") + 3; int endIndex = line.indexOf("(", startIndex); try { currentClass = line.substring(startIndex, endIndex); statementsBeforeTryCatch.add((currentClass + ".<init>()").trim()); } catch (StringIndexOutOfBoundsException ex) { System.out.println("Error parsing line " + line + " startIndex " + startIndex + " endIndex " + endIndex + " from java file " + javaFile.getAbsolutePath() + " current test method test" + currentMethod); } } else { if (line.contains(firstVarFound + ".")) { int startIndex = line.indexOf(firstVarFound + ".") + 4; int endIndex = line.lastIndexOf("("); String calledMethod = ""; calledMethod = line.substring(startIndex, endIndex); statementsBeforeTryCatch.add(currentClass + calledMethod + (calledMethod.endsWith("(") ? "" : "(") + ")"); } } } } } for (int j = 0; j < line.length(); j++) { if (line.charAt(j) == '{') { openBraces.add("{"); } if (line.charAt(j) == '}') { if (!openBraces.isEmpty()) { openBraces.pop(); } } } } if (openBraces.isEmpty()) { String testMethodStatements = statementsBeforeTryCatch.stream().map(st -> st.trim()) .collect(Collectors.joining("")); Map<String, String> currentTestDetails = new HashMap<>(); currentTestDetails.put("foundTryCatch", foundTryCatchForCurrentTestMethod + ""); currentTestDetails.put("statementsBeforeTryCatch", testMethodStatements); if (StringUtils.isNotBlank(currentMethod)) { testMethodDetails.put(currentMethod, currentTestDetails); } currentMethod = null; statementsBeforeTryCatch.clear(); ; foundTryCatchForCurrentTestMethod = false; firstVarFound = null; // Prepare for new method } } } } }