List of usage examples for java.util Stack pop
public synchronized E pop()
From source file:hudson.plugins.active_directory.ActiveDirectoryUnixAuthenticationProvider.java
/** * Performs recursive group membership lookup. * * This was how we did the lookup traditionally until we discovered 1.2.840.113556.1.4.1941. * But various people reported that it slows down the execution tremendously to the point that it is unusable, * while others seem to report that it runs faster than recursive search (http://social.technet.microsoft.com/Forums/fr-FR/f238d2b0-a1d7-48e8-8a60-542e7ccfa2e8/recursive-retrieval-of-all-ad-group-memberships-of-a-user?forum=ITCG) * * This implementation is kept for Windows 2003 that doesn't support 1.2.840.113556.1.4.1941, but it can be also * enabled for those who are seeing the performance problem. * * See JENKINS-22830//from w w w. j a v a 2s .c om */ private void recursiveGroupLookup(DirContext context, Attributes id, Set<GrantedAuthority> groups) throws NamingException { Stack<Attributes> q = new Stack<Attributes>(); q.push(id); while (!q.isEmpty()) { Attributes identity = q.pop(); LOGGER.finer("Looking up group of " + identity); Attribute memberOf = identity.get("memberOf"); if (memberOf == null) continue; for (int i = 0; i < memberOf.size(); i++) { try { LOGGER.log(Level.FINE, "Trying to get the CN of {0}", memberOf.get(i)); Attributes group = context.getAttributes(new LdapName(memberOf.get(i).toString()), new String[] { "CN", "memberOf" }); Attribute cn = group.get("CN"); if (cn == null) { LOGGER.fine("Failed to obtain CN of " + memberOf.get(i)); continue; } if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine(cn.get() + " is a member of " + memberOf.get(i)); if (groups.add(new GrantedAuthorityImpl(cn.get().toString()))) { q.add(group); // recursively look for groups that this group is a member of. } } catch (NameNotFoundException e) { LOGGER.fine("Failed to obtain CN of " + memberOf.get(i)); } } } }
From source file:com.tune.reporting.base.endpoints.EndpointBase.java
/** * Validate any parentheses within string are balanced. * @param str Contents partitioned with parentheses. * @return Boolean If contents contains balanced parentheses returns true. *//*w ww . ja va 2 s. c o m*/ public static boolean isParenthesesBalanced(final String str) { if (str.isEmpty()) { return true; } Stack<Character> stack = new Stack<Character>(); for (int i = 0; i < str.length(); i++) { char current = str.charAt(i); if (current == '{' || current == '(' || current == '[') { stack.push(current); } if (current == '}' || current == ')' || current == ']') { if (stack.isEmpty()) { return false; } char last = stack.peek(); if (current == '}' && last == '{' || current == ')' && last == '(' || current == ']' && last == '[') { stack.pop(); } else { return false; } } } return stack.isEmpty(); }
From source file:gdt.jgui.entity.fields.JFieldsEditor.java
/** * Execute the response locator.//from w w w.j av a 2s. c o m * @param console the main console. * @param locator$ the response locator. */ @Override public void response(JMainConsole console, String locator$) { // System.out.println("FieldsEditor:response:"+Locator.remove(locator$,Locator.LOCATOR_ICON )); try { Properties locator = Locator.toProperties(locator$); String action$ = locator.getProperty(JRequester.REQUESTER_ACTION); entihome$ = locator.getProperty(Entigrator.ENTIHOME); Entigrator entigrator = console.getEntigrator(entihome$); String text$ = locator.getProperty(JTextEditor.TEXT); if (ACTION_NEW_ENTITY.equals(action$)) { Sack newEntity = entigrator.ent_new("fields", text$); newEntity.createElement("field"); newEntity.putElementItem("field", new Core(null, "Name", "Value")); newEntity.createElement("fhandler"); newEntity.putElementItem("fhandler", new Core(null, FieldsHandler.class.getName(), null)); newEntity.putAttribute(new Core(null, "icon", "fields.png")); entigrator.save(newEntity); String icons$ = entihome$ + "/" + Entigrator.ICONS; Support.addHandlerIcon(getClass(), "fields.png", icons$); newEntity = entigrator.ent_reindex(newEntity); // newEntity.print(); reindex(console, entigrator, newEntity); JEntityFacetPanel efp = new JEntityFacetPanel(); String efpLocator$ = efp.getLocator(); efpLocator$ = Locator.append(efpLocator$, Locator.LOCATOR_TITLE, newEntity.getProperty("label")); efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$); efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, newEntity.getKey()); efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_LABEL, newEntity.getProperty("label")); JEntityPrimaryMenu.reindexEntity(console, efpLocator$); Stack<String> s = console.getTrack(); s.pop(); console.setTrack(s); JConsoleHandler.execute(console, efpLocator$); return; } String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); Sack entity = entigrator.getEntityAtKey(entityKey$); String cellField$ = locator.getProperty(CELL_FIELD); String name$ = locator.getProperty(CELL_FIELD_NAME); Core core = entity.getElementItem("field", name$); if (CELL_FIELD_NAME.equals(cellField$)) core.name = text$; else if (CELL_FIELD_VALUE.equals(cellField$)) core.value = text$; // System.out.println("FieldsEditor:response:name="+core.name+" value="+core.value); entity.putElementItem("field", core); entigrator.save(entity); String feLocator$ = getLocator(); feLocator$ = Locator.append(locator$, Entigrator.ENTIHOME, entihome$); feLocator$ = Locator.append(locator$, EntityHandler.ENTITY_KEY, entityKey$); feLocator$ = Locator.remove(feLocator$, BaseHandler.HANDLER_METHOD); JConsoleHandler.execute(console, feLocator$); } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:gdt.jgui.entity.webset.JWeblinkEditor.java
/** * Execute the response locator.//from w w w. j av a 2 s .c o m * @param console the main console. * @param locator$ the response locator. * */ @Override public void response(JMainConsole console, String locator$) { // System.out.println("WeblinksEditor:response:"+Locator.remove(locator$,Locator.LOCATOR_ICON )); try { Properties locator = Locator.toProperties(locator$); String action$ = locator.getProperty(JRequester.REQUESTER_ACTION); entihome$ = locator.getProperty(Entigrator.ENTIHOME); Entigrator entigrator = console.getEntigrator(entihome$); String text$ = locator.getProperty(JTextEditor.TEXT); if (ACTION_NEW_ENTITY.equals(action$)) { Sack newEntity = entigrator.ent_new("webset", text$); newEntity.createElement("fhandler"); newEntity.putElementItem("fhandler", new Core(null, WebsetHandler.class.getName(), null)); newEntity.putAttribute(new Core(null, "icon", "globe.png")); entigrator.save(newEntity); String icons$ = entihome$ + "/" + Entigrator.ICONS; Support.addHandlerIcon(JEntitiesPanel.class, "globe.png", icons$); newEntity = entigrator.ent_reindex(newEntity); reindex(console, entigrator, newEntity); JEntityFacetPanel efp = new JEntityFacetPanel(); String efpLocator$ = efp.getLocator(); efpLocator$ = Locator.append(efpLocator$, Locator.LOCATOR_TITLE, newEntity.getProperty("label")); efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$); efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, newEntity.getKey()); efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_LABEL, newEntity.getProperty("label")); JEntityPrimaryMenu.reindexEntity(console, efpLocator$); Stack<String> s = console.getTrack(); s.pop(); console.setTrack(s); JConsoleHandler.execute(console, efpLocator$); return; } if (ACTION_SET_ICON.equals(action$)) { //System.out.println("WeblinkEditor:response:set icon:locator="+locator$); try { String iconFile$ = locator.getProperty(JIconSelector.ICON); // System.out.println("WeblinkEditor:response:set icon="+iconFile$); String icon$ = entigrator.readIconFromIcons(iconFile$); //icon$=IconSelector.resize16in24(getBackground(), icon$); Sack entity = entigrator.getEntityAtKey(entityKey$); entity.putElementItem("web.icon", new Core(null, webLinkKey$, icon$)); entigrator.save(entity); locator$ = Locator.remove(locator$, BaseHandler.HANDLER_METHOD); locator$ = Locator.remove(locator$, JRequester.REQUESTER_ACTION); JConsoleHandler.execute(console, locator$); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } return; } if (ACTION_ENCODE_PASSWORD.equals(action$)) { //System.out.println("WeblinkEditor:response:set icon:locator="+locator$); try { Sack entity = entigrator.getEntityAtKey(entityKey$); Core login = entity.getElementItem("web.login", webLinkKey$); if (login == null) { if (!entity.existsElement("web.login")) entity.createElement("web.login"); login = new Core(null, webLinkKey$, text$); } else login.value = text$; entity.putElementItem("web.login", login); entigrator.save(entity); locator$ = Locator.remove(locator$, BaseHandler.HANDLER_METHOD); locator$ = Locator.remove(locator$, JRequester.REQUESTER_ACTION); JConsoleHandler.execute(console, locator$); } catch (Exception ee) { Logger.getLogger(getClass().getName()).info(ee.toString()); } return; } } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } }
From source file:com.anite.zebra.hivemind.om.state.ZebraProcessInstance.java
/** * @param results//from w ww . j ava 2 s .co m * @param q * @throws HibernateException */ @Transient private void recursivelyQueryChildProcesses(List<ZebraProcessInstance> results, Query q) throws HibernateException { // Recursive Process children Stack<ZebraProcessInstance> checkList = new Stack<ZebraProcessInstance>(); checkList.push(this); while (!checkList.isEmpty()) { ZebraProcessInstance processInstance = checkList.pop(); q.setLong("guid", processInstance.getProcessInstanceId().longValue()); for (Iterator it = q.iterate(); it.hasNext();) { ZebraProcessInstance childProcess = (ZebraProcessInstance) it.next(); results.add(childProcess); checkList.push(childProcess); } } }
From source file:com.opengamma.integration.copier.portfolio.writer.MasterPortfolioWriter.java
@Override public String[] getCurrentPath() { Stack<ManageablePortfolioNode> stack = _portfolioDocument.getPortfolio().getRootNode() .findNodeStackByObjectId(_currentNode.getUniqueId()); String[] result = new String[stack.size()]; int i = stack.size(); while (!stack.isEmpty()) { result[--i] = stack.pop().getName(); }/*from w w w . j a v a 2 s . c om*/ return result; }
From source file:com.blackducksoftware.integration.hub.detect.detector.pip.PipenvGraphParser.java
public PipParseResult parse(final String projectName, final String projectVersionName, final List<String> pipFreezeOutput, final List<String> pipenvGraphOutput, final String sourcePath) { final MutableMapDependencyGraph dependencyGraph = new MutableMapDependencyGraph(); final Stack<Dependency> dependencyStack = new Stack<>(); final Map<String, String[]> pipFreezeMap = pipFreezeOutput.stream() .map(line -> line.split(TOP_LEVEL_SEPARATOR)).filter(splitLine -> splitLine.length == 2) .collect(Collectors.toMap(splitLine -> splitLine[0].trim().toLowerCase(), splitLine -> splitLine)); int lastLevel = -1; for (final String line : pipenvGraphOutput) { final int currentLevel = getLevel(line); final Optional<Dependency> parsedDependency = getDependencyFromLine(pipFreezeMap, line); if (!parsedDependency.isPresent()) { continue; }/*from www . j a va 2 s .c o m*/ final Dependency dependency = parsedDependency.get(); if (currentLevel == lastLevel) { dependencyStack.pop(); } else { for (; lastLevel >= currentLevel; lastLevel--) { dependencyStack.pop(); } } if (dependencyStack.size() > 0) { dependencyGraph.addChildWithParent(dependency, dependencyStack.peek()); } else { dependencyGraph.addChildrenToRoot(dependency); } lastLevel = currentLevel; dependencyStack.push(dependency); } if (!dependencyGraph.getRootDependencyExternalIds().isEmpty()) { final ExternalId projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PYPI, projectName, projectVersionName); final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PIP, sourcePath, projectExternalId, dependencyGraph).build(); return new PipParseResult(projectName, projectVersionName, codeLocation); } else { return null; } }
From source file:com.projity.pm.graphic.model.transform.NodeCacheTransformer.java
private Map<GraphicNode, List<GraphicNode>> extractAssignments(List list) { Map<GraphicNode, List<GraphicNode>> map = new HashMap<GraphicNode, List<GraphicNode>>(); GraphicNode current, last;//from ww w. j av a 2s. c o m Stack<GraphicNode> path = new Stack<GraphicNode>(); for (ListIterator i = list.listIterator(); i.hasNext();) { current = (GraphicNode) i.next(); if (current.getLevel() == 1) { path.clear(); path.push(current); continue; } while ((last = path.peek()).getLevel() >= current.getLevel()) path.pop(); if (current.isAssignment()) { GraphicNode task = path.peek(); List<GraphicNode> ass = map.get(task); if (ass == null) { ass = new LinkedList<GraphicNode>(); map.put(task, ass); } ass.add(current); i.remove(); } path.push(current); } return map; }
From source file:org.apache.flink.streaming.api.datastream.KeyedStream.java
/** * Validates that a given type of element (as encoded by the provided {@link TypeInformation}) can be * used as a key in the {@code DataStream.keyBy()} operation. This is done by searching depth-first the * key type and checking if each of the composite types satisfies the required conditions * (see {@link #validateKeyTypeIsHashable(TypeInformation)}). * * @param keyType The {@link TypeInformation} of the key. *///from w w w . j a va 2s.c o m private TypeInformation<KEY> validateKeyType(TypeInformation<KEY> keyType) { Stack<TypeInformation<?>> stack = new Stack<>(); stack.push(keyType); List<TypeInformation<?>> unsupportedTypes = new ArrayList<>(); while (!stack.isEmpty()) { TypeInformation<?> typeInfo = stack.pop(); if (!validateKeyTypeIsHashable(typeInfo)) { unsupportedTypes.add(typeInfo); } if (typeInfo instanceof TupleTypeInfoBase) { for (int i = 0; i < typeInfo.getArity(); i++) { stack.push(((TupleTypeInfoBase) typeInfo).getTypeAt(i)); } } } if (!unsupportedTypes.isEmpty()) { throw new InvalidProgramException("Type " + keyType + " cannot be used as key. Contained " + "UNSUPPORTED key types: " + StringUtils.join(unsupportedTypes, ", ") + ". Look " + "at the keyBy() documentation for the conditions a type has to satisfy in order to be " + "eligible for a key."); } return keyType; }
From source file:com.anite.antelope.zebra.om.AntelopeProcessInstance.java
/** * @param results/* w ww . j av a 2 s . c o m*/ * @param q * @throws HibernateException */ private void recursivelyQueryChildProcesses(List results, Query q) throws HibernateException { // Recursive Process children Stack checkList = new Stack(); checkList.push(this); while (!checkList.isEmpty()) { AntelopeProcessInstance processInstance = (AntelopeProcessInstance) checkList.pop(); q.setLong("guid", processInstance.getProcessInstanceId().longValue()); for (Iterator it = q.iterate(); it.hasNext();) { AntelopeProcessInstance childProcess = (AntelopeProcessInstance) it.next(); results.add(childProcess); checkList.push(childProcess); } } }