LUCENE-3686: CategoryEnhancement must override Object.equals()

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1230431 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2012-01-12 07:43:42 +00:00
parent ba60b2f98a
commit d74db06ddf
2 changed files with 43 additions and 25 deletions

View File

@ -47,24 +47,24 @@ import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
* @lucene.experimental
*/
public interface CategoryEnhancement {
/**
* Get the bytes to be added to the category token payload for this
* enhancement.
* <p>
* <b>NOTE</b>: The returned array is copied, it is recommended to allocate
* a new one each time.
* <b>NOTE</b>: The returned array is copied, it is recommended to allocate a
* new one each time.
* <p>
* The bytes generated by this method are the input of
* {@link #extractCategoryTokenData(byte[], int, int)}.
*
* @param categoryAttribute
* The attribute of the category.
* The attribute of the category.
* @return The bytes to be added to the category token payload for this
* enhancement.
*/
byte[] getCategoryTokenBytes(CategoryAttribute categoryAttribute);
/**
* Get the data of this enhancement from a category token payload.
* <p>
@ -72,56 +72,61 @@ public interface CategoryEnhancement {
* {@link #getCategoryTokenBytes(CategoryAttribute)}.
*
* @param buffer
* The payload buffer.
* The payload buffer.
* @param offset
* The offset of this enhancement's data in the buffer.
* The offset of this enhancement's data in the buffer.
* @param length
* The length of this enhancement's data (bytes).
* The length of this enhancement's data (bytes).
* @return An Object containing the data.
*/
Object extractCategoryTokenData(byte[] buffer, int offset, int length);
/**
* Declarative method to indicate whether this enhancement generates
* separate category list.
* Declarative method to indicate whether this enhancement generates separate
* category list.
*
* @return {@code true} if generates category list, else {@code false}.
*/
boolean generatesCategoryList();
/**
* Returns the text of this enhancement's category list term.
*
* @return The text of this enhancement's category list term.
*/
String getCategoryListTermText();
/**
* Get the {@link CategoryListTokenizer} which generates the category list
* for this enhancement. If {@link #generatesCategoryList()} returns
* {@code false} this method will not be called.
* Get the {@link CategoryListTokenizer} which generates the category list for
* this enhancement. If {@link #generatesCategoryList()} returns {@code false}
* this method will not be called.
*
* @param tokenizer
* The input stream containing categories.
* The input stream containing categories.
* @param indexingParams
* The indexing params to use.
* The indexing params to use.
* @param taxonomyWriter
* The taxonomy to add categories and get their ordinals.
* The taxonomy to add categories and get their ordinals.
* @return A {@link CategoryListTokenizer} generating the category list for
* this enhancement, with {@code tokenizer} as it's input.
*/
CategoryListTokenizer getCategoryListTokenizer(TokenStream tokenizer,
EnhancementsIndexingParams indexingParams,
TaxonomyWriter taxonomyWriter);
EnhancementsIndexingParams indexingParams, TaxonomyWriter taxonomyWriter);
/**
* Get a {@link CategoryProperty} class to be retained when creating
* {@link CategoryParentsStream}.
*
* @return the {@link CategoryProperty} class to be retained when creating
* {@link CategoryParentsStream}, or {@code null} if there is no
* such property.
* {@link CategoryParentsStream}, or {@code null} if there is no such
* property.
*/
Class<? extends CategoryProperty> getRetainableProperty();
/**
* Category enhancements must override {@link Object#equals(Object)}, as it is
* used in
* {@link EnhancementsPayloadIterator#getCategoryData(CategoryEnhancement)}.
*/
public boolean equals(Object o);
}

View File

@ -150,4 +150,17 @@ public class AssociationEnhancement implements CategoryEnhancement {
return null;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
return (o instanceof AssociationEnhancement);
}
@Override
public int hashCode() {
return super.hashCode();
}
}