/* Copyright (c) Microsoft Corporation All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. */ using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Reflection; using System.Diagnostics; namespace Microsoft.Research.DryadLinq { /// /// The DryadLINQ type to represent a line of text. /// [Serializable] public struct LineRecord : IComparable, IComparable, IEnumerable, IEnumerable, IEquatable { private string _line; /// /// Initializes a new instance of LineRecord from a string. /// /// The input string. public LineRecord(string line) { _line = line; } /// /// Gets the string value of a LineRecord. /// public string Line { get { return _line; } internal set { _line = value; } } /// /// Determines whether the specified object is equal to the current LineRecord. /// /// The object to compare with. /// true iff the specified object is equal to the current object. public override bool Equals(Object obj) { if (!(obj is LineRecord)) return false; return this.Line.Equals(((LineRecord)obj).Line); } /// /// Determines whether a specified LineRecord is equal to the current LineRecord. /// /// A LineRecord to compare with. /// true iff the argument is equal to the current LineRecord. public bool Equals(LineRecord val) { return this.Line.Equals(val.Line); } /// /// Determines whether two specified LineRecords are equal. /// /// The left LineRecord. /// The right LineRecord. /// true iff two LineRecords are equal. public static bool operator ==(LineRecord a, LineRecord b) { return a.Equals(b); } /// /// Determines whether two specified LineRecords are not equal. /// /// The left LineRecord. /// The right LineRecord. /// true iff two LineRecords are not equal. public static bool operator !=(LineRecord a, LineRecord b) { return !a.Equals(b); } /// /// Returns true iff a LineRecord is less than another LineRecord. /// /// The left LineRecrod. /// The right LineRecord. /// true iff left is less than right. public static bool operator <(LineRecord a, LineRecord b) { return a.CompareTo(b) < 0; } /// /// Returns true iff a LineRecord is greater than another LineRecord. /// /// The left LineRecrod. /// The right LineRecord. /// true iff left is greater than right. public static bool operator >(LineRecord a, LineRecord b) { return a.CompareTo(b) > 0; } /// /// Returns the hash code of the current LineRecord. /// /// A 32-bit signed integer. public override int GetHashCode() { return this.Line.GetHashCode(); } /// /// Compares the current LineRecord with an object. /// /// The value to compare. /// An integer that indicates the order. public int CompareTo(Object val) { if (val == null) return 1; if (!(val is LineRecord)) { throw new ArgumentException(SR.CompareArgIncorrect, "val"); } return StringComparer.Ordinal.Compare(this.Line, ((LineRecord)val).Line); } /// /// Compares the current LineRecord with another LineRecord. /// /// The LineRecord to compare with. /// An integer that indicates the order. public int CompareTo(LineRecord val) { return StringComparer.Ordinal.Compare(this.Line, val.Line); } IEnumerator IEnumerable.GetEnumerator() { return this.Line.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return this.Line.GetEnumerator(); } /// /// Returns a string that represents the current LineRecord. /// /// A string that represents the current LineRecord. public override String ToString() { return this.Line; } } }