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