1 19 20 package org.openidex.search; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import org.openide.nodes.Node; 27 28 32 final class SubnodesSearchInfo implements SearchInfo { 33 34 35 private final Node node; 36 37 40 public SubnodesSearchInfo(final Node node) { 41 this.node = node; 42 } 43 44 46 public boolean canSearch() { 47 final Node[] nodes = node.getChildren().getNodes(true); 48 for (int i = 0; i < nodes.length; i++) { 49 SearchInfo searchInfo = Utils.getSearchInfo(nodes[i]); 50 if (searchInfo != null && searchInfo.canSearch()) { 51 return true; 52 } 53 } 54 return false; 55 } 56 57 59 public Iterator objectsToSearch() { 60 final Node[] nodes = node.getChildren().getNodes(true); 61 if (nodes.length == 0) { 62 return SimpleSearchInfo.EMPTY_SEARCH_INFO.objectsToSearch(); 63 } 64 65 List searchInfoElements = new ArrayList (nodes.length); 66 for (int i = 0; i < nodes.length; i++) { 67 SearchInfo subInfo = Utils.getSearchInfo(nodes[i]); 68 if (subInfo != null && subInfo.canSearch()) { 69 searchInfoElements.add(subInfo); 70 } 71 } 72 73 final int size = searchInfoElements.size(); 74 switch (size) { 75 case 0: 76 return Collections.EMPTY_LIST.iterator(); 77 case 1: 78 return ((SearchInfo) searchInfoElements.get(0)) 79 .objectsToSearch(); 80 default: 81 return new CompoundSearchIterator( 82 (SearchInfo[]) 83 searchInfoElements.toArray(new SearchInfo[size])); 84 } 85 } 86 87 } 88 | Popular Tags |