View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.finder;
18  
19  import java.io.File;
20  import java.util.EventObject;
21  
22  /**
23   * Event upon which notification is made to a FindListener.
24   * It contains references to the Finder and the Directory in which 
25   * the event occured.
26   * Depending on the particular occasion, it may also contain 
27   * a set of files or a file.
28   */
29  // TODO: Extend this to 3 subclasses to stop having 1 class with 3 types
30  public class FindEvent extends EventObject {
31  
32      private File directory;
33      private Finder finder;
34      private File file;
35      private File[] files;
36      private String type;
37  
38      public FindEvent(Finder finder, String type, File directory) {
39          super(directory);
40          this.finder = finder;
41          this.directory = directory;
42          this.type = type;
43      }
44      
45      public FindEvent(Finder finder, String type, File directory, File file) {
46          super(file);
47          this.finder = finder;
48          this.directory = directory;
49          this.file = file;
50          this.type = type;
51      }
52      
53      public FindEvent(Finder finder, String type, File directory, File[] files) {
54          super(files);
55          this.finder = finder;
56          this.directory = directory;
57          this.files = files;
58          this.type = type;
59      }
60  
61      public File getDirectory() {
62          return this.directory;
63      }
64      
65      public Finder getFinder() {
66          return this.finder;
67      }
68      
69      /**
70       * File found.
71       */
72      public File getFile() {
73          return this.file;
74      }
75      
76      /**
77       * Files found in a directory.
78       */
79      public File[] getFiles() {
80          return this.files;
81      }
82  
83      public String getType() {
84          return this.type;
85      }
86  
87      public String toString() {
88          String str = "FindEvent - "+this.type+"; dir="+this.directory+", file="+this.file;
89          if(this.files != null) {
90              str += ", files="+java.util.Arrays.asList(this.files);
91          }
92          return str;
93      }
94  
95  }