Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/14 15:02:27 (10 years ago)
Author:
mkommend
Message:

#2223: Copied directed graph implented in bottom up tree distance branch into the trunk.

Location:
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph
Files:
1 added
1 copied

Legend:

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

    r11239 r11241  
    2424using System.Linq;
    2525using HeuristicLab.Common;
    26 using HeuristicLab.Core;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827
    29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     28namespace HeuristicLab.Core {
    3029  [StorableClass]
    3130  public class Vertex : Item, IVertex {
    3231    [Storable]
    33     protected string label;
     32    private string label;
    3433    public string Label {
    3534      get { return label; }
     
    4241
    4342    [Storable]
    44     protected double weight;
     43    private double weight;
    4544    public double Weight {
    4645      get { return weight; }
     
    5352
    5453    [Storable]
    55     protected object content;
    56     public object Content {
    57       get { return content; }
     54    private IDeepCloneable data;
     55    public IDeepCloneable Data {
     56      get { return data; }
    5857      set {
    59         if (content == value) return;
    60         content = value;
     58        if (data == value) return;
     59        data = value;
    6160        OnChanged(this, EventArgs.Empty);
    6261      }
    6362    }
    6463
    65     private List<IArc> inArcs;
     64    private readonly List<IArc> inArcs = new List<IArc>();
    6665    public IEnumerable<IArc> InArcs {
    67       get { return inArcs ?? Enumerable.Empty<IArc>(); }
     66      get { return inArcs; }
    6867    }
    6968
    70     private List<IArc> outArcs;
     69    private readonly List<IArc> outArcs = new List<IArc>();
    7170    public IEnumerable<IArc> OutArcs {
    72       get { return outArcs ?? Enumerable.Empty<IArc>(); }
     71      get { return outArcs; }
    7372    }
    7473
     
    8382    private void AfterDeserialization() { }
    8483
    85     public Vertex(object content) {
    86       this.content = content;
     84    public Vertex(IDeepCloneable data) {
     85      this.data = data;
    8786    }
    8887
    8988    protected Vertex(Vertex original, Cloner cloner)
    9089      : base(original, cloner) {
    91       content = original.content;
     90      data = cloner.Clone(original.Data);
    9291      label = original.Label;
    9392      weight = original.Weight;
     
    106105
    107106      if (this == arc.Source) {
    108         if (outArcs == null)
    109           outArcs = new List<IArc>();
    110         else if (outArcs.Contains(arc))
    111           throw new InvalidOperationException("Arc already added.");
     107        if (outArcs.Contains(arc)) throw new InvalidOperationException("Arc already added.");
    112108        outArcs.Add(arc);
    113       } else if (this == arc.Target) {
    114         if (inArcs == null)
    115           inArcs = new List<IArc>();
    116         else if (inArcs.Contains(arc))
    117           throw new InvalidOperationException("Arc already added.");
     109      }
     110      if (this == arc.Target) {
     111        if (inArcs.Contains(arc)) throw new InvalidOperationException("Arc already added.");
    118112        inArcs.Add(arc);
    119113      }
     
    125119        throw new InvalidOperationException("The current vertex must be either the arc source or the arc target.");
    126120
    127       if (this == arc.Source && outArcs != null) {
    128         if (!outArcs.Remove(arc))
    129           throw new InvalidOperationException("Arc is not present in this vertex' outgoing arcs.");
    130       } else if (this == arc.Target && inArcs != null) {
    131         if (!inArcs.Remove(arc))
    132           throw new InvalidOperationException("Arc is not present in this vertex' incoming arcs.");
     121      if (this == arc.Source) {
     122        if (!outArcs.Remove(arc)) throw new InvalidOperationException("Arc is not present in this vertex' outgoing arcs.");
     123      }
     124      if (this == arc.Target) {
     125        if (!inArcs.Remove(arc)) throw new InvalidOperationException("Arc is not present in this vertex' incoming arcs.");
    133126      }
    134127      OnArcRemoved(this, new EventArgs<IArc>(arc));
     
    162155  [StorableClass]
    163156  public class Vertex<T> : Vertex, IVertex<T> where T : class,IItem {
    164     public new T Content {
    165       get { return (T)base.Content; }
    166       set { base.Content = value; }
     157    public new T Data {
     158      get { return (T)base.Data; }
     159      set { base.Data = value; }
    167160    }
    168161
Note: See TracChangeset for help on using the changeset viewer.