// -----------------------------------------------------------------------
//
//
// 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;
using System.Diagnostics.CodeAnalysis;
using Support;
using Util;
// DOCS: enhance FlagsAttribute summary
///
/// This attribute is used to pass different flags down the tokenizer chain. i.e. from one TokenFilter to another
/// TokenFilter.
///
///
///
///
/// Java File:
/// lucene/src/java/org/apache/lucene/analysis/tokenattributes/FlagsAttributeImpl.java
///
///
///
/// C# File:
/// src/Lucene.Net/Analysis/TokenAttributes/FlagsAttribute.cs
///
///
///
/// C# Tests:
/// test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs
///
///
///
///
[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.")]
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms",
Justification = "Again, using the class name from java and its appropriate.")]
public class FlagsAttribute : AttributeBase, IFlagsAttribute
{
///
/// Initializes a new instance of the class.
///
public FlagsAttribute()
{
}
///
/// Initializes a new instance of the class.
///
/// The flags.
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms",
Justification = "The variable name is appropriate.")]
public FlagsAttribute(int flags)
{
this.Flags = flags;
}
///
/// Gets or sets the flags.
///
/// The flags.
[SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms",
Justification = "The name is appropriate.")]
public int Flags { get; set; }
///
/// Clears the instance of its flags.
///
public override void Clear()
{
this.Flags = 0;
}
///
/// Creates a clone of the object, generally shallow.
///
/// an the clone of the current instance.
public override AttributeBase Clone()
{
return new FlagsAttribute { Flags = this.Flags };
}
///
/// Copies to the specified attribute.
///
/// The object that is being copied to.
///
/// Thrown when the is not an .
///
public override void CopyTo(AttributeBase attributeBase)
{
IFlagsAttribute attribute = attributeBase as IFlagsAttribute;
if (attribute == null)
throw new ArgumentException(
"The parameter 'attributeBase' must be of type {0} in order to be copied"
.Inject(this.GetType().FullName),
"attributeBase");
attribute.Flags = this.Flags;
}
///
/// 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.Flags;
}
///
/// 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;
FlagsAttribute attribute = obj as FlagsAttribute;
if (attribute != null)
return attribute.Flags == this.Flags;
return false;
}
}
}