public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { String strId = ""; String strBody = ""; // Parse the xml and read data (page id and article body) // Using XOM library Builder builder = new Builder(); try { Document doc = builder.build(value.toString(), null); Nodes nodeId = doc.query("//eecs485_article_id"); strId = nodeId.get(0).getChild(0).getValue(); Nodes nodeBody = doc.query("//eecs485_article_body"); strBody = nodeBody.get(0).getChild(0).getValue(); } catch (ParsingException ex) { System.out.println("Not well-formed."); System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println("io exception"); } // Tokenize document body Pattern pattern = Pattern.compile("\\w+"); Matcher matcher = pattern.matcher(strBody); while (matcher.find()) { // Write the parsed token // key = term, docid value = 1 context.write(new Text(matcher.group() + "," + strId), one); } }
/* * Inserts a new node into the tree. */ public void insertNode(int key, double value) { /* * Create a new node */ Nodes newNode = new Nodes(key, value); if (root == null) { root = newNode; } else { Nodes current = root; Nodes parent = null; while (current != null) { if (key < current.iData) { parent = current; current = current.leftChild; } else { parent = current; current = current.rightChild; } } if (key < parent.iData) parent.leftChild = newNode; else parent.rightChild = newNode; } }
@Test public void getNodes() { Node n0 = Nodes.addNode(new Node("n0", Node.Type.NAMENODE)); Node n1 = Nodes.addNode(new Node("n1", Node.Type.DATANODE)); Node n2 = Nodes.addNode(new Node("n2", Node.Type.DATANODE)); assertEquals(Arrays.asList(n0, n1, n2), Nodes.getNodes()); }
@Override public void refreshMark() { final EditorArea edit = getEditor(); go.setEnabled(edit.script || edit.xquery && !gui.gprop.is(GUIProp.EXECRT)); final Nodes mrk = gui.context.marked; filter.setEnabled(!gui.gprop.is(GUIProp.FILTERRT) && mrk != null && mrk.size() != 0); }
/** * Checks if data can be updated. * * @param n node instance * @param no disallowed node types * @return result of check */ static boolean updatable(final Nodes n, final int... no) { if (n == null || (no.length == 0 ? n.size() < 1 : n.size() != 1)) return false; final int k = n.data.kind(n.pres[0]); for (final int i : no) if (k == i) return false; return true; }
@Test public void getNodes_by_type() { Node nn = Nodes.addNode(new Node("nn", Node.Type.NAMENODE)); Node dn0 = Nodes.addNode(new Node("dn0", Node.Type.DATANODE)); Node dn1 = Nodes.addNode(new Node("dn1", Node.Type.DATANODE)); assertEquals(Arrays.asList(nn), Nodes.getNodes(Node.Type.NAMENODE)); assertEquals(Arrays.asList(dn0, dn1), Nodes.getNodes(Node.Type.DATANODE)); }
public static String getAttributeValue(Nodes attributes) { if (attributes.hasAny()) { Node attribute = attributes.get(0); if (attribute instanceof Attribute) { return attribute.getValue(); } } return ""; }
public static Nodes rndNodes(int max) { int nnodes = rndInt(0, 5); Nodes ns = new Nodes(); for (int i = nnodes; i >= 0; i--) { Node n = rndNode(); ns.getNodes().add(n); } return ns; }
private com.relteq.sirius.jaxb.Outputs restoreOutputs(Nodes db_node) throws TorqueException { Criteria crit = new Criteria(); crit.add(LinksPeer.NETWORK_ID, db_node.getNetworkId()); crit.add(LinksPeer.BEG_NODE_ID, db_node.getId()); @SuppressWarnings("unchecked") List<Links> db_link_l = LinksPeer.doSelect(crit); com.relteq.sirius.jaxb.Outputs outputs = factory.createOutputs(); for (Links db_link : db_link_l) outputs.getOutput().add(restoreOutput(db_link)); return outputs; }
@Override public void execute(final GUI gui) { final StringBuilder sb = new StringBuilder(); final Nodes n = gui.context.copied; for (int i = 0; i < n.size(); ++i) { if (i > 0) sb.append(','); sb.append(openPre(n, i)); } gui.context.copied = null; gui.execute(new XQuery("insert nodes (" + sb + ") into " + openPre(gui.context.marked, 0))); }
@Override public void execute(final GUI gui) { final Context ctx = gui.context; Nodes marked = ctx.marked; if (marked.size() == 0) { final int pre = gui.context.focused; if (pre == -1) return; marked = new Nodes(pre, ctx.data()); } gui.notify.context(marked, false, null); }
@Test public void getNodes_by_state() { Node n0 = Nodes.addNode(new Node("n0")); Node n1 = Nodes.addNode(new Node("n1", Node.Type.DATANODE)); Node n2 = Nodes.addNode(new Node("n2", Node.Type.DATANODE)); n1.state = Node.State.RUNNING; n2.state = Node.State.RUNNING; assertEquals(Arrays.asList(n0), Nodes.getNodes(Node.State.IDLE)); assertEquals(Arrays.asList(n1, n2), Nodes.getNodes(Node.State.RUNNING)); }
@Test public void toJson_fromJson() { Nodes.frameworkId = "id"; Node n0 = Nodes.addNode(new Node("n0")); Node n1 = Nodes.addNode(new Node("n1", Node.Type.DATANODE)); JSONObject json = Nodes.toJson(); Nodes.fromJson(json); assertEquals("id", Nodes.frameworkId); assertEquals(Arrays.asList(n0, n1), Nodes.getNodes()); }
/** * Returns a {@link Nodes} object conatining the nodes config data. * * @param nodesFile the source file * @param format * @return an instance of {@link Nodes} */ public Nodes getNodes(final File nodesFile, final Nodes.Format format) throws NodeFileParserException { final Long modtime = nodesFile.lastModified(); if (null == nodesCache.get(nodesFile) || !modtime.equals(nodesFileTimes.get(nodesFile))) { final Nodes nodes = Nodes.create(nodesFile, format); nodes.addFrameworkNode(this); nodesFileTimes.put(nodesFile, modtime); nodesCache.put(nodesFile, nodes); return nodes; } else { return nodesCache.get(nodesFile); } }
public Node addNode(Role role) { Node2 n2 = nodes.getNode2(role); if (null == n2) { n2 = new Node2(role, this); nodes.addNode2(n2); } boolean f = false; for (int i = 0; i < headNum; i++) { if (head[i].getFirst().equals(n2)) f = true; } if (false == f) addHead(n2); return n2; }
public Node addNode(ComplexRole cr) { Node3 n3 = nodes.getNode3(cr); if (null == n3) { n3 = new Node3(cr, this); nodes.addNode3(n3); } boolean f = false; for (int i = 0; i < headNum; i++) { if (head[i].getFirst().equals(n3)) f = true; } if (false == f) addHead(n3); return n3; }
private com.relteq.sirius.jaxb.Node restoreNode(Nodes db_node) throws TorqueException { com.relteq.sirius.jaxb.Node node = factory.createNode(); node.setId(id2str(db_node.getId())); node.setInSynch(db_node.getInSynch()); NodeType db_nodetype = NodeTypePeer.retrieveByPK(db_node.getId(), db_node.getNetworkId()); node.setType(db_nodetype.getType()); node.setRoadwayMarkers(restoreRoadwayMarkers(db_node)); node.setInputs(restoreInputs(db_node)); node.setOutputs(restoreOutputs(db_node)); node.setPosition(restorePosition(db_node.getGeom())); return node; }
public Node addNode(TMSPrincipal principal) { // TODO Auto-generated method stub Node1 n1 = nodes.getNode1(principal); if (null == n1) { n1 = new Node1(principal, this); nodes.addNode1(n1); } boolean f = false; for (int i = 0; i < headNum; i++) { if (head[i].getFirst().equals(n1)) f = true; } if (false == f) addHead(n1); return n1; }
@Override public void execute(final GUI gui) { if (!BaseXDialog.confirm(gui, DELETE_NODES)) return; final StringBuilder sb = new StringBuilder(); final Nodes n = gui.context.marked; for (int i = 0; i < n.size(); ++i) { if (i > 0) sb.append(','); sb.append(openPre(n, i)); } gui.context.marked = new Nodes(n.data); gui.context.copied = null; gui.context.focused = -1; gui.execute(new XQuery("delete nodes (" + sb + ')')); }
/** * Notifies all views of a selection change. The mode flag determines what happens: * * <ul> * <li>0: set currently focused node as marked node * <li>1: add currently focused node * <li>2: toggle currently focused node * </ul> * * @param mode mark mode * @param vw the calling view */ public void mark(final int mode, final View vw) { final int f = gui.context.focused; if (f == -1) return; final Context ctx = gui.context; Nodes nodes = ctx.marked; if (mode == 0) { nodes = new Nodes(f, ctx.data()); } else if (mode == 1) { nodes.union(new int[] {f}); } else { nodes.toggle(f); } mark(nodes, vw); }
/** * Notifies all views of a context change. * * @param nodes new context set (may be {@code null} if root nodes are addressed) * @param quick quick switch * @param vw the calling view */ public void context(final Nodes nodes, final boolean quick, final View vw) { final Context ctx = gui.context; // add new entry if current node set has not been cached yet final Nodes newn = nodes.checkRoot(); final Nodes empty = new Nodes(new int[0], ctx.data(), ctx.marked.ftpos); final Nodes curr = quick ? ctx.current() : null; final Nodes cmp = quick ? curr : ctx.marked; if (cont[hist] == null ? cmp != null : cmp == null || !cont[hist].sameAs(cmp)) { checkHist(); if (quick) { // store history entry queries[hist] = ""; marked[hist] = new Nodes(ctx.data()); // add current entry cont[++hist] = curr; } else { // store history entry final String in = gui.input.getText(); queries[hist] = in; marked[hist] = ctx.marked; // add current entry cont[++hist] = newn; queries[hist] = in; marked[hist] = empty; } histsize = hist; } ctx.set(newn, empty); for (final View v : view) if (v != vw && v.visible()) v.refreshContext(true, quick); gui.refreshControls(); }
/** * Notifies all views of a selection change. * * @param mark marked nodes * @param vw the calling view */ public void mark(final Nodes mark, final View vw) { final Context ctx = gui.context; ctx.marked = mark; for (final View v : view) if (v != vw && v.visible()) v.refreshMark(); gui.filter.setEnabled(mark.size() != 0); gui.refreshControls(); }
@Override final <P_IN> Node<Long> evaluateToNode( PipelineHelper<Long> helper, Spliterator<P_IN> spliterator, boolean flattenTree, IntFunction<Long[]> generator) { return Nodes.collectLong(helper, spliterator, flattenTree); }
public void loadLocationsAsync(String kml) { List<LotLocation> locations = new ArrayList<LotLocation>(); try { XMLReader parser = XMLReaderFactory.createXMLReader("org.ccil.cowan.tagsoup.Parser"); InputStream is = new ByteArrayInputStream(kml.getBytes()); // build out an XML document using TagSoup Document doc = new Builder(parser).build(is); // set the ns of the document as the XPathContext or we will not find the elements when we // attempt to parse XPathContext context = new XPathContext("ns", "http://www.w3.org/1999/xhtml"); // get the Placemark nodes within the data Nodes nodes = doc.query(".//ns:Placemark", context); for (int index = 0; index < nodes.size(); index++) { LotLocation placemark = new LotLocation(); Node placemarkNode = nodes.get(index); Node nameNode = placemarkNode.query("ns:name", context).get(0); if (nameNode != null) placemark.setLocation(nameNode.getValue()); Node descriptionNode = placemarkNode.query("ns:description", context).get(0); if (descriptionNode != null) placemark.setDescription(descriptionNode.getValue()); Node lnglatNode = placemarkNode.query("ns:Point/ns:coordinates", context).get(0); if (lnglatNode != null) { // get longitude,latitude,altitude, per KML spec String[] points = lnglatNode.getValue().split(","); placemark.setPoint( new LatLng( Double.parseDouble(points[1].trim()), Double.parseDouble(points[0].trim()))); } locations.add(placemark); } // spin off a new thread and load locations new LoadLocationsTask().execute(locations); } catch (Exception e) { Log.e("LoadLocationsTask", "Failure attempting to load locations", e); } }
@Test public void addNode() { Node nn = Nodes.addNode(new Node("nn", Node.Type.NAMENODE)); assertEquals(Arrays.asList(nn), Nodes.getNodes()); // duplicate id try { Nodes.addNode(new Node("nn", Node.Type.DATANODE)); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage(), e.getMessage().contains("duplicate")); } // second namenode try { Nodes.addNode(new Node("nn1", Node.Type.NAMENODE)); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage(), e.getMessage().contains("second")); } }
public static void load(File configuration) { FileConfiguration config = YamlConfiguration.loadConfiguration(configuration); for (Nodes n : Nodes.values()) if (!n.getNode().isEmpty()) if (config.get(n.getNode()) != null) n.setValue(config.get(n.getNode())); }
private com.relteq.sirius.jaxb.RoadwayMarkers restoreRoadwayMarkers(Nodes db_node) throws TorqueException { @SuppressWarnings("unchecked") List<NodeName> db_nname_l = db_node.getNodeNames(); @SuppressWarnings("unchecked") List<Postmiles> db_postmile_l = db_node.getPostmiless(); if (db_nname_l.isEmpty() && db_postmile_l.isEmpty()) return null; com.relteq.sirius.jaxb.RoadwayMarkers markers = factory.createRoadwayMarkers(); for (NodeName db_nname : db_nname_l) { com.relteq.sirius.jaxb.Marker marker = factory.createMarker(); marker.setName(db_nname.getName()); markers.getMarker().add(marker); } for (Postmiles db_postmile : db_postmile_l) { com.relteq.sirius.jaxb.Marker marker = factory.createMarker(); marker.setName(db_postmile.getPostmileHighways().getHighwayName()); marker.setPostmile(db_postmile.getPostmile()); markers.getMarker().add(marker); } return markers; }
public static void main(String[] args) { UserSession.set(new User("seeded-org-id-1", "seeded-test-user-1", "Password1!")); try { NodeService nodeService = new NodeServiceImpl("http://localhost:8081/oec"); CreateNodeType createNode = new CreateNodeType(); createNode.setNetworkDomainId("1c813510-216a-434d-bd07-226ee5424ca3"); createNode.setName("abc"); createNode.setStatus("ENABLED"); createNode.setIpv4Address("10.5.2.19"); createNode.setConnectionLimit(BigInteger.valueOf(100l)); createNode.setConnectionRateLimit(BigInteger.valueOf(100l)); ResponseType response = nodeService.createNode(createNode); System.out.println(response.getMessage()); Nodes nodes = nodeService.listNodes(100, 1, OrderBy.EMPTY, Filter.EMPTY); for (NodeType node : nodes.getNode()) { System.out.println(node.getId() + "=" + node.getName()); } EditNode editNode = new EditNode(); editNode.setId(nodes.getNode().get(1).getId()); editNode.setStatus("DISABLED"); editNode.setConnectionLimit(BigInteger.valueOf(10l)); editNode.setConnectionRateLimit(BigInteger.valueOf(10l)); response = nodeService.editNode(editNode); System.out.println(response.getMessage()); NodeType node = nodeService.getNode(nodes.getNode().get(1).getId()); System.out.println(node.getId() + "," + node.getName() + "," + node.getStatus()); response = nodeService.deleteNode(node.getId()); System.out.println(response.getMessage()); } catch (BadRequestException e) { ResponseType response = e.getResponse(); System.out.println("bad request: " + response.getMessage()); } }
public VariableLike getVariableByName(Referable referable, String variableName) throws NavigationException { Objects.requireNonNull(variableName, "VariableName must not be null!"); NodeHelper element = new NodeHelper(referable); String elementName = element.getLocalName(); if ("scope".equals(elementName) || "process".equals(elementName)) { Nodes variable = element .toXOM() .query("./bpel:variables/bpel:variable[@name='" + variableName + "']", CONTEXT); if (variable != null && !variable.isEmpty()) { return new VariableElement(variable.get(0), processContainer); } if ("process".equals(elementName)) { throw new NavigationException("Variable does not exist."); } } if ("onEvent".equals(elementName)) { if (variableName.equals(element.getAttribute("variable"))) { return new OnEventElement(element.toXOM(), processContainer); } } if ("catch".equals(elementName)) { if (variableName.equals(element.getAttribute("faultVariable"))) { return new CatchElement(element.toXOM(), processContainer); } } if ("forEach".equals(elementName)) { if (variableName.equals(element.getAttribute("counterName"))) { return new ForEachVariable(element.toXOM(), processContainer); } } return getVariableByName(element.getParent(), variableName); }
@Test public void expandExpr() { Nodes.addNode(new Node("nn", Node.Type.NAMENODE)); Nodes.addNode(new Node("dn0", Node.Type.DATANODE)); Nodes.addNode(new Node("dn1", Node.Type.DATANODE)); // id list assertEquals(Arrays.asList("nn", "dn2"), Nodes.expandExpr("nn,dn2")); // wildcard assertEquals(Arrays.asList("dn0", "dn1"), Nodes.expandExpr("dn*")); assertEquals(Arrays.asList("nn", "dn0", "dn1"), Nodes.expandExpr("*")); // range assertEquals(Arrays.asList("1", "2", "3"), Nodes.expandExpr("1..3")); assertEquals(Arrays.asList("dn1", "dn2", "dn3"), Nodes.expandExpr("dn1..3")); }