Example #1
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");
                }
            }
        }
    }
        public static void HashCode_Equals_Boxed()
        {
            var hc  = new HashCodeBuilder();
            var obj = (object)hc;

            Assert.Throws <NotSupportedException>(() => obj.Equals(obj));
        }
Example #3
0
        public override int GetHashCode()
        {
            HashCodeBuilder hashBuilder = new HashCodeBuilder();

            hashBuilder.Append(StartPosition).Append(EndPosition).Append(Name);
            return(hashBuilder.HashCode);
        }
        public int GetHashCode(SearchField obj)
        {
            if (obj is null)
            {
                return(0);
            }

            HashCodeBuilder builder = new HashCodeBuilder();

            builder.Add(obj.Name);
            builder.Add(obj.Type);
            builder.Add(obj.IsKey);
            builder.Add(obj.IsHidden);
            builder.Add(obj.IsSearchable);
            builder.Add(obj.IsFilterable);
            builder.Add(obj.IsSortable);
            builder.Add(obj.IsFacetable);
            builder.Add(obj.Analyzer);
            builder.Add(obj.SearchAnalyzer);
            builder.Add(obj.IndexAnalyzer);
            builder.Add(obj.SynonymMaps, CollectionComparer <string> .Shared);
            builder.Add(obj.Fields, SharedFieldsCollection);

            return(builder.ToHashCode());
        }
        public static void HashCode_Combine()
        {
            var hcs = new int[]
            {
                HashCodeBuilder.Combine(1),
                HashCodeBuilder.Combine(1, 2),
                HashCodeBuilder.Combine(1, 2, 3),
                HashCodeBuilder.Combine(1, 2, 3, 4),
                HashCodeBuilder.Combine(1, 2, 3, 4, 5),
                HashCodeBuilder.Combine(1, 2, 3, 4, 5, 6),
                HashCodeBuilder.Combine(1, 2, 3, 4, 5, 6, 7),
                HashCodeBuilder.Combine(1, 2, 3, 4, 5, 6, 7, 8),

                HashCodeBuilder.Combine(2),
                HashCodeBuilder.Combine(2, 3),
                HashCodeBuilder.Combine(2, 3, 4),
                HashCodeBuilder.Combine(2, 3, 4, 5),
                HashCodeBuilder.Combine(2, 3, 4, 5, 6),
                HashCodeBuilder.Combine(2, 3, 4, 5, 6, 7),
                HashCodeBuilder.Combine(2, 3, 4, 5, 6, 7, 8),
                HashCodeBuilder.Combine(2, 3, 4, 5, 6, 7, 8, 9),
            };

            for (int i = 0; i < hcs.Length; i++)
            {
                for (int j = 0; j < hcs.Length; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    Assert.AreNotEqual(hcs[i], hcs[j]);
                }
            }
        }
Example #6
0
 public override int GetHashCode()
 {
     var hashCode = new HashCodeBuilder();
     hashCode.Add(Name, StringComparer.OrdinalIgnoreCase);
     hashCode.Add(Value);
     return hashCode.ToHashCode();
 }
Example #7
0
        public void HashCollisionTest()
        {
            Random random = new Random(17);

            int arraySize  = 40;
            int arrayCount = 10000;
            var hashes     = new List <int>();

            foreach (var i in Enumerable.Range(0, arrayCount))
            {
                var array = Enumerable.Range(0, arraySize).Select(a => random.NextDouble()).ToArray();

                var hash = new HashCodeBuilder().Append(array).HashCode;
                hashes.Add(hash);

                // modifiy just one element and rehash
                array[array.Length - 1] = random.NextDouble();
                var hash2 = new HashCodeBuilder().Append(array).HashCode;
                hashes.Add(hash2);
            }

            int distinctHashCount = hashes.Distinct().Count();

            Assert.AreEqual(arrayCount * 2, distinctHashCount);
        }
 public override int GetHashCode()
 {
     // Currently the hash code is simply the hash of the authority and first scope as this is what is used to determine equality.
     // This assumes that Authority Scopes are always non-null and Scopes has a length of one.
     // This is guaranteed by the way the AuthenticationChallenge cache is constructed.
     return(HashCodeBuilder.Combine(Authority, Scopes[0]));
 }
        public static void HashCode_Combine_Add_1()
        {
            var hc = new HashCodeBuilder();

            hc.Add(1);
            Assert.AreEqual(hc.ToHashCode(), HashCodeBuilder.Combine(1));
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            HashCodeBuilder hashBuilder = new HashCodeBuilder(SEED, PRIME_NUMBER);

            hashBuilder.Append(CtlIdx).Append(Isn);
            return(hashBuilder.HashCode);
        }
 public void HashCode_DifferentObjectsDifferentPropertyWhichWillBeChecked_DifferentHashCode()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().With(m => m.Prop1).Compile();
     var fooBuilder = FooBuilder.AFoo().WithDummyProp2();
     var foo1 = fooBuilder.WithProp1(ONE).Build();
     var foo2 = fooBuilder.WithProp1(TWO).Build();
     Assert.AreNotEqual(hashCodeBuilder.HashCode(foo1), hashCodeBuilder.HashCode(foo2));
 }
 public void HashCode_DifferentObjectsSamePropertiesOnlyOnePropertyChecked_SameHashCode()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().With(m => m.Prop1).Compile();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     var foo1 = fooBuilder.Build();
     var foo2 = fooBuilder.Build();
     Assert.AreEqual(hashCodeBuilder.HashCode(foo1), hashCodeBuilder.HashCode(foo2));
 }
 public void HashCode_DifferentObjectsDifferentProperties_DifferentHashCode()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithDummyProp2();
     var foo1 = fooBuilder.WithProp1(ONE).Build();
     var foo2 = fooBuilder.WithProp1(TWO).Build();
     Assert.AreNotEqual(hashCodeBuilder.HashCode(foo1), hashCodeBuilder.HashCode(foo2));
 }
 public void HashCode_DifferentObjectsSamePropertiesWithNullObject_SameHashCode()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithDummyProp2();
     var foo1 = fooBuilder.Build();
     var foo2 = fooBuilder.Build();
     Assert.AreEqual(hashCodeBuilder.HashCode(foo1), hashCodeBuilder.HashCode(foo2));
 }
Example #15
0
        public override int GetHashCode()
        {
            var hashCode = new HashCodeBuilder();

            hashCode.Add(Name, StringComparer.InvariantCultureIgnoreCase);
            hashCode.Add(Value);
            return(hashCode.ToHashCode());
        }
Example #16
0
 /// <inheritdoc/>
 public override int GetHashCode()
 {
     return(HashCodeBuilder.For <SnpModel>()
            .Add(Id)
            .Add(Location)
            .Add(Position)
            .Add(Genotype));
 }
 protected override HashCodeBuilder CalculateHashCode()
 {
     return(HashCodeBuilder
            .CreateNew()
            .Add(EmployeeId.GetHashCodeBuilder())
            .Add(Name.GetHashCodeBuilder())
            .Add(Address.GetHashCodeBuilder()));
 }
Example #18
0
 /// <summary>Generates a unique hash code for the given SpindaSpots.</summary>
 /// <returns>Unique hash code</returns>
 public override int GetHashCode()
 {
     return(HashCodeBuilder.Create().AddValue <SpindaCoords>(this.LeftEar)
            .AddValue <SpindaCoords>(this.RightEar)
            .AddValue <SpindaCoords>(this.LeftFace)
            .AddValue <SpindaCoords>(this.RightFace)
            .ToHashCode());
 }
 /// <inheritdoc />
 public override int GetHashCode()
 {
     return(HashCodeBuilder.BuildHashCode(
                67,
                this.GetType(),
                this.PositionChanges
                ));
 }
Example #20
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);
        }
Example #21
0
 public override int GetHashCode()
 {
     return(HashCodeBuilder.Combine(
                Name?.ToLower(CultureInfo.InvariantCulture),
                Family?.ToLower(CultureInfo.InvariantCulture),
                Size?.ToLower(CultureInfo.InvariantCulture),
                Tier?.ToString().ToLower(CultureInfo.InvariantCulture),
                Capacity));
 }
 protected override HashCodeBuilder CalculateHashCode()
 {
     return(HashCodeBuilder.CreateNew()
            .Add(CareOf.GetHashCodeBuilder())
            .WithCaseInsensitiveString(Line1)
            .WithCaseInsensitiveString(City)
            .WithCaseInsensitiveString(Country)
            .Build());
 }
        public override int GetHashCode()
        {
            HashCodeBuilder hashBuilder = new HashCodeBuilder();

            hashBuilder.Append(dataSourceIdentifier)
            .Append(controlId)
            .Append(rangeComparer.GetHashCode(rangeDataList));
            return(hashBuilder.HashCode);
        }
Example #24
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);
        }
Example #25
0
 public override int GetHashCode()
 {
     return(HashCodeBuilder.Combine(
                Name?.ToLower(CultureInfo.InvariantCulture),
                Publisher?.ToLower(CultureInfo.InvariantCulture),
                Product?.ToLower(CultureInfo.InvariantCulture),
                PromotionCode?.ToLower(CultureInfo.InvariantCulture),
                Version?.ToLower(CultureInfo.InvariantCulture)));
 }
 /// <inheritdoc />
 public override int GetHashCode()
 {
     return(HashCodeBuilder.BuildHashCode(
                71,
                this.GetType(),
                this.CurrentGlyphAnchorPoint,
                this.PreviousGlyphAnchorPoint
                ));
 }
Example #27
0
 public void testReflectionHierarchyHashCode()
 {
     Assert.AreEqual(17 * 37 * 37, HashCodeBuilder.ReflectionHashCode(new TestSubObject(0, 0, 0)));
     Assert.AreEqual(17 * 37 * 37 * 37, HashCodeBuilder.ReflectionHashCode(new TestSubObject(0, 0, 0), true));
     Assert.AreEqual((17 * 37 + 7890) * 37 + 123456,
                     HashCodeBuilder.ReflectionHashCode(new TestSubObject(123456, 7890, 0)));
     Assert.AreEqual(((17 * 37 + 7890) * 37 + 0) * 37 + 123456,
                     HashCodeBuilder.ReflectionHashCode(new TestSubObject(123456, 7890, 0), true));
 }
Example #28
0
        public override int GetHashCode()
        {
            var hash = new HashCodeBuilder().
                       append(Cargo).
                       append(CompletionTime).
                       append(Activity).
                       toHashCode();

            return(hash);
        }
 /// <inheritdoc />
 public override int GetHashCode()
 {
     return(HashCodeBuilder.BuildHashCode(
                257,
                typeof(SubstitutionAction),
                this.ReplacedGlyphCount,
                this.ReplacementGlyphIds,
                this.SkippedGlyphCount
                ));
 }
 /// <inheritdoc />
 public override int GetHashCode()
 {
     return(HashCodeBuilder.BuildHashCode(
                271,
                this.GetType(),
                this.HeadShift,
                this.LookupFlags,
                this.Action != null ? this.Action.GetHashCode() : 0
                ));
 }
Example #31
0
 protected override HashCodeBuilder CalculateHashCode()
 {
     return(HashCodeBuilder.CreateNew()
            .WithCaseInsensitiveString(FirstName)
            .WithCaseInsensitiveString(MiddleName)
            .WithCaseInsensitiveString(LastName)
            .WithCaseInsensitiveString(Suffix)
            .WithCaseInsensitiveString(Title)
            .Build());
 }
Example #32
0
        public override int GetHashCode()
        {
            var hashBuilder = new HashCodeBuilder();

            hashBuilder.Append(DatetimeRangeIdx)
            .Append(FieldIndex)
            .Append(Max)
            .Append(Min);
            return(hashBuilder.HashCode);
        }
Example #33
0
        public override int GetHashCode()
        {
            var hashCode = new HashCodeBuilder();

            hashCode.Add(Keys);
            hashCode.Add(Labels);
            hashCode.Add(AsOf);
            hashCode.Add(Fields);
            return(hashCode.ToHashCode());
        }
        public override int GetHashCode()
        {
            var hashCode = new HashCodeBuilder();

            hashCode.Add(Keys);
            hashCode.Add(Labels);
            hashCode.Add(AsOf);
            hashCode.Add(Fields);
            hashCode.Add(BatchLink, StringComparer.Ordinal);
            return(hashCode.ToHashCode());
        }
 public void HashCode_UncompiledBuilder_Exception()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().WithAllPublic();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     var foo1 = fooBuilder.Build();
     hashCodeBuilder.HashCode(foo1);
 }
 public void HashCode_NullParameter_Exception()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().WithAllPublic().Compile();
     Assert.AreEqual(0, hashCodeBuilder.HashCode(null));
 }
 public void HashCode_WrongType_Exception()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().WithAllPublic().Compile();
     var fooBuilder = FooBuilder.AFoo().WithFullDummyData();
     var foo1 = fooBuilder.Build();
     hashCodeBuilder.HashCode(String.Empty);
 }
 public void HashCode_SameObjects_SameHashCode()
 {
     var hashCodeBuilder = new HashCodeBuilder<Foo>().WithAllPublic().Compile();
     var foo = FooBuilder.AFoo().WithFullDummyData().Build();
     Assert.AreEqual(hashCodeBuilder.HashCode(foo), hashCodeBuilder.HashCode(foo));
 }