You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AccumulatingFileFilter.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2000 Xerox Corporation.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.testing.util;
  13. import java.io.File;
  14. import java.util.Vector;
  15. /**
  16. * A FileFilter that accumulates the results when called if they exist.
  17. * Subclasses override accumulate to determine whether it should be
  18. * accumulated.
  19. */
  20. public class AccumulatingFileFilter extends ValidFileFilter {
  21. Vector<File> files = new Vector<File>();
  22. public final boolean accept(File f) {
  23. if (super.accept(f) && (accumulate(f))) {
  24. files.add(f);
  25. }
  26. return true;
  27. }
  28. /**
  29. * This implementation accumulates everything.
  30. * Subclasses should override to implement filter
  31. * @param file a File guaranteed to exist
  32. * @return true if file should be accumulated.
  33. */
  34. public boolean accumulate(File f) {
  35. return true;
  36. }
  37. /**
  38. * @return list of files currently accumulated
  39. */
  40. public File[] getFiles() {
  41. int numFiles = files.size();
  42. File[] result = new File[numFiles];
  43. if (0 < numFiles) {
  44. files.copyInto(result);
  45. }
  46. return result;
  47. }
  48. }