/
FriendLibraryPropertyAutoCompleter.java
executable file
·65 lines (53 loc) · 1.96 KB
/
FriendLibraryPropertyAutoCompleter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.limewire.core.impl.library;
import java.util.Collection;
import java.util.Iterator;
import org.limewire.collection.AutoCompleteDictionary;
import org.limewire.core.api.FilePropertyKey;
import org.limewire.core.api.search.SearchCategory;
/**
* Provides suggestions for a query based on category and file property key for what the user's friends
* have in their libraries for that category.
*/
class FriendLibraryPropertyAutoCompleter implements AutoCompleteDictionary {
private final FriendLibraries friendLibraries;
private final SearchCategory category;
private final FilePropertyKey filePropertyKey;
public FriendLibraryPropertyAutoCompleter(FriendLibraries friendLibraries, SearchCategory category, FilePropertyKey filePropertyKey) {
this.friendLibraries = friendLibraries;
this.category = category;
this.filePropertyKey = filePropertyKey;
}
@Override
public boolean isImmediate() {
return false;
}
public void addEntry(String entry) {
throw new UnsupportedOperationException();
}
public boolean removeEntry(String entry) {
throw new UnsupportedOperationException();
}
public String lookup(String prefix) {
try {
Iterator<String> it = getPrefixedBy(prefix).iterator();
if (!it.hasNext())
return null;
return it.next();
} catch(InterruptedException ie) {
throw new IllegalStateException(ie);
}
}
public Iterator<String> iterator() {
try {
return getPrefixedBy("").iterator();
} catch(InterruptedException ie) {
throw new IllegalStateException(ie);
}
}
public Collection<String> getPrefixedBy(String prefix) throws InterruptedException {
return friendLibraries.getSuggestions(prefix, category, filePropertyKey);
}
public void clear() {
throw new UnsupportedOperationException();
}
}