Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11249


Ignore:
Timestamp:
07/31/14 10:03:24 (10 years ago)
Author:
mkommend
Message:

#2223: Minor code changes in DirectedGraph (renaming of methods, code simplification).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs

    r11248 r11249  
    7171    private void AfterDeserialization() {
    7272      foreach (var vertex in vertices) {
    73         vertex.ArcAdded += OnVertexArcAdded;
    74         vertex.ArcRemoved += OnVertexArcRemoved;
     73        vertex.ArcAdded += Vertex_ArcAdded;
     74        vertex.ArcRemoved += Vertex_ArcRemoved;
    7575      }
    7676
     
    9191      vertices.Add(vertex);
    9292      // register event handlers
    93       vertex.ArcAdded += OnVertexArcAdded;
    94       vertex.ArcRemoved += OnVertexArcRemoved;
    95       OnVertedAdded(this, EventArgs.Empty);
     93      vertex.ArcAdded += Vertex_ArcAdded;
     94      vertex.ArcRemoved += Vertex_ArcRemoved;
     95      OnVertedAdded(this, new EventArgs<IVertex>(vertex));
    9696    }
    9797
     
    103103        RemoveArc(arc);
    104104      // deregister event handlers
    105       vertex.ArcAdded -= OnVertexArcAdded;
    106       vertex.ArcRemoved -= OnVertexArcRemoved;
    107       OnVertexRemoved(this, EventArgs.Empty); // do not pass the removed vertex in the event as we don't need it anymore
     105      vertex.ArcAdded -= Vertex_ArcAdded;
     106      vertex.ArcRemoved -= Vertex_ArcRemoved;
     107      OnVertexRemoved(this, new EventArgs<IVertex>(vertex));
    108108    }
    109109
     
    120120      target.AddArc(arc);
    121121      arcs.Add(arc);
    122       OnArcAdded(this, EventArgs.Empty);
    123122    }
    124123
     
    129128      source.RemoveArc(arc);
    130129      target.RemoveArc(arc);
    131       OnArcRemoved(this, EventArgs.Empty);
    132130    }
    133131
    134     protected virtual void OnVertexArcAdded(object sender, EventArgs<IArc> args) {
     132    protected virtual void Vertex_ArcAdded(object sender, EventArgs<IArc> args) {
     133      // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections
     134      // because the arc is added in both directions by both the source and the target, this event will get fired twice here
    135135      var arc = args.Value;
    136       // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections
    137       // because the arc is added in both directions by both the source and the target, this event will get fired twice
    138       // here, we only want to add the arc once, so if its already contained, we return without complaining
    139       if (arcs.Contains(arc)) return;
    140       arcs.Add(arc);
     136      if (arcs.Add(arc)) OnArcAdded(this, new EventArgs<IArc>(arc));
    141137    }
    142138
    143     protected virtual void OnVertexArcRemoved(object sender, EventArgs<IArc> args) {
     139    protected virtual void Vertex_ArcRemoved(object sender, EventArgs<IArc> args) {
    144140      var arc = args.Value;
    145       if (!arcs.Contains(arc)) return; // the same rationale as above
    146       arcs.Remove(arc);
     141      if (arcs.Remove(arc)) OnArcRemoved(this, new EventArgs<IArc>(arc));
    147142    }
    148143
    149144    // events
    150145    public event EventHandler VertexAdded;
    151     protected virtual void OnVertedAdded(object sender, EventArgs args) {
     146    protected virtual void OnVertedAdded(object sender, EventArgs<IVertex> args) {
    152147      var added = VertexAdded;
    153148      if (added != null)
     
    156151
    157152    public event EventHandler VertexRemoved;
    158     protected virtual void OnVertexRemoved(object sender, EventArgs args) {
     153    protected virtual void OnVertexRemoved(object sender, EventArgs<IVertex> args) {
    159154      var removed = VertexRemoved;
    160155      if (removed != null)
     
    163158
    164159    public event EventHandler ArcAdded;
    165     protected virtual void OnArcAdded(object sender, EventArgs args) {
     160    protected virtual void OnArcAdded(object sender, EventArgs<IArc> args) {
    166161      var added = ArcAdded;
    167162      if (added != null)
     
    170165
    171166    public event EventHandler ArcRemoved;
    172     protected virtual void OnArcRemoved(object sender, EventArgs args) {
     167    protected virtual void OnArcRemoved(object sender, EventArgs<IArc> args) {
    173168      var removed = ArcRemoved;
    174169      if (removed != null)
Note: See TracChangeset for help on using the changeset viewer.