public void addChild(PlantNode child) { Set<PlantNode> gen = children.get(child.getGeneration()); if (gen == null) { // create new generation gen = new HashSet<>(); gen.add(child); children.put(child.getGeneration(), gen); } else { // add to existing generation gen.add(child); } }
public void removeChild(PlantNode child) { Set<PlantNode> gen = children.get(child.getGeneration()); if (gen != null) { gen.remove(child); } }