class EgoFilter implements ComplexFilter {

        private String pattern = "";
        private boolean self = true;
        private int depth = 1;

        @Override
        public Graph filter(Graph graph) {<FILL_FUNCTION_BODY>}

        @Override
        public String getName() {
            return NbBundle.getMessage(EgoBuilder.class, "EgoBuilder.name");
        }

        @Override
        public FilterProperty[] getProperties() {
            try {
                return new FilterProperty[] {
                    FilterProperty.createProperty(this, String.class, "pattern"),
                    FilterProperty.createProperty(this, Integer.class, "depth"),
                    FilterProperty.createProperty(this, Boolean.class, "self")};
            } catch (NoSuchMethodException ex) {
                Exceptions.printStackTrace(ex);
            }
            return new FilterProperty[0];
        }

        public String getPattern() {
            return pattern;
        }

        public void setPattern(String pattern) {
            this.pattern = pattern;
        }

        public Integer getDepth() {
            return depth;
        }

        public void setDepth(Integer depth) {
            this.depth = depth;
        }

        public boolean isSelf() {
            return self;
        }

        public void setSelf(boolean self) {
            this.self = self;
        }
    }

            String str = pattern.toLowerCase();

            List<Node> nodes = new ArrayList<>();
            for (Node n : graph.getNodes()) {
                if (n.getId().toString().toLowerCase().equals(str)) {
                    nodes.add(n);
                } else if ((n.getLabel() != null) && n.getLabel().toLowerCase().equals(str)) {
                    nodes.add(n);
                }
            }

            Set<Node> result = new HashSet<>();

            Set<Node> neighbours = new HashSet<>(nodes);

            for (int i = 0; i < depth; i++) {
                boolean newNodes = false;
                Node[] nei = neighbours.toArray(new Node[0]);
                neighbours.clear();
                for (Node n : nei) {
                    for (Node neighbor : graph.getNeighbors(n)) {
                        if (!result.contains(neighbor)) {
                            neighbours.add(neighbor);
                            newNodes = result.add(neighbor) || newNodes;
                        }
                    }
                }
                if (!newNodes || neighbours.isEmpty()) {
                    break;
                }
            }

            if (self) {
                result.addAll(nodes);
            } else {
                result.removeAll(nodes);
            }

            for (Node node : graph.getNodes().toArray()) {
                if (!result.contains(node)) {
                    graph.removeNode(node);
                }
            }

            return graph;
        
<no_super_class>