/** * Adds the item to this stack. * * @param item the item to add */ public void push(Item item) { Node<Item> oldfirst = first; first = new Node<Item>(); first.item = item; first.next = oldfirst; N++; }
// T = LITERAL | '${' V '}' private Node T() throws ScanException { Token t = getCurentToken(); switch (t.type) { case LITERAL: advanceTokenPointer(); return new Node(Node.Type.LITERAL, t.payload); case CURLY_LEFT: advanceTokenPointer(); Node inner = E(); Token right = getCurentToken(); expectCurlyRight(right); advanceTokenPointer(); Node curlyLeft = new Node(Node.Type.LITERAL, CoreConstants.LEFT_ACCOLADE); curlyLeft.next = inner; Node curlyRightNode = new Node(Node.Type.LITERAL, CoreConstants.RIGHT_ACCOLADE); if (inner == null) curlyLeft.next = curlyRightNode; else appendNode(inner, curlyRightNode); return curlyLeft; case START: advanceTokenPointer(); Node v = V(); Token w = getCurentToken(); expectCurlyRight(w); advanceTokenPointer(); return v; default: return null; } }
// insert an item at current position in the linked list public void insert(T item) { curr.setNext(new Node<T>(item, curr.getNext())); if (tail == curr) { tail = curr.getNext(); } len++; }
private void getNewNodes() { Vector levelNodes = new Vector(); Vector nextLevelNodes = new Vector(); Vector passedNodes = new Vector(); levelNodes.add(centerNode.name); for (int level = 0; level <= Config.navigationDepth; level++) { for (Enumeration e = levelNodes.elements(); e.hasMoreElements(); ) { String nodeName = (String) e.nextElement(); if (!passedNodes.contains(nodeName)) { passedNodes.add(nodeName); Node node = graph.nodeFromName(nodeName); if (node == null) { node = xmlReader.getNode(nodeName); graph.add(node); } node.passed = true; Set linkSet = node.links.keySet(); for (Iterator it = linkSet.iterator(); it.hasNext(); ) { String neighbourName = (String) it.next(); if (!passedNodes.contains(neighbourName) && !levelNodes.contains(neighbourName)) { nextLevelNodes.add(neighbourName); } } } } levelNodes = nextLevelNodes; nextLevelNodes = new Vector(); } }
public boolean removeNode(T data) { if (null == head) return false; if (head.data.equals(data)) { Node n = head; head = head.next; head.previous = null; // VB: This will throw NULL Pointer exception of there is only one elemnt in the // linkedlist before removal n = null; return true; } if (tail.data.equals(data)) { Node n = tail; tail = tail.previous; // VB : Same here tail.next = null; n = null; return true; } Node n = head; while (null != n) { if (n.data.equals(data)) { n.previous.next = n.next; n.next.previous = n.previous; n = null; return true; } n = n.next; } return false; }
/** * generate a dot-graph and exports it to the given file * * @param graph * @param filepath */ public static void generateDigraphHITSAndPageRank(HashSet<Node> graph, String filepath) { System.out.println("generate digraph HITS and PageRank"); StringBuilder sb = new StringBuilder(); sb.append("digraph wikigraph {"); sb.append(System.getProperty("line.separator")); ArrayList<Node> list = new ArrayList<Node>(graph); /** generate links */ for (Node n : list) { sb.append(n.getDOTHITSAndPageRank()); } sb.append("}"); /** write file */ try { FileWriter.writeFile(filepath + "_hits_and_pagerank.dot", sb.toString()); } catch (IOException e) { e.printStackTrace(); } }
private Node getNode(int index) { Node node = first; for (int i = 0; i < index; i++) { node = node.getNext(); } return node; }
public IXArchElement cloneElement(int depth) { synchronized (DOMUtils.getDOMLock(elt)) { Document doc = elt.getOwnerDocument(); if (depth == 0) { Element cloneElt = (Element) elt.cloneNode(false); cloneElt = (Element) doc.importNode(cloneElt, true); AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt); cloneImpl.setXArch(getXArch()); return cloneImpl; } else if (depth == 1) { Element cloneElt = (Element) elt.cloneNode(false); cloneElt = (Element) doc.importNode(cloneElt, true); AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt); cloneImpl.setXArch(getXArch()); NodeList nl = elt.getChildNodes(); int size = nl.getLength(); for (int i = 0; i < size; i++) { Node n = nl.item(i); Node cloneNode = (Node) n.cloneNode(false); cloneNode = doc.importNode(cloneNode, true); cloneElt.appendChild(cloneNode); } return cloneImpl; } else /* depth = infinity */ { Element cloneElt = (Element) elt.cloneNode(true); cloneElt = (Element) doc.importNode(cloneElt, true); AbstractChangeSetImpl cloneImpl = new AbstractChangeSetImpl(cloneElt); cloneImpl.setXArch(getXArch()); return cloneImpl; } } }
/** {@inheritDoc} */ public JCRNodeWrapper getFrozenVersionAsRegular(Node objectNode, JCRStoreProvider provider) throws RepositoryException { try { VersionHistory vh = objectNode .getSession() .getWorkspace() .getVersionManager() .getVersionHistory(objectNode.getPath()); Version v = null; if (versionLabel != null) { v = JCRVersionService.findVersionByLabel(vh, versionLabel); } if (v == null && versionDate != null) { v = JCRVersionService.findClosestVersion(vh, versionDate); } if (v == null) { throw new PathNotFoundException(); } Node frozen = v.getNode(Constants.JCR_FROZENNODE); return provider.getNodeWrapper(frozen, this); } catch (UnsupportedRepositoryOperationException e) { if (getVersionDate() == null && getVersionLabel() == null) { logger.error("Error while retrieving frozen version", e); } } return null; }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NodeList elementList; Node employeeNode; Node childNode; NodeList childNodes; int nodeType; String childName; java.util.List actual = new java.util.ArrayList(); java.util.List expected = new java.util.ArrayList(); expected.add("em"); expected.add("strong"); expected.add("code"); expected.add("sup"); expected.add("var"); expected.add("acronym"); doc = (Document) load("hc_staff", false); elementList = doc.getElementsByTagName("p"); employeeNode = elementList.item(1); childNodes = employeeNode.getChildNodes(); for (int indexN1006C = 0; indexN1006C < childNodes.getLength(); indexN1006C++) { childNode = (Node) childNodes.item(indexN1006C); nodeType = (int) childNode.getNodeType(); childName = childNode.getNodeName(); if (equals(1, nodeType)) { actual.add(childName); } else { assertEquals("textNodeType", 3, nodeType); } } assertEqualsAutoCase("element", "elementNames", expected, actual); }
private void add(Node<T> node, T key) { if (root == null) { root = new Node<>(key); } else { Node<T> current = root; boolean added = false; while (!added) { if (key.compareTo(current.key) < 0) { if (current.left == null) { current.left = new Node<>(key); added = true; } else { current = current.left; } } else { if (current.right == null) { current.right = new Node<>(key); added = true; } else { current = current.right; } } } } }
private void print(Node node) { if (node == null) { return; } System.out.print(node.getValue() + " -> "); print(node.getNext()); }
public Node add(Node node) { if (node.getNext() == null) { node.setNext(head.getNext()); } head.setNext(node); return node; }
public void ExpandCluster( ArrayList<Node> points, Node p, ArrayList<Node> neighborhood, ArrayList<Node> C, int eps, int MinPts) { ArrayList<Node> Cprime = null; Cprime.add(p); ArrayList<Node> ClusterSupreme = null; ClusterSupreme.addAll(Cprime); ClusterSupreme.addAll(neighborhood); for (int i = 0; i < neighborhood.size(); i++) { Node Pprime = neighborhood.get(i); if (Pprime.checkVisited() == false) { Pprime.markVisited(); ArrayList<Node> NeighborPtsPrime = null; NeighborPtsPrime = RegionQuery(Pprime, points, eps); if (NeighborPtsPrime.size() >= MinPts) { neighborhood.addAll(NeighborPtsPrime); } } if (checkCluster(Pprime, ClusterSupreme)) { Cprime.add(Pprime); } } }
public boolean addWord(String word) { if (word == null) { return false; } Node curNode = firstNode; for (int i = 0; i < word.length(); i++) { if (curNode.child == null) { curNode.child = new Node(word.charAt(i)); curNode = curNode.child; // System.out.println(curNode.data); } else { curNode = curNode.child; // System.out.println(curNode.data); while (curNode.data != word.charAt(i)) { if (curNode.sibling == null) { curNode.sibling = new Node(word.charAt(i)); curNode = curNode.sibling; // System.out.println(curNode.data+"Sibling"); } else { curNode = curNode.sibling; // System.out.println(curNode.data); } } } } curNode.child = new Node(endChar); curNode = curNode.child; // System.out.println(curNode.data); numWords++; return true; }
/** Derefernce a node which may be a functor node */ public static Node derefPossFunctor(Node node) { if (node instanceof Node_RuleVariable) { Node dnode = ((Node_RuleVariable) node).deref(); if (dnode.isVariable()) { // Problem with variable in return result "should never happen" throw new ReasonerException("Internal error in LP reasoner: variable in triple result"); } if (Functor.isFunctor(dnode)) { Functor f = (Functor) dnode.getLiteralValue(); Node[] fargs = f.getArgs(); boolean needCopy = false; for (Node farg : fargs) { if (farg.isVariable()) { needCopy = true; break; } } if (needCopy) { Node[] newArgs = new Node[fargs.length]; for (int i = 0; i < fargs.length; i++) { newArgs[i] = deref(fargs[i]); } dnode = Functor.makeFunctorNode(f.getName(), newArgs); } return dnode; } else { return dnode; } } else { return node; } }
/** * generate a dot-graph and exports it to the given file * * @param graph * @param filepath */ public static void generateDigraph(HashMap<String, Node> graph, String filepath) { System.out.println("generate digraph"); StringBuilder sb = new StringBuilder(); sb.append("digraph wikigraph {"); sb.append(System.getProperty("line.separator")); ArrayList<Node> list = new ArrayList<Node>(graph.values()); /** generate nodes and links */ for (Node n : list) { sb.append(n.getDOT()); } sb.append("}"); /** write file */ try { FileWriter.writeFile(filepath + ".dot", sb.toString()); } catch (IOException e) { e.printStackTrace(); } }
private Node getNewNode(final int val) { Node temp = new Node(); temp.left = null; temp.right = null; temp.data = val; return temp; }
private Node calculateAndGetNode( Gene gene, Set<Integer> ids, Set<Integer> realNodeIds, double[] distance) { int nodeId = gene.getValue(); Node node = NODES.get(nodeId); byte type = node.getType(); if (type != Node.SPACE) { if (ids.contains(nodeId)) { distance[0] += FEE_NODE_DUPLICATION; // Eğer id daha önceden kullanılmış ise ceza verilir. } else { ids.add(nodeId); } if (type == Node.REAL) { realNodeIds.add(nodeId); } else { distance[0] += FEE_VIRTUAL_NODE; } return node; } else { distance[0] += FEE_SPACE; } return null; }
public E take() throws InterruptedException { Node<E> x; final AtomicInteger count = this.count; final ReentrantLock takeLock = this.takeLock; takeLock.lockInterruptibly(); try { try { while (count.get() == 0) notEmpty.await(); } catch (InterruptedException ie) { notEmpty.signal(); // propagate to a non-interrupted thread throw ie; } x = extract(); if (count.getAndDecrement() > 1) notEmpty.signal(); } finally { takeLock.unlock(); } E result = x.item; // temporary clearence x.item = null; x.next = null; return result; }
public void run() { while (!_closed) { try { updateAll(); long now = System.currentTimeMillis(); if (inetAddrCacheMS > 0 && _nextResolveTime < now) { _nextResolveTime = now + inetAddrCacheMS; for (Node node : _all) { node.updateAddr(); } } // force check on master // otherwise master change may go unnoticed for a while if no write concern _mongo.getConnector().checkMaster(true, false); } catch (Exception e) { _logger.log(Level.WARNING, "couldn't do update pass", e); } try { Thread.sleep(updaterIntervalMS); } catch (InterruptedException ie) { } } }
public E poll() { final AtomicInteger count = this.count; if (count.get() == 0) return null; Node<E> x = null; final ReentrantLock takeLock = this.takeLock; takeLock.lock(); try { if (count.get() > 0) { x = extract(); if (count.getAndDecrement() > 1) notEmpty.signal(); } } finally { takeLock.unlock(); } if (x != null) { E result = x.item; // temporary clearence x.item = null; x.next = null; return result; } return null; }
public boolean removeNode(Node node) { if (null == node) { return false; } Node previousNode = node.previous; Node nextNode = node.next; // VB: Alternate way to check if head == node && tail == node if (null == previousNode) { if (null == nextNode) { tail = head = null; node = null; return true; } nextNode.previous = null; head = nextNode; node = null; return true; } // VB: Use else if which will improve readability if (null == nextNode) { previousNode.next = null; tail = previousNode; node = null; return true; } return false; }
public void insert(String s) { Conversion c = new Conversion(s); s = c.inToPost(); Stack1 stk = new Stack1(s.length()); s = s + "#"; int i = 0; char symbol = s.charAt(i); Node newNode; while (symbol != '#') { if (symbol >= '0' && symbol <= '9' || symbol >= 'A' && symbol <= 'Z' || symbol >= 'a' && symbol <= 'z') { newNode = new Node(symbol); stk.push(newNode); } else if (symbol == '+' || symbol == '-' || symbol == '/' || symbol == '*') { Node ptr1 = stk.pop(); Node ptr2 = stk.pop(); newNode = new Node(symbol); newNode.leftChild = ptr2; newNode.rightChild = ptr1; stk.push(newNode); } symbol = s.charAt(++i); } root = stk.pop(); }
public static void vol(int issue_length, NodeList issue_node) { for (int i = 0; i < issue_length; i++) { Node nnode = issue_node.item(i); if (nnode.getNodeType() == Element.ELEMENT_NODE) { Element enode = (Element) nnode; NodeList article_node = enode.getElementsByTagName("article"); int article_length = enode.getElementsByTagName("article").getLength(); for (int j = 0; j < article_length; j++) { Node m = article_node.item(j); if (m.getNodeType() == Element.ELEMENT_NODE) { Element f = (Element) m; String title = f.getElementsByTagName("title").item(0).getTextContent(); // System.out.println(title); if (title.equals("Research in Knowledge Base Management Systems.")) { // String article = f.getElementsByTagName("title").item(0).getTextContent(); String endPage = f.getElementsByTagName("endPage").item(0).getTextContent(); String initPage = f.getElementsByTagName("initPage").item(0).getTextContent(); String vol_element = enode.getElementsByTagName("volume").item(0).getTextContent(); String num_element = enode.getElementsByTagName("number").item(0).getTextContent(); // System.out.println("Title: "+ title); System.out.println("Volume: " + vol_element); System.out.println("Number: " + num_element); System.out.println("Init Page: " + initPage); System.out.println("End Page: " + endPage); } } } } } }
/* * Exercise1_3_20 */ public Item delete(int k) { if (isEmpty()) throw new RuntimeException("List is empty"); if (k < 0) k = 0; if (k > N) k = N; if (k == 0) return removeFirst(); if (k == N) return removeLast(); Node prev = null; Node current = first; for (int i = 1; i < k && current != null; i++) { prev = current; current = current.next; } if (current != null) { if (prev == null) first = current.next; else prev.next = current.next; if (current.next == null) last = prev; N--; return current.item; } else return null; }
public void addSomeNodes(int num) { for (int i = 0; i < num; i++) { Node foo = factory.getNode(); foo.setId(idCounter++); ns.addDefaultNode(foo); } }
public void addAttribute(NodeAttribute attr) { for (Node n : nodeList) { if (n instanceof RawNode) { n.addAttributes(attr); } } }
/** * Returns a sibling element that matches a given definition, or <tt>null</tt> if no match is * found. * * @param sibling the sibling DOM element to begin the search * @param target the node to search for * @return the matching element, or <tt>null</tt> if not found */ public static Element findSibling(Element sibling, XmlNode target) { String xmlName = target.getLocalName(); String xmlNamespace = target.getNamespace(); Node node = sibling; if (node == null) { return null; } while ((node = node.getNextSibling()) != null) { if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } Element element = (Element) node; if (!element.getLocalName().equals(xmlName)) { continue; } if (target.isNamespaceAware()) { String ns = element.getNamespaceURI(); if (ns == null) { if (xmlNamespace != null) { continue; } } else { if (!ns.equals(xmlNamespace)) { continue; } } } return element; } return null; }
public static ProcessDefinition createMilestoneProcessDefinition() { ProcessDefinition pd = new ProcessDefinition( new String[] { "start-state start", "fork fork", "state b", "milestone-node m", "state c", "state d", "join join", "end-state end" }, new String[] { "start --> fork", "fork --m--> b", "fork --d--> d", "b --> m", "m --> c", "c --> join", "d --> join", "join --> end" }); Node d = pd.getNode("d"); Delegation instantiatableDelegate = new Delegation(new MilestoneEvent("m", "../m")); Event event = new Event(Event.EVENTTYPE_NODE_LEAVE); d.addEvent(event); event.addAction(new Action(instantiatableDelegate)); pd.addDefinition(new ContextDefinition()); return pd; }