public void commandAction(Command command, Displayable displayable) { if ((displayable == D_MAIN) && D_MAIN.Responds()) { if (command == c_exit) { exitMIDlet(); } if (command == c_history) { switchDisplayable(null, getL_history()); Stack st = D_MAIN.getEqHS(); Enumeration en = st.elements(); l_history.deleteAll(); while (en.hasMoreElements()) { l_history.append((String) en.nextElement(), null); } } if (command == c_tovars) { getL_vars().deleteAll(); StringBuffer sb; Enumeration values = D_MAIN.getEqVars().elements(); Enumeration names = D_MAIN.getEqVars().keys(); String name; Real value; while ((values.hasMoreElements()) && (names.hasMoreElements())) { name = String.valueOf(names.nextElement()); value = new Real(String.valueOf((values.nextElement()))); Real.NumberFormat n = new Real.NumberFormat(); n.maxwidth = 17; n.fse = Real.NumberFormat.FSE_NONE; sb = new StringBuffer(value.toString(n)); if (chartools.contains(sb, 'e')) { StringBuffer ev = new StringBuffer(); for (int i = sb.length() - 1; i > -1; --i) { if (sb.charAt(i) == 'e') { sb.deleteCharAt(i); break; } ev.append(sb.charAt(i)); sb.deleteCharAt(i); } ev.reverse(); sb.append(" * 10^(" + ev + ")"); if ((!(sb.equals(new StringBuffer("")))) && (!(name.equals(""))) && (!(sb.equals(new StringBuffer("null")))) && (!(name.equals("null")))) { l_vars.append(name + " = " + sb.toString(), null); } } else { if ((!(sb.equals(new StringBuffer("")))) && (!(name.equals(""))) && (!(sb.equals(new StringBuffer("null")))) && (!(name.equals("null")))) { getL_vars().append(name + " = " + sb.toString(), null); } } } switchDisplayable(null, getL_vars()); } } if (displayable == f_welcome) { if (command == c_canvas) { switchDisplayable(null, D_MAIN); } } else if (displayable == form) { if (command == c_history) { } else if (command == c_tovars) { } } else if (displayable == l_history) { if (command == List.SELECT_COMMAND) { l_historyAction(); } else if (command == c_canvas) { switchDisplayable(null, D_MAIN); } else if (command == c_insert) { if (l_history.size() != 0) { StringBuffer sb = new StringBuffer(); String his = l_history.getString(l_history.getSelectedIndex()); boolean p_end = false; for (int i = 0; i < his.length(); i++) { if (his.charAt(i) == '=') { break; } if (p_end) { sb.append(his.charAt(i)); } if (his.charAt(i) == ':') { p_end = true; } } sb.deleteCharAt(sb.length() - 1); D_MAIN.appendDispCont(" " + sb.toString()); } switchDisplayable(null, D_MAIN); D_MAIN.repaint(); } } else if (displayable == l_vars) { if (command == List.SELECT_COMMAND) { l_varsAction(); } else if (command == c_canvas) { switchDisplayable(null, D_MAIN); } else if (command == c_delvar) { try { StringBuffer sb = new StringBuffer(); String his = l_vars.getString(l_vars.getSelectedIndex()); for (int i = 0; i < his.length(); i++) { if (his.charAt(i) == '=') { break; } sb.append(his.charAt(i)); } D_MAIN.deletevar(sb.toString().trim()); l_vars.delete(l_vars.getSelectedIndex()); } catch (error er) { switchDisplayable(null, getA_error()); a_error.setString(er.getMessage()); } } else if (command == c_insert) { StringBuffer sb = new StringBuffer(); String his = l_vars.getString(l_vars.getSelectedIndex()); for (int i = 0; i < his.length(); i++) { if (his.charAt(i) == '=') { break; } sb.append(his.charAt(i)); } D_MAIN.appendDispCont(sb.toString()); switchDisplayable(null, D_MAIN); D_MAIN.repaint(); } } }
public static void find_all_paths( AbstractVariable x, AbstractVariable end, Vector path_set, Stack path_stack) throws RemoteException { int i; path_stack.push(x); if (x == end) { // Construct a path from the beginning to the end, using what's on the stack. AbstractVariable[] path = new AbstractVariable[path_stack.size()]; // System.err.println( "\tFound path: " ); Enumeration e; for (i = 0, e = path_stack.elements(); e.hasMoreElements(); i++) { path[i] = (AbstractVariable) e.nextElement(); // System.err.print( path[i].get_name()+" " ); } // System.err.println(""); path_set.addElement(path); path_stack.pop(); return; } AbstractVariable[] parents = x.get_parents(); for (i = 0; i < parents.length; i++) { Enumeration e = path_stack.elements(); boolean is_on_stack = false; while (e.hasMoreElements()) if (e.nextElement() == parents[i]) { is_on_stack = true; break; } if (!is_on_stack) find_all_paths(parents[i], end, path_set, path_stack); } AbstractVariable[] children = x.get_children(); for (i = 0; i < children.length; i++) { Enumeration e = path_stack.elements(); boolean is_on_stack = false; while (e.hasMoreElements()) if (e.nextElement() == children[i]) { is_on_stack = true; break; } if (!is_on_stack) find_all_paths(children[i], end, path_set, path_stack); } path_stack.pop(); }
private synchronized Stack getThreadStack() { if (Thread.currentThread() != cached_thread) { cached_thread = Thread.currentThread(); cached_stack = (Stack) stacks.get(cached_thread); if (cached_stack == null) { cached_stack = new Stack(); stacks.put(cached_thread, cached_stack); } change_count++; // Collect more often if there are many threads, but not *too* often int size = Math.max(1, stacks.size()); // should be >1 b/c always live threads, but... if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT / size)) { Stack dead_stacks = new Stack(); for (Enumeration e = stacks.keys(); e.hasMoreElements(); ) { Thread t = (Thread) e.nextElement(); if (!t.isAlive()) dead_stacks.push(t); } for (Enumeration e = dead_stacks.elements(); e.hasMoreElements(); ) { Thread t = (Thread) e.nextElement(); stacks.remove(t); } change_count = 0; } } return cached_stack; }
private String resolvePath(String path) { if (path.charAt(0) != '/') { path = currentDir + "/" + path; } StringTokenizer pathSt = new StringTokenizer(path, "/"); Stack segments = new Stack(); while (pathSt.hasMoreTokens()) { String segment = pathSt.nextToken(); if (segment.equals("..")) { if (!segments.empty()) { segments.pop(); } } else if (segment.equals(".")) { // skip } else { segments.push(segment); } } StringBuilder pathBuf = new StringBuilder("/"); Enumeration segmentsEn = segments.elements(); while (segmentsEn.hasMoreElements()) { pathBuf.append(segmentsEn.nextElement()); if (segmentsEn.hasMoreElements()) { pathBuf.append("/"); } } return pathBuf.toString(); }
/** * Returns null if the belief network <tt>bn</tt> has no directed cycles. Otherwise returns an * <tt>Enumeration</tt> of variables, which begins at a variable contained in a directed cycle, * leads through the cycle (parent by parent), and ends at that same variable. */ public static Enumeration has_directed_cycle(AbstractBeliefNetwork bn) throws RemoteException { // If is_ancestor returns true, then this stack contains a path from some variable all the // way back to that same variable. If is_ancestor returns false, then this stack remains empty. Stack path_stack = new Stack(); AbstractVariable[] u = bn.get_variables(); for (int i = 0; i < u.length; i++) { if (is_ancestor(u[i], u[i], path_stack)) { path_stack.push(u[i]); return path_stack.elements(); } } return null; }
// public String parseSchema(TreeNode node, String key) throws IOException { // if (node.isObject()) { // type.push(key); // Iterator<String> fields = node.fieldNames(); // List<String> s = new ArrayList<String>(); // while (fields.hasNext()) { // String field = fields.next(); // if (node.at("/type").toString().contains("object")) { // // System.out.println("true"); // key = parseSchema(node.get(field), field); // // } else { // // System.out.println("false"); // // System.out.println(type.toString()+":"+field); // // s.add(node.a); // key = parseSchema(node.get(field), field); // } // } // types.put(type.toString(), s); // type.pop(); // } // // return key; // } public String printAll(JsonNode node, String f) throws JsonProcessingException, IOException, JSONException { System.out.println("---"); ObjectNode json = factory.objectNode(); if (!f.equals("properties")) { type.push(f); } Iterator<String> fieldNames = node.fieldNames(); Enumeration<String> e = type.elements(); while (e.hasMoreElements()) { e.nextElement(); } String uri = type.toString() .replaceAll(", ", ".") .replaceFirst(".schema.", ".community.") .replaceAll("[\\[\\]]", ""); json.put("uri", uri); ArrayNode index_mode = factory.arrayNode(); index_mode.add("dm4.core.fulltext"); index_mode.add("dm4.core.fulltext_key"); json.set("index_mode_uris", index_mode); json.put("data_type_uri", "dm.core.text"); ArrayNode array = factory.arrayNode(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode fieldValue = node.get(fieldName); if (node.findParent("description").get("description") != null) { json.set("value", node.findParent("description").get("description")); } if (fieldValue.isObject()) { ObjectNode assoc = factory.objectNode(); assoc.put( "child_type_uri", uri + "." + printAll(fieldValue, fieldName).replaceAll("\n", "")); assoc.put("child_cardinality_uri", "dm4.core.one"); assoc.put("parent_cardinality_uri", "dm4.core.one"); assoc.put("assoc_type_uri", "dm4.core.composition_def"); // json.append(("composite: "+uri+"."+printAll(fieldValue, fieldName)).replaceAll("\n", // "")+"\n"); array.add(assoc); json.put("data_type_uri", "dm4.core.composite"); json.set("assoc_defs", array); } else { // String value = fieldValue.toString(); if (fieldName.equals("description")) { json.set("value", fieldValue); // json.append("\"value\"" + " : " + value+",\n"); } if (fieldName.equals("enum")) { // json.append("\"options\"" + " : " + value+",\n"); json.set("enum", fieldValue); } } } // json.append("}"); System.out.println("xxx"); System.out.println(m.writerWithDefaultPrettyPrinter().writeValueAsString(json)); TopicTypeModel t = new TopicTypeModel(new JSONObject(json.toString())); System.err.println(t.getUri()); System.err.println(t.getAssocDefs()); if (!f.equals("properties")) { return type.pop(); } else { return ""; } }