BrightSide Workbench Full Report + Source Code
ExpressionFilter.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.file;
19 
20 import java.io.File;
21 import java.io.FileFilter;
22 import org.zkoss.lang.Strings;
23 
28 public class ExpressionFilter implements FileFilter {
29 
30  private boolean fullPath = false, partial = true,
31  acceptOnNull = true, regularExpression = false;
32  private String expression;
33 
34  @Override
35  public boolean accept(File pathname) {
36  if(expression == null) {
37  return acceptOnNull;
38  }
39  String name = fullPath ? pathname.getAbsolutePath() : pathname.getName();
40  String regExp = expression;
41  if(!regularExpression) {
42  regExp = regExp.replaceAll("\\*", ".*")
43  .replaceAll("\\?", ".?");
44  }
45  if(partial) {
46  regExp = ".*" + regExp + ".*";
47  }
48  return name.matches(regExp);
49  }
50 
51  public boolean isEmpty() {
52  return Strings.isEmpty(expression);
53  }
54 
55  public boolean isAcceptOnNull() {
56  return acceptOnNull;
57  }
58 
59  public void setAcceptOnNull(boolean acceptOnNull) {
60  this.acceptOnNull = acceptOnNull;
61  }
62 
63  public String getExpression() {
64  return expression;
65  }
66 
67  public void setExpression(String expression) {
68  this.expression = expression;
69  }
70 
71  public boolean isFullPath() {
72  return fullPath;
73  }
74 
75  public void setFullPath(boolean fullPath) {
76  this.fullPath = fullPath;
77  }
78 
79  public boolean isPartial() {
80  return partial;
81  }
82 
83  public void setPartial(boolean partial) {
84  this.partial = partial;
85  }
86 
87  public boolean isRegularExpression() {
88  return regularExpression;
89  }
90 
91  public void setRegularExpression(boolean regularExpression) {
92  this.regularExpression = regularExpression;
93  }
94 
95 }
void setRegularExpression(boolean regularExpression)
void setPartial(boolean partial)
void setExpression(String expression)
void setAcceptOnNull(boolean acceptOnNull)
void setFullPath(boolean fullPath)