public TreeNode nextElement() { Enumeration enumer = stack.peek(); TreeNode node = (TreeNode) enumer.nextElement(); Enumeration children = node.children(); if (!enumer.hasMoreElements()) { stack.pop(); } if (children.hasMoreElements()) { stack.push(children); } return node; }
public TreeNode nextElement() { Enumeration enumer = (Enumeration) queue.firstObject(); TreeNode node = (TreeNode) enumer.nextElement(); Enumeration children = node.children(); if (!enumer.hasMoreElements()) { queue.dequeue(); } if (children.hasMoreElements()) { queue.enqueue(children); } return node; }
public TreeNode nextElement() { TreeNode retval; if (subtree.hasMoreElements()) { retval = subtree.nextElement(); } else if (children.hasMoreElements()) { subtree = new PostorderEnumeration(children.nextElement()); retval = subtree.nextElement(); } else { retval = root; root = null; } return retval; }
/** Returns the URLs contained within an RMI registry reference. */ private static String[] getURLs(Reference ref) throws NamingException { int size = 0; // number of URLs String[] urls = new String[ref.size()]; Enumeration<RefAddr> addrs = ref.getAll(); while (addrs.hasMoreElements()) { RefAddr addr = addrs.nextElement(); if ((addr instanceof StringRefAddr) && addr.getType().equals(ADDRESS_TYPE)) { urls[size++] = (String) addr.getContent(); } } if (size == 0) { throw (new ConfigurationException("Reference contains no valid addresses")); } // Trim URL array down to size. if (size == ref.size()) { return urls; } String[] urls2 = new String[size]; System.arraycopy(urls, 0, urls2, 0, size); return urls2; }
public void run() { JavaClass clazz = snapshot.findClass(query); String instancesOf; if (newObjects) instancesOf = "New instances of "; else instancesOf = "Instances of "; if (includeSubclasses) { startHtml(instancesOf + query + " (including subclasses)"); } else { startHtml(instancesOf + query); } if (clazz == null) { error("Class not found"); } else { out.print("<strong>"); printClass(clazz); out.print("</strong><br><br>"); Enumeration objects = clazz.getInstances(includeSubclasses); long totalSize = 0; long instances = 0; while (objects.hasMoreElements()) { JavaHeapObject obj = (JavaHeapObject) objects.nextElement(); if (newObjects && !obj.isNew()) continue; printThing(obj); out.println("<br>"); totalSize += obj.getSize(); instances++; } out.println( "<h2>Total of " + instances + " instances occupying " + totalSize + " bytes.</h2>"); } endHtml(); }
// // This function is the recursive search of groups for this // implementation of the Group. The search proceeds building up // a vector of already seen groups. Only new groups are considered, // thereby avoiding loops. // boolean isMemberRecurse(Principal member, Vector<Group> alreadySeen) { Enumeration<? extends Principal> e = members(); while (e.hasMoreElements()) { boolean mem = false; Principal p = (Principal) e.nextElement(); // if the member is in this collection, return true if (p.equals(member)) { return true; } else if (p instanceof GroupImpl) { // // if not recurse if the group has not been checked already. // Can call method in this package only if the object is an // instance of this class. Otherwise call the method defined // in the interface. (This can lead to a loop if a mixture of // implementations form a loop, but we live with this improbable // case rather than clutter the interface by forcing the // implementation of this method.) // GroupImpl g = (GroupImpl) p; alreadySeen.addElement(this); if (!alreadySeen.contains(g)) mem = g.isMemberRecurse(member, alreadySeen); } else if (p instanceof Group) { Group g = (Group) p; if (!alreadySeen.contains(g)) mem = g.isMember(member); } if (mem) return mem; } return false; }
/** Print the HTML tag. */ public static void printTag(PrintStream out, Hashtable atts) { out.print("<applet"); String v = (String) atts.get("codebase"); if (v != null) { out.print(" codebase=\"" + v + "\""); } v = (String) atts.get("code"); if (v == null) { v = "applet.class"; } out.print(" code=\"" + v + "\""); v = (String) atts.get("width"); if (v == null) { v = "150"; } out.print(" width=" + v); v = (String) atts.get("height"); if (v == null) { v = "100"; } out.print(" height=" + v); v = (String) atts.get("name"); if (v != null) { out.print(" name=\"" + v + "\""); } out.println(">"); // A very slow sorting algorithm int len = atts.size(); String params[] = new String[len]; len = 0; for (Enumeration e = atts.keys(); e.hasMoreElements(); ) { String param = (String) e.nextElement(); int i = 0; for (; i < len; i++) { if (params[i].compareTo(param) >= 0) { break; } } System.arraycopy(params, i, params, i + 1, len - i); params[i] = param; len++; } for (int i = 0; i < len; i++) { String param = params[i]; if (systemParam.get(param) == null) { out.println("<param name=" + param + " value=\"" + atts.get(param) + "\">"); } } out.println("</applet>"); }
/** * Delete all the generated source files made during the execution of this environment (those that * have been registered with the "addGeneratedFile" method). */ public void deleteGeneratedFiles() { synchronized (generatedFiles) { Enumeration<File> enumeration = generatedFiles.elements(); while (enumeration.hasMoreElements()) { File file = enumeration.nextElement(); file.delete(); } generatedFiles.removeAllElements(); } }
/** * Returns the depth of the tree rooted at this node -- the longest distance from this node to a * leaf. If this node has no children, returns 0. This operation is much more expensive than * <code>getLevel()</code> because it must effectively traverse the entire tree rooted at this * node. * * @see #getLevel * @return the depth of the tree whose root is this node */ public int getDepth() { Object last = null; Enumeration enum_ = breadthFirstEnumeration(); while (enum_.hasMoreElements()) { last = enum_.nextElement(); } if (last == null) { throw new Error("nodes should be null"); } return ((DefaultMutableTreeNode) last).getLevel() - getLevel(); }
/** * Processes a <CODE>get</CODE> operation. It will throw an exception for V1 requests or it will * set exceptions within the list for V2 requests. * * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved. * @exception SnmpStatusException An error occurred during the operation. */ @Override public void get(SnmpMibRequest inRequest) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp( Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "get", "Get in Exception"); if (inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpStatusException.noSuchName); Enumeration<SnmpVarBind> l = inRequest.getElements(); while (l.hasMoreElements()) { SnmpVarBind varbind = l.nextElement(); varbind.setNoSuchObject(); } }
/** * Processes a <CODE>getBulk</CODE> operation. It will throw an exception if the request is a V1 * one or it will set exceptions within the list for V2 ones. * * @param inRequest The SnmpMibRequest object holding the list of variable to be retrieved. * @exception SnmpStatusException An error occurred during the operation. */ @Override public void getBulk(SnmpMibRequest inRequest, int nonRepeat, int maxRepeat) throws SnmpStatusException { SNMP_ADAPTOR_LOGGER.logp( Level.FINEST, SnmpErrorHandlerAgent.class.getName(), "getBulk", "GetBulk in Exception"); if (inRequest.getVersion() == SnmpDefinitions.snmpVersionOne) throw new SnmpStatusException(SnmpDefinitions.snmpRspGenErr, 0); Enumeration<SnmpVarBind> l = inRequest.getElements(); while (l.hasMoreElements()) { SnmpVarBind varbind = l.nextElement(); varbind.setEndOfMibView(); } }
/** Return an enumeration of all the accessible applets on this page. */ public Enumeration getApplets() { AppletSecurity security = (AppletSecurity) System.getSecurityManager(); Vector v = new Vector(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) { AppletPanel p = (AppletPanel) e.nextElement(); if (p.getDocumentBase().equals(panel.getDocumentBase())) { SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect"); if (panelSp.implies(sp)) { v.addElement(p.applet); } } } return v.elements(); }
/** * Returns the total number of leaves that are descendants of this node. If this node is a leaf, * returns <code>1</code>. This method is O(n) where n is the number of descendants of this node. * * @see #isNodeAncestor * @return the number of leaves beneath this node */ public int getLeafCount() { int count = 0; TreeNode node; Enumeration enum_ = breadthFirstEnumeration(); // order matters not while (enum_.hasMoreElements()) { node = (TreeNode) enum_.nextElement(); if (node.isLeaf()) { count++; } } if (count < 1) { throw new Error("tree has zero leaves"); } return count; }
/** Get an applet by name. */ public Applet getApplet(String name) { AppletSecurity security = (AppletSecurity) System.getSecurityManager(); name = name.toLowerCase(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) { AppletPanel p = (AppletPanel) e.nextElement(); String param = p.getParameter("name"); if (param != null) { param = param.toLowerCase(); } if (name.equals(param) && p.getDocumentBase().equals(panel.getDocumentBase())) { SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect"); if (panelSp.implies(sp)) { return p.applet; } } } return null; }