示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            HashCodeBuilder hashBuilder = new HashCodeBuilder(SEED, PRIME_NUMBER);

            hashBuilder.Append(CtlIdx).Append(Isn);
            return(hashBuilder.HashCode);
        }
示例#2
0
    /// <summary>
    ///     Appends the fields and values defined by the given object of the given Class.
    /// </summary>
    /// <param name="builder">the builder to Append to</param>
    /// <param name="clazz">the class to Append details of</param>
    /// <param name="obj">the object to Append details of</param>
    /// <param name="useTransients">whether to use transient fields</param>
    private static void reflectionAppend(object obj, Type clazz, HashCodeBuilder builder, bool useTransients)
    {
        var fields =
            clazz.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                            | BindingFlags.GetField);

        //AccessibleObject.setAccessible(fields, true);
        for (var i = 0; i < fields.Length; i++)
        {
            var f = fields[i];

            if (f.Name.IndexOf('$') == -1 &&
                (useTransients || !isTransient(f)) &&
                !f.IsStatic)
            {
                try
                {
                    builder.Append(f.GetValue(obj));
                }
                catch (Exception e)
                {
                    //this can't happen. Would get a Security exception instead
                    //throw a runtime exception in case the impossible happens.
                    throw new Exception("Unexpected IllegalAccessException");
                }
            }
        }
    }
示例#3
0
        public override int GetHashCode()
        {
            HashCodeBuilder hashBuilder = new HashCodeBuilder();

            hashBuilder.Append(StartPosition).Append(EndPosition).Append(Name);
            return(hashBuilder.HashCode);
        }
示例#4
0
        public override int GetHashCode()
        {
            // This might not work properly for blobs.
            var hashBuilder = new HashCodeBuilder();

            hashBuilder.Append((IsNull || Value == null) ? 0 : Value.GetHashCode());
            return(hashBuilder.HashCode);
        }
        public override int GetHashCode()
        {
            HashCodeBuilder hashBuilder = new HashCodeBuilder();

            hashBuilder.Append(dataSourceIdentifier)
            .Append(controlId)
            .Append(rangeComparer.GetHashCode(rangeDataList));
            return(hashBuilder.HashCode);
        }
示例#6
0
        public override int GetHashCode()
        {
            var hashBuilder = new HashCodeBuilder();

            hashBuilder.Append(Discard ? 1 : 2)
            .Append((int)Type)
            .Append(Value == null ? 0 : Value.GetHashCode());
            return(hashBuilder.HashCode);
        }
示例#7
0
        public override int GetHashCode()
        {
            var hashBuilder = new HashCodeBuilder();

            hashBuilder.Append(DatetimeRangeIdx)
            .Append(FieldIndex)
            .Append(Max)
            .Append(Min);
            return(hashBuilder.HashCode);
        }
示例#8
0
        public override int GetHashCode()
        {
            if (!hashCodeBuilded)
            {
                HashCodeBuilder builder = new HashCodeBuilder();

                //StructureType
                builder.Append(StructureType);

                //descriptor
                builder.Append(descriptor);

                //Items
                for (int i = 0; i < Path.Length; i++)
                {
                    builder.Append(Path[i]);
                }

                hashCode        = builder.GetHashCode();
                hashCodeBuilded = true;
            }

            return(hashCode);
        }
示例#9
0
        /// <summary>
        /// Instantiates a new function predicate.
        /// </summary>
        /// <param name="resolutionType">The type of resolution for the function.</param>
        /// <param name="predicate">The predicate value, i.e. the string representation of the function predicate.</param>
        /// <param name="bob">The business object binder to use when evaluating the function, or null.</param>
        /// <param name="name">The name of the function, as it was analyzed by the binder.</param>
        /// <param name="arguments">The array of arguments of the function, as it was analyzed by the binder.</param>
        public Function(FunctionResolutionType resolutionType, string predicate, IBinder bob, string name, params string[] arguments) : base(predicate)
        {
            this.resolutionType = resolutionType;
            this.bob            = bob;
            this.name           = name;
            this.arguments      = arguments;

            var hcb = new HashCodeBuilder(base.GetHashCode()).Append(resolutionType).Append(bob).Append(name);

            foreach (var argument in arguments)
            {
                hcb.Append(argument);
            }
            hashCode = hcb.Value;

            // precalculate the function signature to use in the binder to evaluate the function
            functionSignature = Parameter.BuildFunctionSignature(name, arguments);
        }
示例#10
0
        /// <summary>
        /// Instantiates a new atom group.
        /// </summary>
        /// <param name="logicalOperator">The operator that characterizes the relationship between the atoms and atoms group.</param>
        /// <param name="members">An array containing atoms and atom groups.</param>
        /// <param name="runningMembers">An array containing atoms and atom groups that will actually be run (they can be different
        /// from the members because of atom equivalence).</param>
        internal AtomGroup(LogicalOperator logicalOperator, object[] members, object[] runningMembers)
        {
            this.logicalOperator = logicalOperator;
            this.members         = members;

            HashCodeBuilder hcb = new HashCodeBuilder();

            hcb.Append(logicalOperator);
            SortedList <int, object> sortedMembers = new SortedList <int, object>(Comparer <int> .Default);

            // check the members, compute hashcode and build sorted members list
            for (int i = 0; i < members.Length; i++)
            {
                object member = members[i];

                if (member == null)
                {
                    throw new BREException("An atom group can not contain a null member");
                }
                else if (member is AtomGroup)
                {
                    if (((AtomGroup)member).logicalOperator == logicalOperator)
                    {
                        throw new BREException("An atom group can not contain another group with the same logical operator");
                    }
                }
                else if (member is Atom)
                {
                    if (((Atom)member).HasFormula)
                    {
                        throw new BREException("An atom group can not contain an atom that contains a formula");
                    }
                }
                else
                {
                    throw new BREException("An atom group can not hold objects of type: " + member.GetType());
                }

                hcb.Append(member);

                if (runningMembers == null)
                {
                    sortedMembers.Add(GetMemberSortedIndex(members, i), member);
                }
            }

            hashCode = hcb.Value;

            // the members actually used when processing the atom group are not the ones defined in the rule file (usually because of equivalent atoms definitions)
            if (runningMembers != null)
            {
                for (int i = 0; i < runningMembers.Length; i++)
                {
                    sortedMembers.Add(GetMemberSortedIndex(runningMembers, i), runningMembers[i]);
                }
            }

            orderedMembers = sortedMembers.Values;

            allAtoms = new List <Atom>();
            foreach (object member in orderedMembers)
            {
                if (member is Atom)
                {
                    allAtoms.Add((Atom)member);
                }
                else if (member is AtomGroup)
                {
                    allAtoms.AddRange(((AtomGroup)member).AllAtoms);
                }
            }
        }
示例#11
0
文件: Atom.cs 项目: ilkerhalil/NxBRE
        /// <summary>
        /// Instantiates a new Atom.
        /// </summary>
        /// <param name="negative">Negative Atom.</param>
        /// <param name="label">The Label of the new Fact.</param>
        /// <param name="type">The relation type of the Atom.</param>
        /// <param name="members">Array of predicates associated in the Atom.</param>
        /// <remarks>This is the principal constructor for Atom and descendant objects.</remarks>
        internal Atom(bool negative, string label, string type, params IPredicate[] members)
        {
            this.negative = negative;
            this.label    = (label == String.Empty)?null:label;
            this.type     = type;

            // load the predicates, extracting the slot names if any
            predicates = new IPredicate[members.Length];
            slotNames  = new string[members.Length];
            hasSlot    = false;

            for (int i = 0; i < members.Length; i++)
            {
                if (members[i] is Slot)
                {
                    hasSlot = true;
                    Slot slot = (Slot)members[i];
                    predicates[i] = slot.Predicate;
                    slotNames[i]  = slot.Name;
                }
                else
                {
                    predicates[i] = members[i];
                    slotNames[i]  = String.Empty;
                }
            }

            // initialize long hashcode & other characteristics
            HashCodeBuilder hcb = new HashCodeBuilder().Append(type);

            isFact        = true;
            hasFunction   = false;
            hasFormula    = false;
            hasIndividual = false;
            onlyVariables = true;

            foreach (IPredicate member in predicates)
            {
                hcb.Append(member);

                if (member is Individual)
                {
                    hasIndividual = true;
                }
                else
                {
                    isFact = false;
                }

                if (!(member is Variable))
                {
                    onlyVariables = false;
                }

                if (member is Function)
                {
                    hasFunction = true;
                }
                else if (member is Formula)
                {
                    hasFormula = true;
                }
            }

            hashCode = hcb.Value;

            // initialize signature
            signature = type + predicates.Length;
        }