@Override void add(Pair<K, V> newpair) { assert box.contains(newpair.getKey()) : "Not contained: " + box + " - " + newpair.getKey(); OcNode<K, V> child = getChild(newpair.getKey()); if (child == this) { super.add(newpair); } else { child.add(newpair); } }
/** * True if this nodes integrity (all conditions that are required for a quadnode) are true. * * @return True if this nodes integrity (all conditions that are required for a quadnode) are * true. */ boolean checkIntegrity() { assert getMaxNodeSize() >= 1; assert subboxes != null; assert subboxes.size() == 8; assert subboxes.keySet().stream().noneMatch((b) -> b == null); // assert values.size() <= parent.getMaxNodeSize(); assert getValues().stream().noneMatch((p) -> p == null); assert getValues().stream().allMatch((p) -> box.contains(p.getKey())); assert getChildren().values().stream().distinct().count() == getChildren().values().stream().filter((n) -> n != null).count(); return true; }
/** * Returns the child that contains the key, or this node if no child contains the key. * * @param key Key to query for child containment. * @return A child node if the key fits into a child node or this node, if the key doesn't fit * within any child node. */ OcNode<K, V> getChild(K key) { assert box.contains(key); if (isSplit()) { for (Map.Entry<ID3BoundingBox, Quadrant> entry : subboxes.entrySet()) { if (entry.getKey().contains(key)) { if (!hasChild(entry.getValue())) { setChild(entry.getValue(), new OcNode<>(entry.getKey(), getMaxNodeSize())); } return getChild(entry.getValue()); } } } return this; }