1 16 package org.apache.commons.io.filefilter; 17 18 import java.io.File ; 19 import java.util.List ; 20 21 44 public class NameFileFilter extends AbstractFileFilter { 45 46 47 private String [] names; 48 49 55 public NameFileFilter(String name) { 56 if (name == null) { 57 throw new IllegalArgumentException ("The name must not be null"); 58 } 59 this.names = new String [] {name}; 60 } 61 62 71 public NameFileFilter(String [] names) { 72 if (names == null) { 73 throw new IllegalArgumentException ("The array of names must not be null"); 74 } 75 this.names = names; 76 } 77 78 85 public NameFileFilter(List names) { 86 if (names == null) { 87 throw new IllegalArgumentException ("The list of names must not be null"); 88 } 89 this.names = (String []) names.toArray(new String [names.size()]); 90 } 91 92 98 public boolean accept(File file) { 99 String name = file.getName(); 100 for (int i = 0; i < this.names.length; i++) { 101 if (name.equals(this.names[i])) { 102 return true; 103 } 104 } 105 return false; 106 } 107 108 115 public boolean accept(File file, String name) { 116 for (int i = 0; i < this.names.length; i++) { 117 if (name.equals(this.names[i])) { 118 return true; 119 } 120 } 121 return false; 122 } 123 124 } 125 | Popular Tags |