List of usage examples for java.util Stack peek
public synchronized E peek()
From source file:org.sakaiproject.archive.impl.BasicArchiveService.java
/** * Archive the site definition./* www . j a v a2s .c o m*/ * @param site the site. * @param doc The document to contain the xml. * @param stack The stack of elements, the top of which will be the containing * element of the "site" element. */ protected static String archiveSite(Site site, Document doc, Stack stack) { Element element = doc.createElement(SiteService.APPLICATION_ID); ((Element) stack.peek()).appendChild(element); stack.push(element); Element siteNode = site.toXml(doc, stack); stack.push(siteNode); // to add the realm node with user list into site List roles = new Vector(); String realmId = "/site/" + site.getId(); try { Role role = null; AuthzGroup realm = AuthzGroupService.getAuthzGroup(realmId); Element realmNode = doc.createElement("roles"); ((Element) stack.peek()).appendChild(realmNode); stack.push(realmNode); roles.addAll(realm.getRoles()); for (int i = 0; i < roles.size(); i++) { role = (Role) roles.get(i); String roleId = role.getId(); Element node = doc.createElement(roleId); realmNode.appendChild(node); List users = new Vector(); users.addAll(realm.getUsersHasRole(role.getId())); for (int j = 0; j < users.size(); j++) { Element abilityNode = doc.createElement("ability"); abilityNode.setAttribute("roleId", roleId); abilityNode.setAttribute("userId", ((String) users.get(j))); node.appendChild(abilityNode); } } } catch (Exception any) { // M_log.warn("archve: exception archiving site: "+ site.getId() + ": ", any); } stack.pop(); return "archiving Site: " + site.getId() + "\n"; }
From source file:SpectraFrame.java
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked // TODO add your handling code here: String input = moleculefield.getText(); NMR mynmr = new NMR(input, "1H"); ChartPanel thechart = new ChartPanel(mynmr.getchart().getchart()); spectrumarea.setLayout(new java.awt.BorderLayout()); spectrumarea.add(thechart, BorderLayout.CENTER); spectrumarea.validate();/*from w w w . jav a 2 s .co m*/ Stack<Double> thevalues = mynmr.getvalues(); String finalstring = ""; for (int i = 0; i < thevalues.size(); i++) { finalstring = finalstring + thevalues.peek(); thevalues.pop(); } jButton1.setEnabled(false); }
From source file:com.madrobot.di.wizard.json.JSONSerializer.java
/** * Serialize a specific java object recursively. * /*from ww w . j av a 2 s. c om*/ * @param jsonObject * Object whose fields need to be set * * @param stack * Stack of {@link ClassInfo} - entity type under consideration * * @throws JSONException * If an exception occurs during parsing */ private void serializer(JSONObject jsonObject, final Stack<Object> stack) throws JSONException { Object userObject = stack.peek(); Class<?> userClass = userObject.getClass(); Field[] fields = userClass.getDeclaredFields(); for (Field field : fields) { String fieldName = field.getName(); Class<?> classType = field.getType(); String jsonKeyName = getKeyName(field); try { String getMethodName = getGetMethodName(fieldName, classType); Method getMethod = userClass.getDeclaredMethod(getMethodName); Object returnValue = getMethod.invoke(userObject, new Object[] {}); if (Converter.isPseudoPrimitive(classType)) { Converter.storeValue(jsonObject, jsonKeyName, returnValue, field); } else if (Converter.isCollectionType(classType)) { JSONArray jsonArray = new JSONArray(); boolean canAdd = true; if (returnValue instanceof Collection) { Collection<?> userCollectionObj = (Collection<?>) returnValue; if (userCollectionObj.size() != 0) { Iterator<?> iterator = userCollectionObj.iterator(); while (iterator.hasNext()) { Object itemObject = iterator.next(); JSONObject object = new JSONObject(); stack.push(itemObject); serializer(object, stack); jsonArray.put(object); } } else if (field.isAnnotationPresent(ItemType.class)) { ItemType itemType = field.getAnnotation(ItemType.class); canAdd = itemType.canEmpty(); } if (canAdd) jsonObject.put(jsonKeyName, jsonArray); } else if (returnValue instanceof Map) { Map<?, ?> userMapObj = (Map<?, ?>) returnValue; JSONObject object = new JSONObject(userMapObj); jsonArray.put(object); jsonObject.put(jsonKeyName, jsonArray); } } else { stack.push(returnValue); JSONObject object = new JSONObject(); serializer(object, stack); jsonObject.put(jsonKeyName, object); } } catch (NoSuchMethodException e) { Log.e(TAG, e.getMessage()); } catch (IllegalAccessException e) { Log.e(TAG, e.getMessage()); } catch (InvocationTargetException e) { Log.e(TAG, e.getMessage()); } } }
From source file:org.sakaiproject.signup.tool.entityproviders.CopyFileProcessor.java
public Element toXml(String element, Document doc, Stack stack) { Element ele = doc.createElement(element); if (stack.isEmpty()) { doc.appendChild(ele);/*from w ww .ja v a2 s .c o m*/ } else { ((Element) stack.peek()).appendChild(ele); } stack.push(ele); stack.pop(); return ele; }
From source file:padl.creator.cppfile.eclipse.plugin.internal.SearchHelper.java
static IEntity getExistingContainerOrCreateGhost0(final ICodeLevelModel aCodeLevelModel, final Stack<IContainer> someContainers, final char[][] qualifiedName, boolean isGlobalFunction) { char[] name = qualifiedName[0]; if (Utils.isPrimitiveName(name)) { final IPrimitiveEntity entity; if (!aCodeLevelModel.doesContainConstituentWithName(name)) { aCodeLevelModel.addConstituent( ((ICPPFactoryEclipse) CPPFactoryEclipse.getInstance()).createPrimitiveEntity(name)); }/* ww w. j av a 2 s. c o m*/ entity = (IPrimitiveEntity) aCodeLevelModel.getConstituentFromID(name); return entity; } else if (someContainers == null) { return (IFirstClassEntity) SearchHelper.findContainerOrCreateGhostInModelRecursively(aCodeLevelModel, qualifiedName, isGlobalFunction); } else { final IContainer container = someContainers.peek(); char[] id = qualifiedName[0]; IContainer entity = (IContainer) container.getConstituentFromName(id); if (entity == null) { return SearchHelper.getExistingContainerOrCreateGhost(aCodeLevelModel, null, qualifiedName, isGlobalFunction); } if (entity instanceof IConstructor) { return (IFirstClassEntity) container; } for (int i = 1; i < qualifiedName.length; i++) { name = qualifiedName[i]; id = ArrayUtils.addAll(ArrayUtils.add(id, Utils.SEPARATOR), qualifiedName[i]); entity = SearchHelper.findContainerOrCreateGhostInContainer((IContainer) entity, id, name, isGlobalFunction, i == qualifiedName.length - 1); } return (IFirstClassEntity) entity; } }
From source file:org.ros.internal.node.server.ParameterServer.java
@SuppressWarnings("unchecked") public boolean has(GraphName name) { Preconditions.checkArgument(name.isGlobal()); Stack<String> parts = getGraphNameParts(name); Map<String, Object> subtree = tree; while (!parts.empty() && subtree.containsKey(parts.peek())) { String part = parts.pop(); if (!parts.empty()) { subtree = (Map<String, Object>) subtree.get(part); }/*from www . j av a 2 s.c o m*/ } return parts.empty(); }
From source file:org.ros.internal.node.server.ParameterServer.java
@SuppressWarnings("unchecked") public void delete(GraphName name) { Preconditions.checkArgument(name.isGlobal()); Stack<String> parts = getGraphNameParts(name); Map<String, Object> subtree = tree; while (!parts.empty() && subtree.containsKey(parts.peek())) { String part = parts.pop(); if (parts.empty()) { subtree.remove(part);// www .j a v a2 s. com } else { subtree = (Map<String, Object>) subtree.get(part); } } }
From source file:org.cvasilak.jboss.mobile.app.activities.JBossServerRootActivity.java
@Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { // Select proper stack Stack<String> backStack = backStacks.get(tab.getTag()); // Get topmost fragment String tag = backStack.peek(); Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); // Detach it//w w w. j a v a 2 s.c om ft.detach(fragment); }
From source file:org.cvasilak.jboss.mobile.app.activities.JBossServerRootActivity.java
private void showFragment(Stack<String> backStack, FragmentTransaction ft) { // Peek topmost fragment from the stack String tag = backStack.peek(); Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); // and attach it ft.attach(fragment);/* www .j av a 2 s . com*/ }
From source file:org.sakaiproject.calendar.impl.ExclusionSeqRecurrenceRule.java
/** * Serialize the resource into XML, adding an element to the doc under the top of the stack element. * @param doc The DOM doc to contain the XML (or null for a string return). * @param stack The DOM elements, the top of which is the containing element of the new "resource" element. * @return The newly added element.// w w w . j av a 2 s .c o m */ public Element toXml(Document doc, Stack stack) { // add the "rule" element to the stack'ed element Element rule = doc.createElement("ex-rule"); ((Element) stack.peek()).appendChild(rule); // set the class name - old style for CHEF 1.2.10 compatibility rule.setAttribute("class", "org.chefproject.osid.calendar.ExclusionSeqRecurrenceRule"); // set the rule class name w/o package, for modern usage rule.setAttribute("name", "ExclusionSeqRecurrenceRule"); // set the ranges for (Iterator iSeq = m_exclusions.iterator(); iSeq.hasNext();) { Integer seq = (Integer) iSeq.next(); Element exElement = doc.createElement("exclude"); rule.appendChild(exElement); exElement.setAttribute("sequence", seq.toString()); } return rule; }