Beispiel #1
0
        /// <summary>
        /// Checks a validity of a given STON simple-valued entity.
        /// </summary>
        /// <param name="entity">The entity to check the validity of.</param>
        public static void ValidateEntity(IStonSimpleEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            try
            {
                if (entity.GlobalIdentifier != null)
                {
                    ValidateGlobalIdentifier(entity.GlobalIdentifier);
                }
                if (entity.Type != null)
                {
                    ValidateType(entity.Type);
                }

                if (entity.Value == null)
                {
                    throw new StonException("A simple-valued entity cannot have a non-existing value.");
                }
                ValidateSimpleValue(entity.Value);
            }
            catch (StonException ex)
            {
                throw new StonValueException(entity, ex.Message);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Creates a structurally equivalent simple-valued entity from a given entity.
 /// </summary>
 /// <param name="entity">The entity to copy the structure of.</param>
 /// <returns>A structurally equivalent copy of the given entity.</returns>
 public static IStonSimpleEntity Copy(IStonSimpleEntity entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     return(new StonSimpleEntity(entity));
 }
Beispiel #3
0
        /// <summary>
        /// Returns a hash code for a given simple-valued entity, applied to entities semantic equivalence.
        /// </summary>
        /// <param name="obj">The simple-valued entity to get a hash code of.</param>
        /// <returns>The hash code for the entity.</returns>
        public int GetHashCode(IStonSimpleEntity obj)
        {
            if (obj == null)
            {
                return(0);
            }

            int result = TypeComparer.GetHashCode(obj.Type);

            result  = (result << 5) ^ (result >> 27);
            result ^= 0x1010101 * (byte)obj.Value.DataType;
            if (obj.Value.DataType != StonDataType.Null)
            {
                result  = (result << 5) ^ (result >> 27);
                result ^= obj.Value.Content.GetHashCode();
            }

            return(result);
        }
Beispiel #4
0
 /// <summary>
 /// Determines whether two simple-valued entities are semantically equivalent.
 /// </summary>
 /// <param name="x">The first simple-valued entity to compare.</param>
 /// <param name="y">The second simple-valued entity to compare.</param>
 /// <returns>True when entities are semantically equivalent, false otherwise.</returns>
 public bool Equals(IStonSimpleEntity x, IStonSimpleEntity y)
 {
     if (x == y)
     {
         return(true);
     }
     else if (x == null || y == null)
     {
         return(false);
     }
     else if (!TypeComparer.Equals(x.Type, y.Type) || x.Value.DataType != y.Value.DataType)
     {
         return(false);
     }
     else if (x.Value.DataType == StonDataType.Null)
     {
         return(true);
     }
     else
     {
         return(x.Value.Content == y.Value.Content);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Creates a structurally equivalent simple-valued entity from a given entity.
 /// </summary>
 /// <param name="entity">The entity to copy the structure of.</param>
 public StonSimpleEntity(IStonSimpleEntity entity)
     : this(entity.Value, entity.Type, entity.GlobalIdentifier)
 {
 }
Beispiel #6
0
 // writes a simple valued entity
 private void WriteEntity(StonTokenWriter writer, IStonSimpleEntity entity)
 {
     WriteGlobalIdentifier(writer, entity.GlobalIdentifier);
     WriteTypeDefinition(writer, entity.Type);
     WriteSimpleValue(writer, entity.Value);
 }