Esempio n. 1
0
 /// <summary> An AttributeSource that uses the same attributes as the supplied one.</summary>
 public AttributeSource(AttributeSource input)
 {
     if (input == null)
     {
         throw new System.ArgumentException("input AttributeSource must not be null");
     }
     this.attributes     = input.attributes;
     this.attributeImpls = input.attributeImpls;
     this.factory        = input.factory;
 }
Esempio n. 2
0
        public override bool Equals(System.Object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            if (obj is AttributeSource)
            {
                AttributeSource other = (AttributeSource)obj;

                if (HasAttributes())
                {
                    if (!other.HasAttributes())
                    {
                        return(false);
                    }

                    if (this.attributeImpls.Count != other.attributeImpls.Count)
                    {
                        return(false);
                    }

                    // it is only equal if all attribute impls are the same in the same order
                    if (this.currentState == null)
                    {
                        this.ComputeCurrentState();
                    }
                    State thisState = this.currentState;
                    if (other.currentState == null)
                    {
                        other.ComputeCurrentState();
                    }
                    State otherState = other.currentState;
                    while (thisState != null && otherState != null)
                    {
                        if (otherState.attribute.GetType() != thisState.attribute.GetType() || !otherState.attribute.Equals(thisState.attribute))
                        {
                            return(false);
                        }
                        thisState  = thisState.next;
                        otherState = otherState.next;
                    }
                    return(true);
                }
                else
                {
                    return(!other.HasAttributes());
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
		/// <summary> Performs a clone of all {@link AttributeImpl} instances returned in a new
		/// AttributeSource instance. This method can be used to e.g. create another TokenStream
		/// with exactly the same attributes (using {@link #AttributeSource(AttributeSource)})
		/// </summary>
		public virtual AttributeSource CloneAttributes()
		{
			AttributeSource clone = new AttributeSource(this.factory);
			
			// first clone the impls
			if (HasAttributes())
			{
				if (currentState == null)
				{
					ComputeCurrentState();
				}
				for (State state = currentState; state != null; state = state.next)
				{
					AttributeImpl impl = (AttributeImpl) state.attribute.Clone();
                    clone.attributeImpls.Add(new SupportClass.AttributeImplItem(impl.GetType(), impl));
				}
			}
			
			// now the interfaces
            foreach (SupportClass.AttributeImplItem att in this.attributes)
			{
                clone.attributes.Add(new SupportClass.AttributeImplItem(att.Key, clone.attributeImpls[att.Value.GetType()].Value));
			}
			
			return clone;
		}
Esempio n. 4
0
		/// <summary> An AttributeSource that uses the same attributes as the supplied one.</summary>
		public AttributeSource(AttributeSource input)
		{
			if (input == null)
			{
				throw new System.ArgumentException("input AttributeSource must not be null");
			}
			this.attributes = input.attributes;
			this.attributeImpls = input.attributeImpls;
			this.factory = input.factory;
		}