Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/Constraints/ConstraintOperation.cs @ 3613

Last change on this file since 3613 was 3603, checked in by mkommend, 14 years ago

corrected == operator of ConstraintOperation (ticket #996)

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24namespace HeuristicLab.Core {
25  [StorableClass]
26  public class ConstraintOperation {
27    public static readonly ConstraintOperation Equal = new ConstraintOperation(0, "Equal");
28    public static readonly ConstraintOperation NotEqual = new ConstraintOperation(1, "Not equal");
29    public static readonly ConstraintOperation Lesser = new ConstraintOperation(2, "Lesser");
30    public static readonly ConstraintOperation LesserOrEqual = new ConstraintOperation(3, "Lesser or equal");
31    public static readonly ConstraintOperation Greater = new ConstraintOperation(4, "Greater");
32    public static readonly ConstraintOperation GreaterOrEqual = new ConstraintOperation(5, "Greater or equal");
33    public static readonly ConstraintOperation IsTypeCompatible = new ConstraintOperation(6, "Is type compatible to");
34    public static readonly ConstraintOperation IsTypeNotCompatible = new ConstraintOperation(7, "Is type not compatible to");
35
36    [Storable]
37    private int value;
38    [Storable]
39    private string name;
40
41    [StorableConstructor]
42    protected ConstraintOperation(bool deserializing) {
43    }
44    protected ConstraintOperation(int value, string name) {
45      this.value = value;
46      this.name = name;
47    }
48
49    public override string ToString() {
50      return name;
51    }
52
53    public override bool Equals(object obj) {
54      if (obj is ConstraintOperation)
55        return this == (ConstraintOperation)obj;
56
57      return false;
58    }
59    public override int GetHashCode() {
60      return value;
61    }
62    public static bool operator ==(ConstraintOperation co1, ConstraintOperation co2) {
63      if(object.ReferenceEquals(co1,co2))
64        return true;
65     
66      if((object)co1 == null || (object) co2 == null)
67        return false;
68
69      return co1.value == co2.value;
70    }
71    public static bool operator !=(ConstraintOperation co1, ConstraintOperation co2) {
72      return !(co1 == co2);
73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.