1 19 20 package org.openidex.search; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import org.openide.filesystems.FileObject; 28 import org.openide.loaders.DataFolder; 29 30 34 final class SimpleSearchInfo implements SearchInfo { 35 36 43 static final SearchInfo EMPTY_SEARCH_INFO 44 = new SearchInfo() { 45 public boolean canSearch() { 46 return true; 47 } 48 public java.util.Iterator objectsToSearch() { 49 return Collections.EMPTY_LIST.iterator(); 50 } 51 }; 52 53 54 private final DataFolder rootFolder; 55 56 private final boolean recursive; 57 58 private final FileObjectFilter[] filters; 59 60 68 SimpleSearchInfo(DataFolder folder, 69 boolean recursive, 70 FileObjectFilter[] filters) { 71 if (folder == null) { 72 throw new IllegalArgumentException (); 73 } 74 75 if ((filters != null) && (filters.length == 0)) { 76 filters = null; 77 } 78 this.rootFolder = folder; 79 this.recursive = recursive; 80 this.filters = filters; 81 } 82 83 85 public boolean canSearch() { 86 return (filters != null) 87 ? checkFolderAgainstFilters(rootFolder.getPrimaryFile()) 88 : true; 89 } 90 91 93 public Iterator objectsToSearch() { 94 return new SimpleSearchIterator(rootFolder, 95 recursive, 96 filters != null ? Arrays.asList(filters) 97 : null); 98 } 99 100 102 private boolean checkFolderAgainstFilters(final FileObject folder) { 103 assert folder.isFolder(); 104 105 for (int i = 0; i < filters.length; i++) { 106 if (filters[i].traverseFolder(folder) 107 == FileObjectFilter.DO_NOT_TRAVERSE) { 108 return false; 109 } 110 } 111 return true; 112 } 113 114 } 115 | Popular Tags |