Exemplo n.º 1
0
 /**
  * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>.
  *
  * @param parent
  */
 public void makeElement(Node parent) {
   Document doc;
   if (parent instanceof Document) {
     doc = (Document) parent;
   } else {
     doc = parent.getOwnerDocument();
   }
   Element element = doc.createElement("table");
   int size;
   if (this.id_ != null) {
     URelaxer.setAttributePropertyByString(element, "id", this.id_);
   }
   if (this.xmlLang_ != null) {
     URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_);
   }
   if (this.caption_ != null) {
     this.caption_.makeElement(element);
   }
   size = this.tr_.size();
   for (int i = 0; i < size; i++) {
     FcTr value = (FcTr) this.tr_.get(i);
     value.makeElement(element);
   }
   parent.appendChild(element);
 }
Exemplo n.º 2
0
  /**
   * Reload the composite nodes of the circuit, this is recursive
   *
   * @param g the graphics that will paint the node
   * @throws CircuitLoadingException if the internal circuit can not be loaded
   */
  public void reloadCompositeNodes(Graphics g) throws CircuitLoadingException {
    for (iterNodes = this.nodes.iterator(); iterNodes.hasNext(); ) {
      Node n = iterNodes.next();

      if (n.getCategoryID() == Node.COMPOSITE) ((CompositeNode) n).reload(g);
    }
  }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
  /*
   * Output this item. Then, if the element has child elements, output each.
   */
  private void outputItem(Element e, PrintWriter out) {
    int chk = 0;
    HashMap collection = new HashMap();
    String key = null;
    Element collectionElement = null;
    log.fine("outputing item for " + e.getAttribute("name") + ":   " + e.getAttribute("query"));
    out.println("<item>");
    out.println("<name>" + e.getAttribute("name") + "</name>");
    if (e.getTagName().equalsIgnoreCase("collection")) {

      // change made by NETTY (change collectionlist to collection)
      out.println(
          "<query>collection="
              + e.getAttribute("col_id")
              + "&amp;xsl=metadata_to_html_full</query>");
    } else {
      out.println(
          "<query>owner=" + e.getAttribute("query") + "&amp;xsl=metadata_to_html_full</query>");
    }
    // now output children

    NodeList children = e.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
      Node child = children.item(i);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        chk++;
        outputItem((Element) child, out);
      }
    }

    out.println("</item>");
  }
Exemplo n.º 5
0
 /*
  * If the element contains an attribute 'makeOnly' with a value of 'true',
  * create a child element before any existing children which will display a node
  * which will display only the elements records.
  * Compute the query attribute, which is the appended result of all of the children
  * appended to this element name. If noQuery=true. then do not generate a query term
  * for this element.
  */
 String computeQuery(Element e) {
   String query = "";
   if (!(e.getAttribute("noQuery").equalsIgnoreCase("true"))) {
     query = e.getAttribute("name");
   }
   String makeOnly = e.getAttribute("makeOnly");
   boolean madeOnly = false;
   NodeList children = e.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     Node child = children.item(i);
     if (child.getNodeType() == Node.ELEMENT_NODE) {
       if (makeOnly.equalsIgnoreCase("true") && !madeOnly) {
         // need to make an ...-Only node and populate it
         String onlyTagName = e.getTagName() + "-Only";
         Element only = ((Document) dom.getNode()).createElement(onlyTagName);
         only.setAttribute("name", e.getAttribute("name") + "-Only");
         only.setAttribute("query", e.getAttribute("name"));
         e.insertBefore(only, child);
         i++;
         madeOnly = true;
       }
       if (query.length() > 0) {
         query += ",";
       }
       query += computeQuery((Element) child);
     }
   }
   log.info("setting query for " + e.getNodeName() + "   " + query);
   e.setAttribute("query", query);
   return query;
 }
Exemplo n.º 6
0
    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) {
        }
      }
    }
 protected void createNodesTable() throws Exception {
   table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display");
   thead();
   tr();
   createThs(
       "Node", "Health", "Count", "Errors", "Time since last up", "Current Threads", "Action");
   end();
   end();
   tbody();
   for (Node n : router.getClusterManager().getAllNodesByCluster(params.get("cluster"))) {
     tr();
     td();
     createLink(
         "" + n.getHost() + ":" + n.getPort(),
         "node",
         "show",
         createQueryString(
             "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
     end();
     createTds(
         n.isUp() ? "Up" : "Down",
         "" + n.getCounter(),
         String.format("%1$.2f%%", n.getErrors() * 100),
         formatDurationHMS(System.currentTimeMillis() - n.getLastUpTime()),
         "" + n.getThreads());
     td();
     createIcon("ui-icon-trash", "node", "delete", createQuery4Node(n));
     createIcon("ui-icon-circle-arrow-n", "node", "up", createQuery4Node(n));
     createIcon("ui-icon-circle-arrow-s", "node", "down", createQuery4Node(n));
     end();
     end();
   }
   end();
   end();
 }
Exemplo n.º 8
0
      public void onDocument(Document document, String xpath) throws XmlParserException {
        if (xpath.equals(XPATH_IPEAK)) {
          Node node = document.getFirstChild();

          // check whether we're getting the correct ipeak
          Node typeattribute = node.getAttributes().getNamedItem(PeakMLWriter.TYPE);
          if (typeattribute == null)
            throw new XmlParserException("Failed to locate the type attribute.");
          if (!typeattribute.getNodeValue().equals(PeakMLWriter.TYPE_BACKGROUNDION))
            throw new XmlParserException(
                "IPeak ("
                    + typeattribute.getNodeValue()
                    + ") is not of type: '"
                    + PeakMLWriter.TYPE_BACKGROUNDION
                    + "'");

          // parse this node as a mass chromatogram
          BackgroundIon<? extends Peak> backgroundion = parseBackgroundIon(node);
          if (backgroundion != null) peaks.add(backgroundion);

          //
          if (_listener != null && result.header != null && result.header.getNrPeaks() != 0)
            _listener.update((100. * index++) / result.header.getNrPeaks());
        } else if (xpath.equals(XPATH_HEADER)) {
          result.header = parseHeader(document.getFirstChild());
        }
      }
Exemplo n.º 9
0
  private static Header parseHeader(Node parent) throws XmlParserException {
    Header header = new Header();

    NodeList nodes = parent.getChildNodes();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      try {
        if (element.getTagName().equals("nrpeaks"))
          header.setNrPeaks(Integer.parseInt(element.getTextContent()));
        else if (element.getTagName().equals("date")) header.setDate(element.getTextContent());
        else if (element.getTagName().equals("owner")) header.setOwner(element.getTextContent());
        else if (element.getTagName().equals("description"))
          header.setDescription(element.getTextContent());
        else if (element.getTagName().equals("sets")) header.addSetInfos(parseSets(element));
        else if (element.getTagName().equals("measurements"))
          header.addMeasurementInfos(parseMeasurements(element));
        else if (element.getTagName().equals("annotations")) {
          Vector<Annotation> annotations = parseAnnotations(element);
          if (annotations != null)
            for (Annotation annotation : annotations) header.addAnnotation(annotation);
        }
      } catch (Exception e) {
        throw new XmlParserException(
            "Invalid value in header (" + element.getTagName() + "): '" + e.getMessage() + "'.");
      }
    }

    return header;
  }
Exemplo n.º 10
0
 void solve(int caseNum) {
   chars = in.next().toCharArray();
   Node tree = new Node();
   tree.stretch();
   System.out.println(caseNum);
   System.out.print(tree);
 }
  public void insert(int val, Node ptr) {
    // find correct position to insert
    int p = this.findKeyIndex(val);

    // if node is not full
    if (!full()) {
      // if val is larger than last key, increment p
      if (val > this.getKey(this.getLast())) {
        p++;
      }
      // insertion for simple case
      this.insertSimple(val, ptr, p);
    } else {
      // create a neighbor node with val and ptr
      Node split = new InternalNode(degree, null, val, ptr, this.getNext(), this);
      // set split to be next node of current node
      this.setNext(split);
      // get val to be inserted into parent
      int parentVal = this.redistribute();

      // if current node has a parent, insert value into parent
      if (this.getParent() != null) {
        this.getParent().getNode().insert(parentVal, split);
        // if no parent for current node, create a new root
      } else {
        Node newRoot = new InternalNode(degree, this, parentVal, split, null, null);
        // set parent references
        this.setParent(new Reference(newRoot, 0, false));
        split.setParent(new Reference(newRoot, 1, false));
      }
    }
  }
Exemplo n.º 12
0
  public static void main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    Scanner in = new Scanner(System.in);

    int N = in.nextInt();

    Node[] nodes = new Node[N];

    for (int i = 0; i < N; i++) {
      nodes[i] = new Node(i + 1);
    }

    for (int i = 0; i < N; i++) {
      int a = in.nextInt();
      int b = in.nextInt();

      Node n = nodes[i];

      if (a != -1) n.left = nodes[a - 1];
      if (b != -1) n.right = nodes[b - 1];
    }

    int T = in.nextInt();

    for (int i = 0; i < T; i++) {
      int K = in.nextInt();

      swap(nodes[0], K, 1);

      Inorder(nodes[0]);
      System.out.println("");
    }
  }
Exemplo n.º 13
0
 /**
  * Creates a DOM representation of the object. Result is appended to the Node <code>parent</code>.
  *
  * @param parent
  */
 public void makeElement(Node parent) {
   Document doc;
   if (parent instanceof Document) {
     doc = (Document) parent;
   } else {
     doc = parent.getOwnerDocument();
   }
   Element element = doc.createElement("fixme");
   int size;
   if (this.author_ != null) {
     URelaxer.setAttributePropertyByString(element, "author", this.author_);
   }
   if (this.id_ != null) {
     URelaxer.setAttributePropertyByString(element, "id", this.id_);
   }
   if (this.xmlLang_ != null) {
     URelaxer.setAttributePropertyByString(element, "xml:lang", this.xmlLang_);
   }
   size = this.content_.size();
   for (int i = 0; i < size; i++) {
     IFdContentMixMixed value = (IFdContentMixMixed) this.content_.get(i);
     value.makeElement(element);
   }
   parent.appendChild(element);
 }
Exemplo n.º 14
0
 @Override
 public void mouseClicked(MouseEvent me) {
   Element el = doc.getCharacterElement(viewToModel(me.getPoint()));
   if (el == null) return;
   AttributeSet as = el.getAttributes();
   if (as.isDefined("ip")) {
     String ip = (String) as.getAttribute("ip");
     ScriptException se = (ScriptException) as.getAttribute("exception");
     Node node = net.getAtIP(ip);
     if (node == null) {
       Utility.displayError("Error", "Computer does not exist");
       return;
     }
     String errorString =
         "--ERROR--\n"
             + "Error at line number "
             + se.getLineNumber()
             + " and column number "
             + se.getColumnNumber()
             + "\n"
             + se.getMessage();
     new ScriptDialog(
             parentFrame,
             str -> {
               if (str != null) {
                 node.setScript(str);
               }
             },
             node.getScript(),
             errorString)
         .setVisible(true);
   }
 }
Exemplo n.º 15
0
  // Lee la configuracion que se encuentra en conf/RegistryConf
  private void readConfXml() {
    try {
      File inputFile = new File("src/java/Conf/RegistryConf.xml");
      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(inputFile);
      doc.getDocumentElement().normalize();
      NodeList nList = doc.getElementsByTagName("RegistryConf");
      for (int i = 0; i < nList.getLength(); i++) {
        Node nNode = nList.item(i);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
          Element eElement = (Element) nNode;
          RegistryConf reg = new RegistryConf();
          String aux;
          int idSensor;
          int value;
          aux = eElement.getElementsByTagName("idSensor").item(0).getTextContent();
          idSensor = Integer.parseInt(aux);
          reg.setIdSensor(idSensor);

          aux = eElement.getElementsByTagName("saveType").item(0).getTextContent();
          reg.setSaveTypeString(aux);

          aux = eElement.getElementsByTagName("value").item(0).getTextContent();
          value = Integer.parseInt(aux);
          reg.setValue(value);

          registryConf.add(reg);
          lastRead.put(idSensor, 0);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 16
0
  private static SetInfo parseSet(Node parent) throws XmlParserException {
    String id = "";
    String type = "";
    String measurementids = null;

    NodeList nodes = parent.getChildNodes();
    Vector<SetInfo> sets = new Vector<SetInfo>();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      if (element.getTagName().equals("id")) id = element.getTextContent();
      else if (element.getTagName().equals("set")) sets.add(parseSet(element));
      else if (element.getTagName().equals("type")) type = element.getTextContent();
      else if (element.getTagName().equals("measurementids"))
        measurementids = element.getTextContent();
    }

    // create the set
    SetInfo set = new SetInfo(id, Integer.parseInt(type));
    if (measurementids != null) {
      int mids[] = ByteArray.toIntArray(Base64.decode(measurementids), ByteArray.ENDIAN_LITTLE, 32);
      for (int mid : mids) set.addMeasurementID(mid);
    }

    // add the children
    for (SetInfo s : sets) set.addChild(s);

    return set;
  }
Exemplo n.º 17
0
  /**
   * Search for the end of the maze using the frontier. Keep going until you find a solution or run
   * out of elements on the frontier.
   */
  private boolean solve() {
    Node startNode = new Node(startRow, startCol, null);
    placesToGo.add(startNode); // adding start pos to frontier
    while (placesToGo.hasNext()) {
      Node current = placesToGo.next();

      int[] xandy = current.getValue();
      int x = xandy[0];
      int y = xandy[1];
      if (maze[x][y] == 'E') {
        return true;
      }

      for (Node neigh : getNeighbors(current)) {
        placesToGo.add(neigh);
        maze[x][y] = '.';
      }

      if (animate) {
        wait(100);
        clearTerminal();
        System.out.println(toString());
      }
    }
    return false;
  }
Exemplo n.º 18
0
  private static MeasurementInfo parseMeasurement(Node parent) throws XmlParserException {
    String id = "";
    String label = "";
    String sampleid = "";
    Vector<FileInfo> files = null;
    Vector<ScanInfo> scans = null;

    NodeList nodes = parent.getChildNodes();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      if (element.getTagName().equals("id")) id = element.getTextContent();
      else if (element.getTagName().equals("label")) label = element.getTextContent();
      else if (element.getTagName().equals("sampleid")) sampleid = element.getTextContent();
      else if (element.getTagName().equals("scans")) scans = parseScans(node);
      else if (element.getTagName().equals("files")) files = parseFiles(node);
    }

    MeasurementInfo measurement = new MeasurementInfo(Integer.parseInt(id), sampleid);
    measurement.setLabel(label);
    measurement.addFileInfos(files);
    if (scans != null) measurement.addScanInfos(scans);

    return measurement;
  }
Exemplo n.º 19
0
  private void guardaRes(String resu, CliGol cliGol)
      throws ParserConfigurationException, SAXException, IOException {

    String[] nodos = {"NoHit", "Hit", "Buro"};

    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(resu));
    Document xml = db.parse(is);

    Element raiz = xml.getDocumentElement();

    String nombre = obtenerNombre(raiz);

    for (String s : nodos) {

      Node nodo =
          raiz.getElementsByTagName(s) == null ? null : raiz.getElementsByTagName(s).item(0);

      if (nodo != null) {
        String informacion = sustraerInformacionNodo(cliGol, nodo);

        guardarEnListas(nodo.getNodeName(), nombre + "," + informacion);
      }
    }
  }
Exemplo n.º 20
0
  @Override
  protected void initFlow(HierarchicalConfiguration flowCfg) {
    // int node = flowCfg.getInt("[@node]");

    int inLink = flowCfg.getInt("[@inLink]", -1);
    int outLink = flowCfg.getInt("[@outLink]", -1);

    // int next = flowCfg.getInt("[@next]");
    int no = flowCfg.getInt("[@no]", 0);

    Node node;
    Node next;

    if (inLink != -1) {
      Link link = idToLinkMap.get(Id.create(inLink, Link.class));

      node = link.getFromNode();
      next = link.getToNode();
    } else {
      Link link = idToLinkMap.get(Id.create(outLink, Link.class));

      node = link.getToNode();
      next = link.getFromNode();
    }

    int nodeId = Integer.parseInt(node.getId().toString());
    int nextId = Integer.parseInt(next.getId().toString());

    flows[nodeId] = new MATSimFlow(nodeId, inLink, outLink, nextId, no);
  }
Exemplo n.º 21
0
 /**
  * Obtain a new Node from a type that matches the given string. It will try to correctly detect
  * RealVar and constant nodes. The Node is cloned and initialized, so it can be used separatedly
  *
  * @param name The type of the requested Node. It must coincide with one of the class names of
  *     available Nodes, unless it represents a variable or constant terminal
  * @param currentGlobalDepth The depth of the requested Node in the Tree
  */
 public Node newNode(String name, int currentGlobalDepth) {
   System.out.println(name);
   Node outNode = null;
   if (name.startsWith("X")) {
     outNode = new RealVar(Integer.parseInt(name.substring("X".length(), name.length())));
   } else if (name.startsWith("angle")) {
     outNode = new Angle(Integer.parseInt(name.substring("angle".length(), name.length())));
   } else if (name.substring(0, 1).matches("\\d")) {
     outNode = new RealConstant(Double.parseDouble(name));
   } else if (name.equals("true")) {
     outNode = new LogicConstant(1);
   } else if (name.equals("false")) {
     outNode = new LogicConstant(0);
   } else {
     List<Node> all = new ArrayList<Node>();
     for (int i = 0; i < nodeSets.length; i++) {
       all.addAll(nodeSets[i].getAll());
     }
     for (Node n : all) {
       if (name.equals(n.name())) {
         try {
           outNode = (Node) n.clone();
         } catch (CloneNotSupportedException e) {
           Logger.log(e);
         }
         break;
       }
     }
   }
   outNode.setCurrentDepth(currentGlobalDepth);
   return outNode;
 }
Exemplo n.º 22
0
 private void updateDepthOfGoal(Node node, Node n, String type) {
   if (type.equals("compGoals")) {
     node.depthOfCompGoal = n.depthOfCompGoal;
   } else {
     node.depthOfUserGoal = n.depthOfUserGoal;
   }
 }
Exemplo n.º 23
0
 private void buildHierarchyDOM() {
   TransformerFactory factory = TransformerFactory.newInstance();
   StreamSource src =
       new StreamSource(
           this.getServletContext()
               .getResourceAsStream("/WEB-INF/classes/gpt/search/browse/ownerHierarchy.xml"));
   log.info("initializing src from stream " + src);
   try {
     Transformer t = factory.newTransformer();
     dom = new DOMResult();
     t.transform(src, dom);
     // now go thru tree, setting up the query attribute for each node
     Node tree = dom.getNode();
     NodeList children = tree.getChildNodes();
     log.info("dom tree contains " + children.getLength() + " nodes");
     for (int i = 0; i < children.getLength(); i++) {
       Node child = children.item(i);
       if (child.getNodeType() == Node.ELEMENT_NODE) {
         Element e = (Element) child;
         String query = computeQuery(e);
         e.setAttribute("query", query);
       }
     }
   } catch (Exception e) {
     log.severe("Could not init ownerHierarchy because exception thrown:");
     StringWriter sw = new StringWriter();
     e.printStackTrace(new PrintWriter(sw));
     log.severe(sw.toString());
   }
 }
Exemplo n.º 24
0
 public static void main(String args[]) {
   long pow = 1;
   for (int i = 0; i < tenPow.length; i++) {
     tenPow[i] = pow;
     pow = (pow * 10) % MOD;
   }
   String S = in.next();
   int N = in.nextInt();
   nodes = new Node[10];
   Node root = new Node(-1);
   for (int i = 0; i < S.length(); i++) {
     root.children.add(get((int) S.charAt(i) - '0'));
   }
   for (int i = 0; i < N; i++) {
     String Q = in.next();
     int d = (int) Q.charAt(0) - '0';
     if (nodes[d] != null) {
       Node nd = nodes[d];
       nodes[d] = null;
       for (int j = 3; j < Q.length(); j++) {
         nd.children.add(get((int) Q.charAt(j) - '0'));
       }
       if (Q.length() == 3) {
         nd.children.add(Node.EMPTY_LEAF);
       }
     }
   }
   out.println(root.ans());
 }
Exemplo n.º 25
0
  /**
   * Reads in a decision stored in XML.
   *
   * @param decN - the XML element.
   */
  public void fromXML(Element decN) {
    this.fromXML = true;

    RationaleDB db = RationaleDB.getHandle();

    String rid = decN.getAttribute("rid");
    id = Integer.parseInt(rid.substring(2));

    name = decN.getAttribute("name");

    type = DecisionType.fromString(decN.getAttribute("type"));

    devPhase = Phase.fromString(decN.getAttribute("phase"));

    status = DecisionStatus.fromString(decN.getAttribute("status"));

    Node child = decN.getFirstChild();
    importHelper(child);

    Node nextNode = child.getNextSibling();
    while (nextNode != null) {
      importHelper(nextNode);
      nextNode = nextNode.getNextSibling();
    }

    db.addPatternDecisionFromXML(this);
  }
Exemplo n.º 26
0
  /**
   * 唯一的构建方法
   *
   * @param _key 值set,必须字典序
   * @param _length 对应每个key的长度,留空动态获取
   * @param _value 每个key对应的值,留空使用key的下标作为值
   * @param _keySize key的长度,应该设为_key.size
   * @return 是否出错
   */
  public int build(List<String> _key, int _length[], int _value[], int _keySize) {
    if (_keySize > _key.size() || _key == null) return 0;

    // progress_func_ = progress_func;
    key = _key;
    length = _length;
    keySize = _keySize;
    value = _value;
    progress = 0;

    resize(65536 * 32); // 32个双字节

    base[0] = 1;
    nextCheckPos = 0;

    Node root_node = new Node();
    root_node.left = 0;
    root_node.right = keySize;
    root_node.depth = 0;

    List<Node> siblings = new ArrayList<Node>();
    fetch(root_node, siblings);
    insert(siblings);

    // size += (1 << 8 * 2) + 1; // ???
    // if (size >= allocSize) resize (size);

    used = null;
    key = null;
    length = null;

    return error_;
  }
    int query(int node, int treeStart, int treeEnd, int rangeStart, int rangeEnd) {
      Node temp = tree[node];
      temp.lazy %= 3;

      if (temp.lazy > 0) {
        if (treeStart != treeEnd) {
          tree[2 * node].lazy += temp.lazy;
          tree[2 * node + 1].lazy += temp.lazy;
        }

        while (temp.lazy > 0) {
          int temp2 = temp.count[2];

          temp.count[2] = temp.count[1];
          temp.count[1] = temp.count[0];
          temp.count[0] = temp2;
          temp.lazy--;
        }
      }

      if (treeStart > rangeEnd || treeEnd < rangeStart) return 0;

      if (treeStart >= rangeStart && treeEnd <= rangeEnd) return temp.count[0];

      int mid, left, right;

      mid = treeStart + ((treeEnd - treeStart) >> 1);
      left = query(2 * node, treeStart, mid, rangeStart, rangeEnd);
      right = query(2 * node + 1, mid + 1, treeEnd, rangeStart, rangeEnd);

      return left + right;
    }
Exemplo n.º 28
0
 public static final Map parseFrame(Node node) {
   NodeList bones = node.getChildNodes();
   Map bone_infos = new HashMap();
   for (int i = 0; i < bones.getLength(); i++) {
     Node bone = bones.item(i);
     if (bone.getNodeName().equals("transform")) {
       String name = bone.getAttributes().getNamedItem("name").getNodeValue();
       float[] matrix = new float[16];
       matrix[0 * 4 + 0] = getAttrFloat(bone, "m00");
       matrix[0 * 4 + 1] = getAttrFloat(bone, "m01");
       matrix[0 * 4 + 2] = getAttrFloat(bone, "m02");
       matrix[0 * 4 + 3] = getAttrFloat(bone, "m03");
       matrix[1 * 4 + 0] = getAttrFloat(bone, "m10");
       matrix[1 * 4 + 1] = getAttrFloat(bone, "m11");
       matrix[1 * 4 + 2] = getAttrFloat(bone, "m12");
       matrix[1 * 4 + 3] = getAttrFloat(bone, "m13");
       matrix[2 * 4 + 0] = getAttrFloat(bone, "m20");
       matrix[2 * 4 + 1] = getAttrFloat(bone, "m21");
       matrix[2 * 4 + 2] = getAttrFloat(bone, "m22");
       matrix[2 * 4 + 3] = getAttrFloat(bone, "m23");
       matrix[3 * 4 + 0] = getAttrFloat(bone, "m30");
       matrix[3 * 4 + 1] = getAttrFloat(bone, "m31");
       matrix[3 * 4 + 2] = getAttrFloat(bone, "m32");
       matrix[3 * 4 + 3] = getAttrFloat(bone, "m33");
       bone_infos.put(name, matrix);
     }
   }
   return bone_infos;
 }
Exemplo n.º 29
0
 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;
 }
Exemplo n.º 30
0
  public void deleteitem(int element) {
    Node temp; // ref:http://web.cse.ohio-state.edu/~reeves/CSE2421sp13/lab3linklistCOD
    temp = head;
    while (temp != null) // while LL is not empty
    {
      if (element == temp.data) {
        if (temp == head) // deleting the first node
        {
          head = head.next;
          temp.next.prev = null;
          temp.next = null;

        } else if (end == temp) // is it end
        {
          temp.prev.next = null;
          end = temp.prev;
          temp.prev = null;

        } else // if not first then
        {
          // while(head.next != temp)
          // {
          temp.prev.next = temp.next;
          temp.next.prev = temp.prev;
          temp.next = null;
          temp.prev = null;
          // }
        }
      }
      temp = temp.next; // traversing through the LL by pointing to next ref
    }
  }