- Timestamp:
- 10/18/13 21:33:56 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GPDL/HeuristicLab.Grammars/3.3/Symbol.cs
r10063 r10067 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 23 26 namespace HeuristicLab.Grammars { 24 public class Symbol : ISymbol , IEquatable<ISymbol>{27 public class Symbol : ISymbol { 25 28 public string Name { get; private set; } 26 public I Attribute Attribute{ get; private set; }27 public Symbol(string name, I Attribute attribute= null) {29 public IEnumerable<IAttribute> Attributes { get; private set; } 30 public Symbol(string name, IEnumerable<IAttribute> attributes = null) { 28 31 this.Name = name; 29 this.Attribute = attribute; 32 if (attributes != null) this.Attributes = attributes; 33 else this.Attributes = Enumerable.Empty<IAttribute>(); 30 34 } 31 35 32 public bool Equals(ISymbol other) { 33 return Name == other.Name; 36 public string GetAttributeString() { 37 if (!Attributes.Any()) return string.Empty; 38 return Attributes.Skip(1).Aggregate(Attributes.First().ToString(), (str, a) => str + ", " + a.ToString()); 34 39 } 35 40 … … 37 42 if (obj == null) return false; 38 43 if (obj == this) return true; 39 var other = obj as ISymbol;44 var other = obj as Symbol; 40 45 if (other == null) return false; 41 return Equals(other);46 return this.Name == other.Name; // compare names only 42 47 } 43 48 … … 45 50 return Name.GetHashCode(); 46 51 } 52 53 public override string ToString() { 54 return Name + "<" + GetAttributeString() + ">"; 55 } 47 56 } 48 57 }
Note: See TracChangeset
for help on using the changeset viewer.