| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Order |
|
| 0.0;0 |
| 1 | // BSD License (http://galagosearch.org) | |
| 2 | ||
| 3 | package org.galagosearch.tupleflow; | |
| 4 | ||
| 5 | import java.util.Collection; | |
| 6 | import java.util.Comparator; | |
| 7 | ||
| 8 | /** | |
| 9 | * An Order is a class that represents an ordering of a Galago Type. You won't usually | |
| 10 | * implement this interface directly; instead, let Galago make the class for you | |
| 11 | * with the TemplateTypeBuilder/TypeBuilderMojo tools. | |
| 12 | * | |
| 13 | * @author trevor | |
| 14 | * @param <T> The ordered class. | |
| 15 | */ | |
| 16 | public interface Order<T> { | |
| 17 | /// Returns the class ordered by this Order. | |
| 18 | public Class<T> getOrderedClass(); | |
| 19 | /** | |
| 20 | * Returns a string representation of the fields ordered by this class. For example: | |
| 21 | * <pre>{ "+document", "-score" }</pre> | |
| 22 | * means that this order orders first by the document number in ascending order, but | |
| 23 | * breaks ties by the score in descending order. | |
| 24 | */ | |
| 25 | public String[] getOrderSpec(); | |
| 26 | ||
| 27 | /** | |
| 28 | * Returns a comparator that applies this order to objects of type T. | |
| 29 | * For example, if <pre>getOrderSpec() == { "+document" }</pre> and | |
| 30 | * a.document = 5 and b.document = 7, then: | |
| 31 | * <pre>lessThan().compare(a, b) < 0</pre>. | |
| 32 | */ | |
| 33 | public Comparator<T> lessThan(); | |
| 34 | /** | |
| 35 | * lessThan().compare(a,b) = greaterThan().compare(b,a); | |
| 36 | */ | |
| 37 | public Comparator<T> greaterThan(); | |
| 38 | ||
| 39 | /** | |
| 40 | * This is a hash function over an object that only uses ordered fields. | |
| 41 | * For instance, if the order is <pre>{ "+document", "-score" }</pre>, this | |
| 42 | * hash function incorporates data from the document and score fields, but | |
| 43 | * no other fields. | |
| 44 | * | |
| 45 | * @param object | |
| 46 | * @return | |
| 47 | */ | |
| 48 | public int hash(T object); | |
| 49 | ||
| 50 | /** | |
| 51 | * Produces an OrderedWriter object that can write objects of class T in this | |
| 52 | * order. This object assumes that its input is already correctly ordered. | |
| 53 | * The OrderedWriter uses the ordering property to write the data in | |
| 54 | * compressed form. | |
| 55 | * | |
| 56 | * @param output | |
| 57 | * @return | |
| 58 | */ | |
| 59 | public Processor<T> orderedWriter(ArrayOutput output); | |
| 60 | ||
| 61 | /** | |
| 62 | * Produces an OrderedReader object. This object can read objects that were | |
| 63 | * written with an OrderedWriter object produced by the Order.orderedWriter method. | |
| 64 | * | |
| 65 | * @param input | |
| 66 | * @return | |
| 67 | */ | |
| 68 | public TypeReader<T> orderedReader(ArrayInput input); | |
| 69 | ||
| 70 | /** | |
| 71 | * Produces an OrderedReader object. This is just like the previous orderedReader | |
| 72 | * method, except you can explicitly set a buffer size. | |
| 73 | * | |
| 74 | * @param input | |
| 75 | * @param bufferSize | |
| 76 | * @return | |
| 77 | */ | |
| 78 | public TypeReader<T> orderedReader(ArrayInput input, int bufferSize); | |
| 79 | ||
| 80 | /** | |
| 81 | * Produces an OrderedCombiner object. An ordered combiner merges objects | |
| 82 | * from many OrderedReaders into a single ordered stream of objects. | |
| 83 | * | |
| 84 | * @param readers | |
| 85 | * @param closeOnExit | |
| 86 | * @return | |
| 87 | */ | |
| 88 | public ReaderSource<T> orderedCombiner(Collection<TypeReader<T>> readers, boolean closeOnExit); | |
| 89 | } |