1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.usageprofiles; |
---|
16 | |
---|
17 | import java.io.Serializable; |
---|
18 | |
---|
19 | /** |
---|
20 | * <p> |
---|
21 | * This interface can be used for implementing comparison strategies for symbols. |
---|
22 | * </p> |
---|
23 | * |
---|
24 | * @author Patrick Harms |
---|
25 | */ |
---|
26 | public interface SymbolComparator<T> extends Serializable { |
---|
27 | |
---|
28 | /** |
---|
29 | * <p> |
---|
30 | * compares two symbols and returns true, if the concrete comparison strategy sees both |
---|
31 | * symbols as equal. The method must be commutative, i.e., |
---|
32 | * <code>equals(symbol1, symbol2) == equals(symbol2, symbol1)</code>. |
---|
33 | * </p> |
---|
34 | * |
---|
35 | * @param symbol1 the first symbol to be compared |
---|
36 | * @param symbol2 the second symbol to be compared |
---|
37 | * |
---|
38 | * @return true if the comparison strategy sees both symbols as equal, false else. |
---|
39 | */ |
---|
40 | public boolean equals(T symbol1, T symbol2); |
---|
41 | |
---|
42 | /** |
---|
43 | * <p> |
---|
44 | * returns a search order for buckets. This method can be used for optimizing a search for |
---|
45 | * equal symbols. The client of this class can store symbols in buckets of similar symbols. |
---|
46 | * Those buckets get an id denoted by an integer. The most appropriate bucket for a symbol is |
---|
47 | * the first element in the array returned by this method. The symbol should therefore be put |
---|
48 | * into that bucket. |
---|
49 | * </p> |
---|
50 | * <p> |
---|
51 | * In case a search for an equal symbol shall be performed at the client side, the client |
---|
52 | * checks the available buckets in the order given as return value of this method. All other |
---|
53 | * buckets are searched afterwards. In this scenario it is ensured, that the equal symbol is |
---|
54 | * found as soon as possible as the search always starts in the most appropriate bucket. |
---|
55 | * However, the other buckets are searched, as well, if no equal symbol is found. Therefore, |
---|
56 | * in the worst case, all buckets are searched. In the optimal case, the equal symbol is found |
---|
57 | * in the first bucket. |
---|
58 | * </p> |
---|
59 | * <p> |
---|
60 | * The returned array should contain different integers in each field. This allows a most |
---|
61 | * efficient search. If an integer is repeated, it is up to the clien, if this is ignored. |
---|
62 | * </p> |
---|
63 | * |
---|
64 | * @param symbol the symbol for which the bucket order is to be returned |
---|
65 | * |
---|
66 | * @return a search order for buckets as described |
---|
67 | * |
---|
68 | * @see SymbolMap |
---|
69 | */ |
---|
70 | public int[] getBucketSearchOrder(T symbol); |
---|
71 | } |
---|