Subversion Repository Public Repository

WOX2

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Text;

/// <header>
/// <wox>
///     <version>1.0</version>
///     <author>Carlos R. Jaimez Gonzalez</author>
///     <author>Simon M. Lucas</author>
///     <site>http://woxserializer.sourceforge.net/</site>
/// </wox>
/// <wox>
///     <version>1.5</version>
///     <author>Steven M Lewis</author>
/// </wox>
/// <wox>
///     <version>2.0</version>
///     <author>George A Smith</author>
///     <svn>http://woxserializer.sourceforge.net/</svn>
///     <note>XML form for vs 2 is more compact and therefor incompatible with vs 1</note>
/// </wox>
/// </header>

namespace wox.serial.tests.objects
{
    public class Perscription : IEquatable<Perscription>
    {
        private static int gCurrentId = 1000;

        public Perscription()
        {
            PerscriptionId = "" + gCurrentId++;
        }

        /// <summary>
        /// Build a perscription from a String
        /// </summary>
        /// <param name="s"></param>
        public Perscription( String s )
        {
            String[] items = s.Split( ',' );
            int index = 1; // 0
            PerscriptionId = "" + gCurrentId++; // items[index++];
            ProviderId = items[index++];
            PatientId = items[index++];
            Drug = items[index++];
            Dose = items[index++];
            EndDate = DateTime.Parse( items[index] );
        }

        public String ProviderId { get; set; }
        public String PerscriptionId { get; set; }
        public String Drug { get; set; }
        public String Dose { get; set; }
        public DateTime EndDate { get; set; }
        public String PatientId { get; set; }

        public String Id
        {
            get { return PerscriptionId + "_" + ProviderId; }
        }

        #region IEquatable<Perscription> Members

        public bool Equals( Perscription other )
        {
            if ( ReferenceEquals( null, other ) )
            {
                return false;
            }
            if ( ReferenceEquals( this, other ) )
            {
                return true;
            }
            long t1 = other.EndDate.Ticks / 10000000;
            long t2 = EndDate.Ticks / 10000000;
            if ( t1 != t2 )
            {
                return false;
            }
            if ( !Equals( other.Drug, Drug ) )
            {
                return false;
            }
            if ( !Equals( other.Dose, Dose ) )
            {
                return false;
            }
            if ( !Equals( other.PatientId, PatientId ) )
            {
                return false;
            }
            if ( !Equals( other.ProviderId, ProviderId ) )
            {
                return false;
            }
            if ( !Equals( other.PerscriptionId, PerscriptionId ) )
            {
                return false;
            }
            return true;
        }

        #endregion

        public static bool operator ==( Perscription left, Perscription right )
        {
            return Equals( left, right );
        }

        public static bool operator !=( Perscription left, Perscription right )
        {
            return !Equals( left, right );
        }


        public override bool Equals( object obj )
        {
            if ( ReferenceEquals( null, obj ) )
            {
                return false;
            }
            if ( ReferenceEquals( this, obj ) )
            {
                return true;
            }
            if ( obj.GetType() != typeof (Perscription) )
            {
                return false;
            }
            return Equals( (Perscription) obj );
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = EndDate.GetHashCode();
                result = (result * 397) ^ (Drug != null ? Drug.GetHashCode() : 0);
                result = (result * 397) ^ (Dose != null ? Dose.GetHashCode() : 0);
                result = (result * 397) ^ (PerscriptionId != null ? PerscriptionId.GetHashCode() : 0);
                result = (result * 397) ^ (ProviderId != null ? ProviderId.GetHashCode() : 0);
                result = (result * 397) ^ (PatientId != null ? PatientId.GetHashCode() : 0);
                return result;
            }
        }

        public override string ToString()
        {
            var sb = new StringBuilder();
            sb.Append( PerscriptionId );
            sb.Append( "," );
            sb.Append( ProviderId );
            sb.Append( "," );
            sb.Append( PatientId );
            sb.Append( "," );
            sb.Append( Drug );
            sb.Append( "," );
            sb.Append( Dose );
            sb.Append( "," );
            sb.Append( EndDate );

            return sb.ToString();
        }
    }
}

Commits for WOX2/trunk/CSharp/tests/wox/serial/tests/objects/Perscription.cs

Diff revisions: vs.
Revision Author Commited Message
14 Diff Diff GeorgeS picture GeorgeS Fri 19 Feb, 2010 19:15:03 +0000
3 GeorgeS picture GeorgeS Thu 04 Feb, 2010 23:53:47 +0000