@Test public void sort() { root.addChild("2"); root.addChild("1"); root.addChild("0"); root.sort(new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { return o1.getName().compareTo(o2.getName()); } }); assertEquals(3, root.getChildCount()); assertEquals("0", root.getChild(0).getName()); assertEquals("1", root.getChild(1).getName()); assertEquals("2", root.getChild(2).getName()); }
@Override public void sort(Comparator<Node> comparator) { Parameters.requireNonNull(comparator, "comparator"); if (context.isExpanded()) { ApiNode[] a = new ApiNode[context.getNodeSize()]; for (NodeContext<ApiNode> c = context.getFirst(); c != null; c = c.getNext()) { a[c.getIndex()] = c.getNode(); } Arrays.sort(a, comparator); for (int i = 0; i < a.length; i++) { ApiNode n = a[i]; NodeContext<ApiNode> c = n.getContext(); if (c.getIndex() != i) { c.getNode().moveTo(i); } } } }
ApiNode implements Node { @Override public void sort(Comparator<Node> comparator) { Parameters.requireNonNull(comparator, "comparator"); if (context.isExpanded()) { ApiNode[] a = new ApiNode[context.getNodeSize()]; for (NodeContext<ApiNode> c = context.getFirst(); c != null; c = c.getNext()) { a[c.getIndex()] = c.getNode(); } Arrays.sort(a, comparator); for (int i = 0; i < a.length; i++) { ApiNode n = a[i]; NodeContext<ApiNode> c = n.getContext(); if (c.getIndex() != i) { c.getNode().moveTo(i); } } } } }
ApiNode implements Node { @Override public void sort(Comparator<Node> comparator) { Parameters.requireNonNull(comparator, "comparator"); if (context.isExpanded()) { ApiNode[] a = new ApiNode[context.getNodeSize()]; for (NodeContext<ApiNode> c = context.getFirst(); c != null; c = c.getNext()) { a[c.getIndex()] = c.getNode(); } Arrays.sort(a, comparator); for (int i = 0; i < a.length; i++) { ApiNode n = a[i]; NodeContext<ApiNode> c = n.getContext(); if (c.getIndex() != i) { c.getNode().moveTo(i); } } } } ApiNode(NavigationImpl navigation, NodeContext<ApiNode> context); }
ApiNode implements Node { @Override public void sort(Comparator<Node> comparator) { Parameters.requireNonNull(comparator, "comparator"); if (context.isExpanded()) { ApiNode[] a = new ApiNode[context.getNodeSize()]; for (NodeContext<ApiNode> c = context.getFirst(); c != null; c = c.getNext()) { a[c.getIndex()] = c.getNode(); } Arrays.sort(a, comparator); for (int i = 0; i < a.length; i++) { ApiNode n = a[i]; NodeContext<ApiNode> c = n.getContext(); if (c.getIndex() != i) { c.getNode().moveTo(i); } } } } ApiNode(NavigationImpl navigation, NodeContext<ApiNode> context); @Override Node addChild(int index, String childName); @Override Node addChild(String childName); @Override FilteredNode filter(); @Override Node getChild(int index); @Override Node getChild(String childName); @Override int getChildCount(); @Override Node getNode(String... nodePath); @Override Node getNode(NodePath nodePath); @Override String getIconName(); @Override String getDisplayName(); @Override LocalizedString getDisplayNames(); @Override String getName(); @Override NodePath getNodePath(); @Override PageId getPageId(); @Override Node getParent(); @Override Attributes getAttributes(); @Override String getURI(); @Override Visibility getVisibility(); @Override boolean hasChild(String childName); @Override int indexOf(String childName); @Override boolean isChildrenLoaded(); @Override boolean isRoot(); @Override boolean isVisible(); @Override Iterator<Node> iterator(); @Override void moveTo(int index); @Override void moveTo(int index, Node parent); @Override void moveTo(Node parent); @Override boolean removeChild(String childName); @Override void setName(String name); @Override void setIconName(String iconName); @Override void setDisplayName(String displayName); @Override void setDisplayNames(LocalizedString displayName); @Override void setPageId(PageId pageId); @Override void setVisibility(boolean visible); @Override void setVisibility(PublicationDate publicationDate); @Override void setVisibility(Visibility visibility); @Override void sort(Comparator<Node> comparator); @Override String toString(); }
ApiNode implements Node { @Override public void sort(Comparator<Node> comparator) { Parameters.requireNonNull(comparator, "comparator"); if (context.isExpanded()) { ApiNode[] a = new ApiNode[context.getNodeSize()]; for (NodeContext<ApiNode> c = context.getFirst(); c != null; c = c.getNext()) { a[c.getIndex()] = c.getNode(); } Arrays.sort(a, comparator); for (int i = 0; i < a.length; i++) { ApiNode n = a[i]; NodeContext<ApiNode> c = n.getContext(); if (c.getIndex() != i) { c.getNode().moveTo(i); } } } } ApiNode(NavigationImpl navigation, NodeContext<ApiNode> context); @Override Node addChild(int index, String childName); @Override Node addChild(String childName); @Override FilteredNode filter(); @Override Node getChild(int index); @Override Node getChild(String childName); @Override int getChildCount(); @Override Node getNode(String... nodePath); @Override Node getNode(NodePath nodePath); @Override String getIconName(); @Override String getDisplayName(); @Override LocalizedString getDisplayNames(); @Override String getName(); @Override NodePath getNodePath(); @Override PageId getPageId(); @Override Node getParent(); @Override Attributes getAttributes(); @Override String getURI(); @Override Visibility getVisibility(); @Override boolean hasChild(String childName); @Override int indexOf(String childName); @Override boolean isChildrenLoaded(); @Override boolean isRoot(); @Override boolean isVisible(); @Override Iterator<Node> iterator(); @Override void moveTo(int index); @Override void moveTo(int index, Node parent); @Override void moveTo(Node parent); @Override boolean removeChild(String childName); @Override void setName(String name); @Override void setIconName(String iconName); @Override void setDisplayName(String displayName); @Override void setDisplayNames(LocalizedString displayName); @Override void setPageId(PageId pageId); @Override void setVisibility(boolean visible); @Override void setVisibility(PublicationDate publicationDate); @Override void setVisibility(Visibility visibility); @Override void sort(Comparator<Node> comparator); @Override String toString();  }