All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bdrc.lucene.sa.PartOfSpeechAttributeImpl Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package io.bdrc.lucene.sa;

import org.apache.lucene.util.AttributeImpl;
import org.apache.lucene.util.AttributeReflector;

/** Default implementation of {@link PartOfSpeechAttribute}. */
public class PartOfSpeechAttributeImpl extends AttributeImpl implements PartOfSpeechAttribute, Cloneable {
    
    private PartOfSpeech pos = PartOfSpeech.Unknown;
    
    public PartOfSpeechAttributeImpl() {}
    
    /**
     * Initialize this attribute with pos
     * @param pos part of speech
     */
    public PartOfSpeechAttributeImpl(PartOfSpeech pos) {
        super();
        this.pos = pos;
    }
    
    @Override
    public void setPartOfSpeech(PartOfSpeech pos) {
        this.pos = pos;
    }

    @Override
    public PartOfSpeech getPartOfSpeech() {
        return pos;
    }

    @Override
    public void clear() {
        pos = PartOfSpeech.Unknown;
    }

    @Override
    public void copyTo(AttributeImpl target) {
        ((PartOfSpeechAttribute) target).setPartOfSpeech(PartOfSpeech.Unknown);
    }

    @Override
    public boolean equals(Object other) {
      if (other == this) {
        return true;
      }
      
      if (other instanceof PartOfSpeechAttributeImpl) {
        final PartOfSpeechAttributeImpl o = (PartOfSpeechAttributeImpl) other;
        return (this.pos == null ? o.pos == null : this.pos.equals(o.pos));
      }
      
      return false;
    }
    
    @Override
    public void reflectWith(AttributeReflector reflector) {
        // inspired by https://github.com/apache/lucene-solr/blob/branch_6_4/lucene/core/src/java/org/apache/lucene/util/AttributeImpl.java#L78
        reflector.reflect(PartOfSpeechAttribute.class, "pos", pos);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy