// -----------------------------------------------------------------------
//
//
// 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;
using Lucene.Net.Index;
using Lucene.Net.Util;
///
/// The payload of a Token.
///
///
[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 PayloadAttribute : AttributeBase, IPayloadAttribute
{
///
/// Initializes a new instance of the class.
///
public PayloadAttribute()
{
}
///
/// Initializes a new instance of the class.
///
/// The payload.
public PayloadAttribute(Payload payload)
{
this.Payload = payload;
}
///
/// Gets or sets the payload.
///
/// The payload.
public Index.Payload Payload { get; set; }
///
/// Clears the instance.
///
public override void Clear()
{
this.Payload = null;
}
///
/// Creates a clone of the object, generally shallow.
///
/// an the clone of the current instance.
public override AttributeBase Clone()
{
PayloadAttribute clone = (PayloadAttribute)this.MemberwiseClone();
if (this.Payload != null)
clone.Payload = (Payload)this.Payload.Clone();
return clone;
}
///
/// Copies this instance to the specified target.
///
/// The attribute base.
public override void CopyTo(AttributeBase attributeBase)
{
IPayloadAttribute attribute = (IPayloadAttribute)attributeBase;
attribute.Payload = this.Payload == null ? null : (Payload)this.Payload.Clone();
}
///
/// 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;
PayloadAttribute attribute = obj as PayloadAttribute;
if (attribute == null)
return false;
if (attribute.Payload == null || this.Payload == null)
return attribute.Payload == null && this.Payload == null;
return attribute.Payload.Equals(this.Payload);
}
///
/// 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.Payload == null ? 0 : this.Payload.GetHashCode();
}
}
}