diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-02-04 10:42:21 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-02-04 10:42:21 +0100 |
commit | a14a0644c2a27ddec22f23925578a40aa6fa8302 (patch) | |
tree | aa5c078cc8ec7c4e2020960ad9a343fb7e79a16c /sonar-duplications/src/main/java | |
parent | 0f44a42b85093a3dcef64b52f6e15337b119ec88 (diff) | |
download | sonarqube-a14a0644c2a27ddec22f23925578a40aa6fa8302.tar.gz sonarqube-a14a0644c2a27ddec22f23925578a40aa6fa8302.zip |
Upgrade copyright headers
Diffstat (limited to 'sonar-duplications/src/main/java')
37 files changed, 826 insertions, 826 deletions
diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java index 46a252bbf7a..f60f2f80044 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AbstractLanguage.java @@ -1,43 +1,43 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.cpd;
-
-import net.sourceforge.pmd.util.filter.Filters;
-
-import java.io.FilenameFilter;
-
-public abstract class AbstractLanguage implements Language {
- private final Tokenizer tokenizer;
- private final FilenameFilter fileFilter;
-
- public AbstractLanguage(Tokenizer tokenizer, String... extensions) {
- this.tokenizer = tokenizer;
- fileFilter = net.sourceforge.pmd.util.filter.Filters.toFilenameFilter(Filters.getFileExtensionOrDirectoryFilter(extensions));
- }
-
- public FilenameFilter getFileFilter() {
- return fileFilter;
- }
-
- public Tokenizer getTokenizer() {
- return tokenizer;
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.cpd; + +import net.sourceforge.pmd.util.filter.Filters; + +import java.io.FilenameFilter; + +public abstract class AbstractLanguage implements Language { + private final Tokenizer tokenizer; + private final FilenameFilter fileFilter; + + public AbstractLanguage(Tokenizer tokenizer, String... extensions) { + this.tokenizer = tokenizer; + fileFilter = net.sourceforge.pmd.util.filter.Filters.toFilenameFilter(Filters.getFileExtensionOrDirectoryFilter(extensions)); + } + + public FilenameFilter getFileFilter() { + return fileFilter; + } + + public Tokenizer getTokenizer() { + return tokenizer; + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyLanguage.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyLanguage.java index 9f302512e00..b3c094e4cd3 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyLanguage.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyLanguage.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java index 0a3659857a0..595fa235b45 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/AnyTokenizer.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDListener.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDListener.java index 3d74c9deec6..fa17bce8d2e 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDListener.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDListener.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDNullListener.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDNullListener.java index ae154776d1e..13a97b24346 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDNullListener.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/CPDNullListener.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileFinder.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileFinder.java index 19051059602..f2c61bd25d2 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileFinder.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileFinder.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileReporter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileReporter.java index 743697472d1..6c530b690a3 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileReporter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/FileReporter.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Language.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Language.java index a609a81ceb0..f9f418d64c0 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Language.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Language.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/ReportException.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/ReportException.java index 1fa87f75630..f2d371b45cb 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/ReportException.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/ReportException.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java index 3a0282196c4..2ce2ea4b42c 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java index 883354568a4..1da17017bf5 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/TokenEntry.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java index 8706cd4dea8..54f8c216779 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokenizer.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java index dfbf2501cac..67731611a84 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/Tokens.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserConstants.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserConstants.java index e6f57bd9945..57ec6e503d7 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserConstants.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserConstants.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserTokenManager.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserTokenManager.java index 452ddc6cac0..a5421f2e805 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserTokenManager.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/CPPParserTokenManager.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/ParseException.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/ParseException.java index 1c0e6e03f57..c093ff15c5c 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/ParseException.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/ParseException.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/SimpleCharStream.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/SimpleCharStream.java index aad959fe7f2..54005b298d1 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/SimpleCharStream.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/SimpleCharStream.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/Token.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/Token.java index ab4824448e5..15f78e80a1f 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/Token.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/Token.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/TokenMgrError.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/TokenMgrError.java index 9f4258d9742..e51205fe2f9 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/TokenMgrError.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/cpd/cppast/TokenMgrError.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/FileFinder.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/FileFinder.java index ada54ced4ad..42f8764f264 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/FileFinder.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/FileFinder.java @@ -1,62 +1,62 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A utility class for finding files within a directory.
- */
-public class FileFinder {
-
- private FilenameFilter filter;
- private static final String FILE_SEP = System.getProperty("file.separator");
-
- public List<File> findFilesFrom(String dir, FilenameFilter filter, boolean recurse) {
- this.filter = filter;
- List<File> files = new ArrayList<File>();
- scanDirectory(new File(dir), files, recurse);
- return files;
- }
-
- /**
- * Implements a tail recursive file scanner
- */
- private void scanDirectory(File dir, List<File> list, boolean recurse) {
- String[] candidates = dir.list(filter);
- if (candidates == null) {
- return;
- }
- for (int i = 0; i < candidates.length; i++) {
- File tmp = new File(dir + FILE_SEP + candidates[i]);
- if (tmp.isDirectory()) {
- if (recurse) {
- scanDirectory(tmp, list, true);
- }
- } else {
- list.add(new File(dir + FILE_SEP + candidates[i]));
- }
- }
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.List; + +/** + * A utility class for finding files within a directory. + */ +public class FileFinder { + + private FilenameFilter filter; + private static final String FILE_SEP = System.getProperty("file.separator"); + + public List<File> findFilesFrom(String dir, FilenameFilter filter, boolean recurse) { + this.filter = filter; + List<File> files = new ArrayList<File>(); + scanDirectory(new File(dir), files, recurse); + return files; + } + + /** + * Implements a tail recursive file scanner + */ + private void scanDirectory(File dir, List<File> list, boolean recurse) { + String[] candidates = dir.list(filter); + if (candidates == null) { + return; + } + for (int i = 0; i < candidates.length; i++) { + File tmp = new File(dir + FILE_SEP + candidates[i]); + if (tmp.isDirectory()) { + if (recurse) { + scanDirectory(tmp, list, true); + } + } else { + list.add(new File(dir + FILE_SEP + candidates[i])); + } + } + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/StringUtil.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/StringUtil.java index 41d1d27760c..ce84dd3dc0d 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/StringUtil.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/StringUtil.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractCompoundFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractCompoundFilter.java index 6d5523ba8ce..13e300689f9 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractCompoundFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractCompoundFilter.java @@ -1,76 +1,76 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A base class for Filters which implements behavior using a List of other
- * Filters.
- *
- * @param <T>
- * The underlying type on which the filter applies.
- */
-public abstract class AbstractCompoundFilter<T> implements Filter<T> {
-
- protected List<Filter<T>> filters;
-
- public AbstractCompoundFilter() {
- filters = new ArrayList<Filter<T>>(2);
- }
-
- public AbstractCompoundFilter(Filter<T>... filters) {
- this.filters = new ArrayList<Filter<T>>(filters.length);
- for (Filter<T> filter : filters) {
- this.filters.add(filter);
- }
- }
-
- public List<Filter<T>> getFilters() {
- return filters;
- }
-
- public void setFilters(List<Filter<T>> filters) {
- this.filters = filters;
- }
-
- public void addFilter(Filter<T> filter) {
- filters.add(filter);
- }
-
- protected abstract String getOperator();
-
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("(");
- for (int i = 0; i < filters.size(); i++) {
- if (i > 0) {
- builder.append(" ");
- builder.append(getOperator());
- builder.append(" ");
- }
- builder.append(filters.get(i));
- }
- builder.append(")");
- return builder.toString();
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +import java.util.ArrayList; +import java.util.List; + +/** + * A base class for Filters which implements behavior using a List of other + * Filters. + * + * @param <T> + * The underlying type on which the filter applies. + */ +public abstract class AbstractCompoundFilter<T> implements Filter<T> { + + protected List<Filter<T>> filters; + + public AbstractCompoundFilter() { + filters = new ArrayList<Filter<T>>(2); + } + + public AbstractCompoundFilter(Filter<T>... filters) { + this.filters = new ArrayList<Filter<T>>(filters.length); + for (Filter<T> filter : filters) { + this.filters.add(filter); + } + } + + public List<Filter<T>> getFilters() { + return filters; + } + + public void setFilters(List<Filter<T>> filters) { + this.filters = filters; + } + + public void addFilter(Filter<T> filter) { + filters.add(filter); + } + + protected abstract String getOperator(); + + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("("); + for (int i = 0; i < filters.size(); i++) { + if (i > 0) { + builder.append(" "); + builder.append(getOperator()); + builder.append(" "); + } + builder.append(filters.get(i)); + } + builder.append(")"); + return builder.toString(); + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractDelegateFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractDelegateFilter.java index 678ef1d535f..e203bb58b6c 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractDelegateFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AbstractDelegateFilter.java @@ -1,57 +1,57 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-/**
- * A base class for Filters which implements behavior using delegation
- * to an underlying filter.
- *
- * @param <T>
- * The underlying type on which the filter applies.
- */
-public abstract class AbstractDelegateFilter<T> implements Filter<T> {
- protected Filter<T> filter;
-
- public AbstractDelegateFilter() {
- }
-
- public AbstractDelegateFilter(Filter<T> filter) {
- this.filter = filter;
- }
-
- public Filter<T> getFilter() {
- return filter;
- }
-
- public void setFilter(Filter<T> filter) {
- this.filter = filter;
- }
-
- // Subclass should override to do something other the simply delegate.
- public boolean filter(T obj) {
- return filter.filter(obj);
- }
-
- // Subclass should override to do something other the simply delegate.
- public String toString() {
- return filter.toString();
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +/** + * A base class for Filters which implements behavior using delegation + * to an underlying filter. + * + * @param <T> + * The underlying type on which the filter applies. + */ +public abstract class AbstractDelegateFilter<T> implements Filter<T> { + protected Filter<T> filter; + + public AbstractDelegateFilter() { + } + + public AbstractDelegateFilter(Filter<T> filter) { + this.filter = filter; + } + + public Filter<T> getFilter() { + return filter; + } + + public void setFilter(Filter<T> filter) { + this.filter = filter; + } + + // Subclass should override to do something other the simply delegate. + public boolean filter(T obj) { + return filter.filter(obj); + } + + // Subclass should override to do something other the simply delegate. + public String toString() { + return filter.toString(); + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AndFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AndFilter.java index b74c211f30a..96ab80a3edd 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AndFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/AndFilter.java @@ -1,54 +1,54 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-/**
- * A logical AND of a list of Filters. This implementation is short circuiting.
- *
- * @param <T>
- * The underlying type on which the filter applies.
- */
-public class AndFilter<T> extends AbstractCompoundFilter<T> {
-
- public AndFilter() {
- super();
- }
-
- public AndFilter(Filter<T>... filters) {
- super(filters);
- }
-
- public boolean filter(T obj) {
- boolean match = true;
- for (Filter<T> filter : filters) {
- if (!filter.filter(obj)) {
- match = false;
- break;
- }
- }
- return match;
- }
-
- @Override
- protected String getOperator() {
- return "and";
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +/** + * A logical AND of a list of Filters. This implementation is short circuiting. + * + * @param <T> + * The underlying type on which the filter applies. + */ +public class AndFilter<T> extends AbstractCompoundFilter<T> { + + public AndFilter() { + super(); + } + + public AndFilter(Filter<T>... filters) { + super(filters); + } + + public boolean filter(T obj) { + boolean match = true; + for (Filter<T> filter : filters) { + if (!filter.filter(obj)) { + match = false; + break; + } + } + return match; + } + + @Override + protected String getOperator() { + return "and"; + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/DirectoryFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/DirectoryFilter.java index 65a39c981a9..4d632ec23b0 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/DirectoryFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/DirectoryFilter.java @@ -1,37 +1,37 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-import java.io.File;
-
-/**
- * Directory filter.
- */
-public class DirectoryFilter implements Filter<File> {
- public static final DirectoryFilter INSTANCE = new DirectoryFilter();
-
- private DirectoryFilter() {
- }
-
- public boolean filter(File file) {
- return file.isDirectory();
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +import java.io.File; + +/** + * Directory filter. + */ +public class DirectoryFilter implements Filter<File> { + public static final DirectoryFilter INSTANCE = new DirectoryFilter(); + + private DirectoryFilter() { + } + + public boolean filter(File file) { + return file.isDirectory(); + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/FileExtensionFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/FileExtensionFilter.java index 12c5658fcc8..f442e8e93ef 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/FileExtensionFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/FileExtensionFilter.java @@ -1,62 +1,62 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-import java.io.File;
-
-public class FileExtensionFilter implements Filter<File> {
- protected final String[] extensions;
- protected final boolean ignoreCase;
-
- /**
- * Matches any files with the given extensions, ignoring case
- */
- public FileExtensionFilter(String... extensions) {
- this(true, extensions);
- }
-
- /**
- * Matches any files with the given extensions, optionally ignoring case.
- */
- public FileExtensionFilter(boolean ignoreCase, String... extensions) {
- this.extensions = extensions;
- this.ignoreCase = ignoreCase;
- if (ignoreCase) {
- for (int i = 0; i < this.extensions.length; i++) {
- this.extensions[i] = this.extensions[i].toUpperCase();
- }
- }
- }
-
- public boolean filter(File file) {
- boolean accept = extensions == null;
- if (!accept) {
- for (String extension : extensions) {
- String name = file.getName();
- if (ignoreCase ? name.toUpperCase().endsWith(extension) : name.endsWith(extension)) {
- accept = true;
- break;
- }
- }
- }
- return accept;
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +import java.io.File; + +public class FileExtensionFilter implements Filter<File> { + protected final String[] extensions; + protected final boolean ignoreCase; + + /** + * Matches any files with the given extensions, ignoring case + */ + public FileExtensionFilter(String... extensions) { + this(true, extensions); + } + + /** + * Matches any files with the given extensions, optionally ignoring case. + */ + public FileExtensionFilter(boolean ignoreCase, String... extensions) { + this.extensions = extensions; + this.ignoreCase = ignoreCase; + if (ignoreCase) { + for (int i = 0; i < this.extensions.length; i++) { + this.extensions[i] = this.extensions[i].toUpperCase(); + } + } + } + + public boolean filter(File file) { + boolean accept = extensions == null; + if (!accept) { + for (String extension : extensions) { + String name = file.getName(); + if (ignoreCase ? name.toUpperCase().endsWith(extension) : name.endsWith(extension)) { + accept = true; + break; + } + } + } + return accept; + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filter.java index 1a35080ee6d..2acd458c6c6 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filter.java @@ -1,31 +1,31 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-/**
- * A Filter interface, used for filtering arbitrary objects.
- *
- * @param <T>
- * The underlying type on which the filter applies.
- */
-public interface Filter<T> {
- boolean filter(T obj);
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +/** + * A Filter interface, used for filtering arbitrary objects. + * + * @param <T> + * The underlying type on which the filter applies. + */ +public interface Filter<T> { + boolean filter(T obj); +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filters.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filters.java index 5318e298e45..9acd1a61660 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filters.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/Filters.java @@ -1,220 +1,220 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Utility class for working with Filters. Contains builder style methods,
- * apply methods, as well as mechanisms for adapting Filters and FilenameFilters.
- */
-public class Filters {
-
- /**
- * Filter a given Collection.
- * @param <T> Type of the Collection.
- * @param filter A Filter upon the Type of objects in the Collection.
- * @param collection The Collection to filter.
- * @return A List containing only those objects for which the Filter returned <code>true</code>.
- */
- public static <T> List<T> filter(Filter<T> filter, Collection<T> collection) {
- List<T> list = new ArrayList<T>();
- for (T obj : collection) {
- if (filter.filter(obj)) {
- list.add(obj);
- }
- }
- return list;
- }
-
- /**
- * Get a File Filter for files with the given extensions, ignoring case.
- * @param extensions The extensions to filter.
- * @return A File Filter.
- */
- public static Filter<File> getFileExtensionFilter(String... extensions) {
- return new FileExtensionFilter(extensions);
- }
-
- /**
- * Get a File Filter for directories.
- * @return A File Filter.
- */
- public static Filter<File> getDirectoryFilter() {
- return DirectoryFilter.INSTANCE;
- }
-
- /**
- * Get a File Filter for directories or for files with the given extensions, ignoring case.
- * @param extensions The extensions to filter.
- * @return A File Filter.
- */
- public static Filter<File> getFileExtensionOrDirectoryFilter(String... extensions) {
- return new OrFilter<File>(getFileExtensionFilter(extensions), getDirectoryFilter());
- }
-
- /**
- * Given a String Filter, expose as a File Filter. The File paths are
- * normalized to a standard pattern using <code>/</code> as a path separator
- * which can be used cross platform easily in a regular expression based
- * String Filter.
- *
- * @param filter A String Filter.
- * @return A File Filter.
- */
- public static Filter<File> toNormalizedFileFilter(final Filter<String> filter) {
- return new Filter<File>() {
- public boolean filter(File file) {
- String path = file.getPath();
- path = path.replace('\\', '/');
- return filter.filter(path);
- }
-
- public String toString() {
- return filter.toString();
- }
- };
- }
-
- /**
- * Given a String Filter, expose as a Filter on another type. The
- * <code>toString()</code> method is called on the objects of the other
- * type and delegated to the String Filter.
- * @param <T> The desired type.
- * @param filter The existing String Filter.
- * @return A Filter on the desired type.
- */
- public static <T> Filter<T> fromStringFilter(final Filter<String> filter) {
- return new Filter<T>() {
- public boolean filter(T obj) {
- return filter.filter(obj.toString());
- }
-
- public String toString() {
- return filter.toString();
- }
- };
- }
-
- /**
- * Given a File Filter, expose as a FilenameFilter.
- * @param filter The File Filter.
- * @return A FilenameFilter.
- */
- public static FilenameFilter toFilenameFilter(final Filter<File> filter) {
- return new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return filter.filter(new File(dir, name));
- }
-
- public String toString() {
- return filter.toString();
- }
- };
- }
-
- /**
- * Given a FilenameFilter, expose as a File Filter.
- * @param filter The FilenameFilter.
- * @return A File Filter.
- */
- public static Filter<File> toFileFilter(final FilenameFilter filter) {
- return new Filter<File>() {
- public boolean filter(File file) {
- return filter.accept(file.getParentFile(), file.getName());
- }
-
- public String toString() {
- return filter.toString();
- }
- };
- }
-
- /**
- * Construct a String Filter using set of include and exclude regular
- * expressions. If there are no include regular expressions provide, then
- * a regular expression is added which matches every String by default.
- * A String is included as long as it matches an include regular expression
- * and does not match an exclude regular expression.
- * <p>
- * In other words, exclude patterns override include patterns.
- *
- * @param includeRegexes The include regular expressions. May be <code>null</code>.
- * @param excludeRegexes The exclude regular expressions. May be <code>null</code>.
- * @return A String Filter.
- */
- public static Filter<String> buildRegexFilterExcludeOverInclude(List<String> includeRegexes,
- List<String> excludeRegexes) {
- OrFilter<String> includeFilter = new OrFilter<String>();
- if (includeRegexes == null || includeRegexes.size() == 0) {
- includeFilter.addFilter(new RegexStringFilter(".*"));
- } else {
- for (String includeRegex : includeRegexes) {
- includeFilter.addFilter(new RegexStringFilter(includeRegex));
- }
- }
-
- OrFilter<String> excludeFilter = new OrFilter<String>();
- if (excludeRegexes != null) {
- for (String excludeRegex : excludeRegexes) {
- excludeFilter.addFilter(new RegexStringFilter(excludeRegex));
- }
- }
-
- return new AndFilter<String>(includeFilter, new NotFilter<String>(excludeFilter));
- }
-
- /**
- * Construct a String Filter using set of include and exclude regular
- * expressions. If there are no include regular expressions provide, then
- * a regular expression is added which matches every String by default.
- * A String is included as long as the case that there is an include which
- * matches or there is not an exclude which matches.
- * <p>
- * In other words, include patterns override exclude patterns.
- *
- * @param includeRegexes The include regular expressions. May be <code>null</code>.
- * @param excludeRegexes The exclude regular expressions. May be <code>null</code>.
- * @return A String Filter.
- */
- public static Filter<String> buildRegexFilterIncludeOverExclude(List<String> includeRegexes,
- List<String> excludeRegexes) {
- OrFilter<String> includeFilter = new OrFilter<String>();
- if (includeRegexes != null) {
- for (String includeRegex : includeRegexes) {
- includeFilter.addFilter(new RegexStringFilter(includeRegex));
- }
- }
-
- OrFilter<String> excludeFilter = new OrFilter<String>();
- if (excludeRegexes != null) {
- for (String excludeRegex : excludeRegexes) {
- excludeFilter.addFilter(new RegexStringFilter(excludeRegex));
- }
- }
-
- return new OrFilter<String>(includeFilter, new NotFilter<String>(excludeFilter));
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +import java.io.File; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Utility class for working with Filters. Contains builder style methods, + * apply methods, as well as mechanisms for adapting Filters and FilenameFilters. + */ +public class Filters { + + /** + * Filter a given Collection. + * @param <T> Type of the Collection. + * @param filter A Filter upon the Type of objects in the Collection. + * @param collection The Collection to filter. + * @return A List containing only those objects for which the Filter returned <code>true</code>. + */ + public static <T> List<T> filter(Filter<T> filter, Collection<T> collection) { + List<T> list = new ArrayList<T>(); + for (T obj : collection) { + if (filter.filter(obj)) { + list.add(obj); + } + } + return list; + } + + /** + * Get a File Filter for files with the given extensions, ignoring case. + * @param extensions The extensions to filter. + * @return A File Filter. + */ + public static Filter<File> getFileExtensionFilter(String... extensions) { + return new FileExtensionFilter(extensions); + } + + /** + * Get a File Filter for directories. + * @return A File Filter. + */ + public static Filter<File> getDirectoryFilter() { + return DirectoryFilter.INSTANCE; + } + + /** + * Get a File Filter for directories or for files with the given extensions, ignoring case. + * @param extensions The extensions to filter. + * @return A File Filter. + */ + public static Filter<File> getFileExtensionOrDirectoryFilter(String... extensions) { + return new OrFilter<File>(getFileExtensionFilter(extensions), getDirectoryFilter()); + } + + /** + * Given a String Filter, expose as a File Filter. The File paths are + * normalized to a standard pattern using <code>/</code> as a path separator + * which can be used cross platform easily in a regular expression based + * String Filter. + * + * @param filter A String Filter. + * @return A File Filter. + */ + public static Filter<File> toNormalizedFileFilter(final Filter<String> filter) { + return new Filter<File>() { + public boolean filter(File file) { + String path = file.getPath(); + path = path.replace('\\', '/'); + return filter.filter(path); + } + + public String toString() { + return filter.toString(); + } + }; + } + + /** + * Given a String Filter, expose as a Filter on another type. The + * <code>toString()</code> method is called on the objects of the other + * type and delegated to the String Filter. + * @param <T> The desired type. + * @param filter The existing String Filter. + * @return A Filter on the desired type. + */ + public static <T> Filter<T> fromStringFilter(final Filter<String> filter) { + return new Filter<T>() { + public boolean filter(T obj) { + return filter.filter(obj.toString()); + } + + public String toString() { + return filter.toString(); + } + }; + } + + /** + * Given a File Filter, expose as a FilenameFilter. + * @param filter The File Filter. + * @return A FilenameFilter. + */ + public static FilenameFilter toFilenameFilter(final Filter<File> filter) { + return new FilenameFilter() { + public boolean accept(File dir, String name) { + return filter.filter(new File(dir, name)); + } + + public String toString() { + return filter.toString(); + } + }; + } + + /** + * Given a FilenameFilter, expose as a File Filter. + * @param filter The FilenameFilter. + * @return A File Filter. + */ + public static Filter<File> toFileFilter(final FilenameFilter filter) { + return new Filter<File>() { + public boolean filter(File file) { + return filter.accept(file.getParentFile(), file.getName()); + } + + public String toString() { + return filter.toString(); + } + }; + } + + /** + * Construct a String Filter using set of include and exclude regular + * expressions. If there are no include regular expressions provide, then + * a regular expression is added which matches every String by default. + * A String is included as long as it matches an include regular expression + * and does not match an exclude regular expression. + * <p> + * In other words, exclude patterns override include patterns. + * + * @param includeRegexes The include regular expressions. May be <code>null</code>. + * @param excludeRegexes The exclude regular expressions. May be <code>null</code>. + * @return A String Filter. + */ + public static Filter<String> buildRegexFilterExcludeOverInclude(List<String> includeRegexes, + List<String> excludeRegexes) { + OrFilter<String> includeFilter = new OrFilter<String>(); + if (includeRegexes == null || includeRegexes.size() == 0) { + includeFilter.addFilter(new RegexStringFilter(".*")); + } else { + for (String includeRegex : includeRegexes) { + includeFilter.addFilter(new RegexStringFilter(includeRegex)); + } + } + + OrFilter<String> excludeFilter = new OrFilter<String>(); + if (excludeRegexes != null) { + for (String excludeRegex : excludeRegexes) { + excludeFilter.addFilter(new RegexStringFilter(excludeRegex)); + } + } + + return new AndFilter<String>(includeFilter, new NotFilter<String>(excludeFilter)); + } + + /** + * Construct a String Filter using set of include and exclude regular + * expressions. If there are no include regular expressions provide, then + * a regular expression is added which matches every String by default. + * A String is included as long as the case that there is an include which + * matches or there is not an exclude which matches. + * <p> + * In other words, include patterns override exclude patterns. + * + * @param includeRegexes The include regular expressions. May be <code>null</code>. + * @param excludeRegexes The exclude regular expressions. May be <code>null</code>. + * @return A String Filter. + */ + public static Filter<String> buildRegexFilterIncludeOverExclude(List<String> includeRegexes, + List<String> excludeRegexes) { + OrFilter<String> includeFilter = new OrFilter<String>(); + if (includeRegexes != null) { + for (String includeRegex : includeRegexes) { + includeFilter.addFilter(new RegexStringFilter(includeRegex)); + } + } + + OrFilter<String> excludeFilter = new OrFilter<String>(); + if (excludeRegexes != null) { + for (String excludeRegex : excludeRegexes) { + excludeFilter.addFilter(new RegexStringFilter(excludeRegex)); + } + } + + return new OrFilter<String>(includeFilter, new NotFilter<String>(excludeFilter)); + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/NotFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/NotFilter.java index e82ca332a53..aeb77ce4bbe 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/NotFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/NotFilter.java @@ -1,45 +1,45 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-/**
- * A logical NEGATION of a Filter.
- *
- * @param <T>
- * The underlying type on which the filter applies.
- */
-public class NotFilter<T> extends AbstractDelegateFilter<T> {
- public NotFilter() {
- super();
- }
-
- public NotFilter(Filter<T> filter) {
- super(filter);
- }
-
- public boolean filter(T obj) {
- return !filter.filter(obj);
- }
-
- public String toString() {
- return "not (" + filter + ")";
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +/** + * A logical NEGATION of a Filter. + * + * @param <T> + * The underlying type on which the filter applies. + */ +public class NotFilter<T> extends AbstractDelegateFilter<T> { + public NotFilter() { + super(); + } + + public NotFilter(Filter<T> filter) { + super(filter); + } + + public boolean filter(T obj) { + return !filter.filter(obj); + } + + public String toString() { + return "not (" + filter + ")"; + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/OrFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/OrFilter.java index df561b8f011..142d4131b26 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/OrFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/OrFilter.java @@ -1,54 +1,54 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-/**
- * A logical OR of a list of Filters. This implementation is short circuiting.
- *
- * @param <T>
- * The underlying type on which the filter applies.
- */
-public class OrFilter<T> extends AbstractCompoundFilter<T> {
-
- public OrFilter() {
- super();
- }
-
- public OrFilter(Filter<T>... filters) {
- super(filters);
- }
-
- public boolean filter(T obj) {
- boolean match = false;
- for (Filter<T> filter : filters) {
- if (filter.filter(obj)) {
- match = true;
- break;
- }
- }
- return match;
- }
-
- @Override
- protected String getOperator() {
- return "or";
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +/** + * A logical OR of a list of Filters. This implementation is short circuiting. + * + * @param <T> + * The underlying type on which the filter applies. + */ +public class OrFilter<T> extends AbstractCompoundFilter<T> { + + public OrFilter() { + super(); + } + + public OrFilter(Filter<T>... filters) { + super(filters); + } + + public boolean filter(T obj) { + boolean match = false; + for (Filter<T> filter : filters) { + if (filter.filter(obj)) { + match = true; + break; + } + } + return match; + } + + @Override + protected String getOperator() { + return "or"; + } +} diff --git a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/RegexStringFilter.java b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/RegexStringFilter.java index 7d2615db9ee..b23b202d783 100644 --- a/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/RegexStringFilter.java +++ b/sonar-duplications/src/main/java/net/sourceforge/pmd/util/filter/RegexStringFilter.java @@ -1,60 +1,60 @@ -/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-
-package net.sourceforge.pmd.util.filter;
-
-import java.util.regex.Pattern;
-
-/**
- * A filter to which uses a regular expression to match upon Strings.
- */
-public class RegexStringFilter implements Filter<String> {
-
- protected String regex;
-
- protected Pattern pattern;
-
- public RegexStringFilter() {
- }
-
- public RegexStringFilter(String regex) {
- this.regex = regex;
- }
-
- public String getRegex() {
- return regex;
- }
-
- public void setRegex(String regex) {
- this.regex = regex;
- this.pattern = null;
- }
-
- public boolean filter(String obj) {
- if (pattern == null) {
- pattern = Pattern.compile(regex);
- }
- return pattern.matcher(obj).matches();
- }
-
- public String toString() {
- return "matches " + regex;
- }
-}
+/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ + +package net.sourceforge.pmd.util.filter; + +import java.util.regex.Pattern; + +/** + * A filter to which uses a regular expression to match upon Strings. + */ +public class RegexStringFilter implements Filter<String> { + + protected String regex; + + protected Pattern pattern; + + public RegexStringFilter() { + } + + public RegexStringFilter(String regex) { + this.regex = regex; + } + + public String getRegex() { + return regex; + } + + public void setRegex(String regex) { + this.regex = regex; + this.pattern = null; + } + + public boolean filter(String obj) { + if (pattern == null) { + pattern = Pattern.compile(regex); + } + return pattern.matcher(obj).matches(); + } + + public String toString() { + return "matches " + regex; + } +} diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CPD.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CPD.java index 7e1319d0cf3..8d193f30b64 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CPD.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CPD.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CodeLoaderWithoutCache.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CodeLoaderWithoutCache.java index 34339a0a74c..24abfc5ad55 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CodeLoaderWithoutCache.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/CodeLoaderWithoutCache.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/FileCodeLoaderWithoutCache.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/FileCodeLoaderWithoutCache.java index 738d03e116e..dee15b8e52a 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/FileCodeLoaderWithoutCache.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/FileCodeLoaderWithoutCache.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java index 8d35729b0e5..a4f44aa335a 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/Match.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchAlgorithm.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchAlgorithm.java index 80b50751cbb..c94b69fee14 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchAlgorithm.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchAlgorithm.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchCollector.java b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchCollector.java index 8f5da22fbf3..219d0b8bd71 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchCollector.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/cpd/MatchCollector.java @@ -1,6 +1,6 @@ /* * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA + * Copyright (C) 2008-2011 SonarSource * mailto:contact AT sonarsource DOT com * * Sonar is free software; you can redistribute it and/or |