// -----------------------------------------------------------------------
//
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// -----------------------------------------------------------------------
namespace Lucene.Net.Analysis.TokenAttributes
{
using System.Diagnostics.CodeAnalysis;
///
/// The attribute that can be used to make a token as a keyword. Keyword
/// aware s can decide to modify a token
/// based on the return value of , if the token
/// is modified. Stemming filters for instance can use this attribute
/// to conditionally skip a term if returns true.
///
[SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix",
Justification = "The class was called Attribute in Java. It would be fun to call it Annotation. However, " +
"its probably best to try to honor the correlating names when possible.")]
public class KeywordAttribute : Util.AttributeBase, IKeywordAttribute
{
///
/// Initializes a new instance of the class.
///
public KeywordAttribute()
{
}
///
/// Initializes a new instance of the class.
///
/// if set to true [is keyword].
public KeywordAttribute(bool isKeyword)
{
this.IsKeyword = isKeyword;
}
///
/// Gets or sets a value indicating whether this instance is keyword.
///
///
/// true if this instance is keyword; otherwise, false.
///
public bool IsKeyword { get; set; }
///
/// Clears the instance.
///
public override void Clear()
{
this.IsKeyword = false;
}
///
/// Copies to the target attribute base.
///
/// The attribute base.
public override void CopyTo(Util.AttributeBase attributeBase)
{
IKeywordAttribute attr = (IKeywordAttribute)attributeBase;
attr.IsKeyword = this.IsKeyword;
}
///
/// Determines whether the specified is equal to this instance.
///
/// The to compare with this instance.
///
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj)
{
if (this == obj)
return true;
if (this.GetType() != obj.GetType())
return false;
KeywordAttribute y = obj as KeywordAttribute;
return y != null && this.IsKeyword == y.IsKeyword;
}
///
/// Returns a hash code for this instance.
///
///
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode()
{
return this.IsKeyword ? 31 : 37;
}
}
}