View Javadoc

1   /* Copyright (c) 2008 Sascha Kohlmann
2    *
3    * This program is free software: you can redistribute it and/or modify
4    * it under the terms of the GNU Affero General Public License as published by
5    * the Free Software Foundation, either version 3 of the License, or
6    * (at your option) any later version.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Affero General Public License for more details.
12   *
13   * You should have received a copy of the GNU Affero General Public License
14   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15   */
16  package net.sf.eos.trie;
17  
18  import java.util.EventListener;
19  import java.util.EventObject;
20  import java.util.Map.Entry;
21  
22  public interface TrieSource {
23  
24      public static class TrieEntryEvent extends EventObject {
25          public TrieEntryEvent(final TrieEntry source) {
26              super(source);
27          }
28      }
29  
30      public static interface TrieEntryListener extends EventListener {
31          void onEntry(final TrieEntryEvent event);
32      }
33  
34      /**
35       * Represents an entry in the Trie.
36       * @author Sascha Kohlmann
37       */
38      public static class TrieEntry implements Entry<String, String> {
39  
40          private final String key;
41          private String value;
42  
43          /** Creates a new instance for the given key.
44           * @param key the key of the entry */
45          public TrieEntry(@SuppressWarnings("hiding") final String key) {
46              this(key, null);
47          }
48  
49          /** Creates a new instance for the given key.
50           * @param key the key of the entry 
51           * @param value the value of the entry */
52          @SuppressWarnings("nls") 
53          public TrieEntry(@SuppressWarnings("hiding") final String key,
54                           @SuppressWarnings("hiding") final String value) {
55              if (key == null) {
56                  throw new IllegalArgumentException("key is null");
57              }
58              this.key = key;
59              this.value = value;
60          }
61  
62          /**
63           * @see Entry#getKey()
64           */
65          public String getKey() {
66              return this.key;
67          }
68  
69          /**
70           * @see Entry#getValue()
71           */
72          public String getValue() {
73              return this.value;
74          }
75  
76          /**
77           * @see Entry#setValue(Object)
78           */
79          public String setValue(@SuppressWarnings("hiding") final String value) {
80              final String old = this.value;
81              this.value = value;
82              return old;
83          }
84      }
85  
86      public void addTrieEntryListener(final TrieEntryListener listener);
87  
88      public void removeTrieEntryListener(final TrieEntryListener listener);
89  }