private void hash(Node node) { hash(node.getNodeType()); switch (node.getNodeType()) { case Node.ATTRIBUTE_NODE: case Node.ELEMENT_NODE: hash(node.getNodeName()); break; case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: hash(node.getNodeValue()); break; } hash((short) node.getChildNodes().getLength()); if (node.getNodeType() == Node.ELEMENT_NODE) { NamedNodeMap attrs = node.getAttributes(); int nAttrs = attrs.getLength(); hash((short) nAttrs); for (int i = 0; i < nAttrs; ++i) { hash(attrs.item(i)); } } for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { hash(child); } }
/** Hashes the given parse tree. */ void hash(ParseTreeNode node) { hash(System.identityHashCode(node.getClass())); Object value = node.getValue(); if (value != null) { if (value instanceof String) { hash((String) value); } else if (value instanceof Node) { hash((Node) value); } else { hash(value.hashCode()); } } List<? extends ParseTreeNode> children = node.children(); hash((short) children.size()); for (ParseTreeNode child : children) { hash(child); } }
ModuleCacheKey(ContentType type, ParseTreeNode node) { Hasher hasher = new Hasher(type); hasher.hash(node); this.hashBytes = hasher.getHashBytes(); this.first32Bits = (hashBytes[0] & 0xff) | ((hashBytes[1] & 0xff) << 8) | ((hashBytes[2] & 0xff) << 16) | ((hashBytes[3] & 0xff) << 24); }