@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (description != null ? description.hashCode() : 0); result = 31 * result + (rootNode != null ? rootNode.hashCode() : 0); return result; }
/** @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((color == null) ? 0 : color.hashCode()); result = prime * result + (fixedValue ? 1231 : 1237); result = prime * result + ((parent == null) ? 0 : parent.hashCode()); result = prime * result + ((value == null) ? 0 : value.hashCode()); return result; }
@Test public void testNode() { Node root = new Node(String.class); assertNull(root.getParent()); Node child = new Node(Integer.class); assertTrue(root.addChild(child)); assertTrue(root.addChild(new Node(Long.class))); assertNotNull(root.hashCode()); List<Node> allButMeChild = child.allButMe(); assertEquals(2, allButMeChild.size()); assertTrue(allButMeChild.add(child)); assertFalse(allButMeChild.add(child)); List<Node> allButMeRoot = root.allButMe(); assertEquals(2, allButMeRoot.size()); Node child2 = new Node(Integer.class); assertFalse(root.addChild(child2)); }
@Override public int hashCode() { return attr + (int) Double.doubleToLongBits(split) + loChild.hashCode() + hiChild.hashCode(); }
/** * Returns true if node is in the pathList * * @param node - node to look for * @return - True if node in pathlist, else False */ public boolean inPath(Node to) { return toNodes.containsKey(to.hashCode()); }
/** * Add node to path. * * @param newNode */ public void addEdge(Edge newEdge) { pathList.add(newEdge); Node toNode = newEdge.getTo(); toNodes.put(toNode.hashCode(), toNode); }
public void outputToJSON(String filePath, int numTopWords, double boundaryFactor) { System.out.println("Writing down the model..."); JSONObject featureCollection = new JSONObject(); featureCollection.put("type", "FeatureCollection"); JSONArray features = new JSONArray(); Queue<Node> nodeQueue = new LinkedList<>(); nodeQueue.offer(root); while (!nodeQueue.isEmpty()) { Node currentNode = nodeQueue.poll(); JSONObject feature = new JSONObject(); feature.put("type", "Feature"); feature.put("id", currentNode.hashCode()); JSONObject properties = new JSONObject(); properties.put("level", currentNode.level + 1); properties.put("num_documents", currentNode.numCustomers); if (currentNode.parent != null) { properties.put("parent", currentNode.parent.hashCode()); } if (!currentNode.isLeaf()) { JSONArray children = new JSONArray(); for (Node child : currentNode.children) { children.put(child.hashCode()); } properties.put("children", children); } JSONArray center = new JSONArray(); double longitude = currentNode.location.longitude; center.put(longitude); double latitude = currentNode.location.latitude; center.put(latitude); properties.put("center", center); JSONArray deviation = new JSONArray(); double longitudeDeviation = Math.sqrt(currentNode.location.longitudeVariance); deviation.put(longitudeDeviation); double latitudeDeviation = Math.sqrt(currentNode.location.latitudeVariance); deviation.put(latitudeDeviation); properties.put("deviation", deviation); JSONArray topWords = new JSONArray(); PriorityQueue<Map.Entry<Integer, Integer>> wordMinHeap = new PriorityQueue<>( numTopWords, new Comparator<Map.Entry<Integer, Integer>>() { @Override public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) { return o1.getValue() - o2.getValue(); } }); for (Map.Entry<Integer, Integer> entry : currentNode.wordCounts.entrySet()) { if (wordMinHeap.size() < numTopWords) { wordMinHeap.offer(entry); } else { if (entry.getValue() > wordMinHeap.peek().getValue()) { wordMinHeap.poll(); wordMinHeap.offer(entry); } } } while (!wordMinHeap.isEmpty()) { topWords.put(this.id2Word.get(wordMinHeap.poll().getKey())); } properties.put("top_words", topWords); feature.put("properties", properties); JSONObject geometry = new JSONObject(); geometry.put("type", "Polygon"); JSONArray coordinates = new JSONArray(); JSONArray boundary = new JSONArray(); double east = longitude + boundaryFactor * longitudeDeviation; double west = longitude - boundaryFactor * longitudeDeviation; double north = latitude + boundaryFactor * latitudeDeviation; double south = latitude - boundaryFactor * latitudeDeviation; boundary.put(new JSONArray(new double[] {west, north})); boundary.put(new JSONArray(new double[] {east, north})); boundary.put(new JSONArray(new double[] {east, south})); boundary.put(new JSONArray(new double[] {west, south})); boundary.put(new JSONArray(new double[] {west, north})); coordinates.put(boundary); geometry.put("coordinates", coordinates); feature.put("geometry", geometry); features.put(feature); for (Node child : currentNode.children) { nodeQueue.offer(child); } } featureCollection.put("features", features); try { PrintWriter writer = new PrintWriter(filePath); featureCollection.write(writer); writer.close(); } catch (FileNotFoundException e) { System.err.println("Model JSON cannot be created."); } }