Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Pair.cs « Utils « Common « Data « System « System.Data.Entity « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4e671634668ca2a8972b142bb3492f96cfee8607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//---------------------------------------------------------------------
// <copyright file="Pair.cs" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Linq;


namespace System.Data.Common.Utils
{
    internal class Pair<TFirst, TSecond> : InternalBase
    {
        #region Fields
        private readonly TFirst first;
        private readonly TSecond second;

        #endregion

        #region Constructor
        internal Pair(TFirst first, TSecond second)
        {
            this.first = first;
            this.second = second;
        }
        #endregion

        #region Properties
        internal TFirst First
        {
            get
            {
                return first;
            }
        }

        internal TSecond Second
        {
            get
            {
                return second;
            }
        }
        #endregion 

        #region Methods
        public override int GetHashCode()
        {
            return (first.GetHashCode()<<5) ^ second.GetHashCode();
        }

        public bool Equals(Pair<TFirst, TSecond> other)
        {
            return first.Equals(other.first) && second.Equals(other.second);
        }

        public override bool Equals(object other)
        {
            Pair<TFirst, TSecond> otherPair = other as Pair<TFirst, TSecond>;

            return (otherPair != null && Equals(otherPair));
        }
        #endregion

        #region InternalBase
        internal override void ToCompactString(StringBuilder builder)
        {
            builder.Append("<");
            builder.Append(first.ToString());
            builder.Append(", "+second.ToString());
            builder.Append(">");
        }
        #endregion


        internal class PairComparer : IEqualityComparer<Pair<TFirst, TSecond>>
        {
            private PairComparer() { }

            internal static readonly PairComparer Instance = new PairComparer();
            private static readonly EqualityComparer<TFirst> firstComparer = EqualityComparer<TFirst>.Default;
            private static readonly EqualityComparer<TSecond> secondComparer = EqualityComparer<TSecond>.Default;

            public bool Equals(Pair<TFirst, TSecond> x, Pair<TFirst, TSecond> y)
            {
                return firstComparer.Equals(x.First, y.First) && secondComparer.Equals(x.Second, y.Second);
            }

            public int GetHashCode(Pair<TFirst, TSecond> source)
            {
                return source.GetHashCode();
            }
        }
    }

    

}