Skip to content

Commit

Permalink
Remove interface for object path making stuff just too complicated fo… (
Browse files Browse the repository at this point in the history
#1905)

* Remove interface for object path making stuff just too complicated for nothing

* Fixing tests

* Fixes #1904 parent
  • Loading branch information
msevestre authored Feb 17, 2023
1 parent 75881f2 commit 958e688
Show file tree
Hide file tree
Showing 69 changed files with 342 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public interface IApplicationMoleculeBuilder : IUsingFormula
/// <para></para>
/// Must be defined relative to the root container of the application
/// </summary>
IObjectPath RelativeContainerPath { get; set; }
ObjectPath RelativeContainerPath { get; set; }
}

public class ApplicationMoleculeBuilder : Entity, IApplicationMoleculeBuilder
{
public IObjectPath RelativeContainerPath { get; set; }
public ObjectPath RelativeContainerPath { get; set; }
public IFormula Formula { get; set; }
public IDimension Dimension { get; set; }

Expand All @@ -33,7 +33,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone
var srcAppMoleculeBuilder = source as IApplicationMoleculeBuilder;
if (srcAppMoleculeBuilder == null) return;

RelativeContainerPath = srcAppMoleculeBuilder.RelativeContainerPath.Clone<IObjectPath>();
RelativeContainerPath = srcAppMoleculeBuilder.RelativeContainerPath.Clone<ObjectPath>();
Formula = cloneManager.Clone(srcAppMoleculeBuilder.Formula);
Dimension = srcAppMoleculeBuilder.Dimension;
}
Expand Down
6 changes: 3 additions & 3 deletions src/OSPSuite.Core/Domain/Builder/EventAssignmentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IAssignment : IUsingFormula
/// <summary>
/// Path to IUsingFormulaEntity object, whose formula will be changed
/// </summary>
IObjectPath ObjectPath { get; set; }
ObjectPath ObjectPath { get; set; }

/// <summary>
/// Defines whether the formula itself or the VALUE of the formula
Expand All @@ -28,7 +28,7 @@ public interface IEventAssignmentBuilder : IAssignment

public class EventAssignmentBuilder : Entity, IEventAssignmentBuilder
{
public IObjectPath ObjectPath { get; set; }
public ObjectPath ObjectPath { get; set; }

/// <summary>
/// New formula to be set when event fires
Expand All @@ -48,7 +48,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone
UseAsValue = srcEventAssignmentBuilder.UseAsValue;
Dimension = srcEventAssignmentBuilder.Dimension;

ObjectPath = srcEventAssignmentBuilder.ObjectPath.Clone<IObjectPath>();
ObjectPath = srcEventAssignmentBuilder.ObjectPath.Clone<ObjectPath>();
}
}
}
4 changes: 2 additions & 2 deletions src/OSPSuite.Core/Domain/Builder/IWithPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface IWithPath
{
IObjectPath Path { get; set; }
IObjectPath ContainerPath { get; set; }
ObjectPath Path { get; set; }
ObjectPath ContainerPath { get; set; }
}
}
14 changes: 7 additions & 7 deletions src/OSPSuite.Core/Domain/Builder/PathAndValueEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OSPSuite.Core.Domain.Builder
{
public abstract class PathAndValueEntity : Entity, IUsingFormula, IWithDisplayUnit, IWithPath, IWithNullableValue
{
private IObjectPath _containerPath;
private ObjectPath _containerPath;
protected IFormula _formula;
private Unit _displayUnit;
private IDimension _dimension;
Expand All @@ -22,12 +22,12 @@ protected PathAndValueEntity()
ValueOrigin = new ValueOrigin();
}

private void entityFullPathToComponents(IObjectPath fullPath)
private void entityFullPathToComponents(ObjectPath fullPath)
{
if (fullPath.Any())
{
Name = fullPath.Last();
ContainerPath = fullPath.Clone<IObjectPath>();
ContainerPath = fullPath.Clone<ObjectPath>();
if (ContainerPath.Count > 0)
ContainerPath.RemoveAt(ContainerPath.Count - 1);
}
Expand All @@ -38,7 +38,7 @@ private void entityFullPathToComponents(IObjectPath fullPath)
}
}

public IObjectPath ContainerPath
public ObjectPath ContainerPath
{
get => _containerPath;
set => SetProperty(ref _containerPath, value);
Expand All @@ -63,9 +63,9 @@ public Unit DisplayUnit
}


public IObjectPath Path
public ObjectPath Path
{
get => ContainerPath.Clone<IObjectPath>().AndAdd(Name);
get => ContainerPath.Clone<ObjectPath>().AndAdd(Name);
set => entityFullPathToComponents(value);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone
if (sourcePathAndValueEntity == null) return;

Value = sourcePathAndValueEntity.Value;
ContainerPath = sourcePathAndValueEntity.ContainerPath.Clone<IObjectPath>();
ContainerPath = sourcePathAndValueEntity.ContainerPath.Clone<ObjectPath>();
DisplayUnit = sourcePathAndValueEntity.DisplayUnit;
Dimension = sourcePathAndValueEntity.Dimension;
Formula = cloneManager.Clone(sourcePathAndValueEntity.Formula);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace OSPSuite.Core.Domain.Builder
{
public abstract class PathAndValueEntityBuildingBlock<T> : BuildingBlock, IBuildingBlock<T> where T: class, IWithPath, IObjectBase
{
protected ICache<IObjectPath, T> _allValues = new Cache<IObjectPath, T>(x => x.Path, x => null);
protected ICache<ObjectPath, T> _allValues = new Cache<ObjectPath, T>(x => x.Path, x => null);

public T this[IObjectPath objectPath]
public T this[ObjectPath objectPath]
{
get => _allValues[objectPath];
set => _allValues[objectPath] = value;
Expand All @@ -29,7 +29,7 @@ public void Remove(T startValue)
}


public void Remove(IObjectPath objectPath)
public void Remove(ObjectPath objectPath)
{
Remove(this[objectPath]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/OSPSuite.Core/Domain/Builder/StartValueBuildingBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IStartValuesBuildingBlock<T> : IBuildingBlock<T> where T : clas
/// </summary>
/// <param name="objectPath"></param>
/// <returns></returns>
T this[IObjectPath objectPath] { get; set; }
T this[ObjectPath objectPath] { get; set; }

/// <summary>
/// Id of the spatial structure used to create the parameter start values.
Expand All @@ -34,7 +34,7 @@ public interface IStartValuesBuildingBlock<T> : IBuildingBlock<T> where T : clas
/// <summary>
/// Removes the start value with path <paramref name="objectPath" /> if available. Does nothing otherwise
/// </summary>
void Remove(IObjectPath objectPath);
void Remove(ObjectPath objectPath);
}

public abstract class StartValueBuildingBlock<T> : PathAndValueEntityBuildingBlock<T>, IStartValuesBuildingBlock<T> where T : class, IStartValue
Expand All @@ -55,7 +55,7 @@ private bool refersTo(IBuildingBlock buildingBlock, string idToCheck)

protected StartValueBuildingBlock()
{
_allValues = new Cache<IObjectPath, T>(x => x.Path, x => null);
_allValues = new Cache<ObjectPath, T>(x => x.Path, x => null);
}

public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager cloneManager)
Expand Down
30 changes: 19 additions & 11 deletions src/OSPSuite.Core/Domain/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public interface IContainer : IEntity, IEnumerable<IEntity>
/// </summary>
IReadOnlyList<IEntity> Children { get; }

/// <summary>
/// Returns the path to the parent container.
/// It should only be set if the container has no parent in the hierarchy. Otherwise, it will be null
/// </summary>
ObjectPath ParentPath { get; set; }

/// <summary>
/// Add the given child to the container
Expand Down Expand Up @@ -92,15 +97,14 @@ public interface IContainer : IEntity, IEnumerable<IEntity>

public class Container : Entity, IContainer
{
private readonly List<IEntity> _children;
private ContainerMode _mode;
private readonly List<IEntity> _children = new List<IEntity>();

private ContainerMode _mode = ContainerMode.Logical;

private ContainerType _containerType;

public Container()
{
_children = new List<IEntity>();
Mode = ContainerMode.Logical;
}
//Path to parent container is null by default. In this case, it will be evaluated from container structure
private ObjectPath _parentPath;

public virtual IReadOnlyList<IEntity> Children => _children;

Expand Down Expand Up @@ -137,6 +141,12 @@ public ContainerMode Mode
set => SetProperty(ref _mode, value);
}

public ObjectPath ParentPath
{
get => _parentPath;
set => SetProperty(ref _parentPath, value);
}

public ContainerType ContainerType
{
get => _containerType;
Expand Down Expand Up @@ -190,10 +200,7 @@ public override void AcceptVisitor(IVisitor visitor)
/// <summary>
/// Returns all children of type <typeparamref name="T" />
/// </summary>
public virtual IEnumerable<T> GetChildren<T>() where T : class, IEntity
{
return GetChildren<T>(x => true);
}
public virtual IEnumerable<T> GetChildren<T>() where T : class, IEntity => GetChildren<T>(x => true);

public virtual IEnumerable<T> GetChildren<T>(Func<T, bool> predicate) where T : class, IEntity
{
Expand Down Expand Up @@ -250,6 +257,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone

Mode = container.Mode;
ContainerType = container.ContainerType;
ParentPath = container.ParentPath?.Clone<ObjectPath>();
}

public IEnumerator<IEntity> GetEnumerator()
Expand Down
4 changes: 2 additions & 2 deletions src/OSPSuite.Core/Domain/EventAssignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class EventAssignment : Entity, IEventAssignment
/// <summary>
/// Path to IUsingFormulaEntity object, whose formula will be changed
/// </summary>
public IObjectPath ObjectPath { get; set; }
public ObjectPath ObjectPath { get; set; }

/// <summary>
/// Defines whether the formula itself or the VALUE of the formula
Expand All @@ -54,7 +54,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone
var sourceEventAssignment = source as IEventAssignment;
if (sourceEventAssignment == null) return;
UseAsValue = sourceEventAssignment.UseAsValue;
ObjectPath = sourceEventAssignment.ObjectPath.Clone<IObjectPath>();
ObjectPath = sourceEventAssignment.ObjectPath.Clone<ObjectPath>();
Dimension = sourceEventAssignment.Dimension;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OSPSuite.Core/Domain/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public MissingMoleculeAmountException(string containerName, string moleculeName)

public class UnableToResolvePathException : OSPSuiteException
{
public UnableToResolvePathException(IObjectPath objectPath, IEntity currentEntity)
public UnableToResolvePathException(ObjectPath objectPath, IEntity currentEntity)
: base($"Unable to resolve path '{objectPath}' for entity '{currentEntity.Name}' with path '{currentEntity.EntityPath()}'")

{
Expand Down
14 changes: 7 additions & 7 deletions src/OSPSuite.Core/Domain/FormulaUsablePath.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using System.Collections.Generic;
using System.Linq;
using OSPSuite.Core.Domain.UnitSystem;
using OSPSuite.Utility.Extensions;

namespace OSPSuite.Core.Domain
{
public interface IFormulaUsablePath : IWithDimension, IObjectPath
{
string Alias { get; set; }
}

public class FormulaUsablePath : ObjectPath, IFormulaUsablePath
public class FormulaUsablePath : ObjectPath, IWithDimension
{
public string Alias { get; set; }
public IDimension Dimension { get; set; }
public virtual IDimension Dimension { get; set; }

public FormulaUsablePath()
{
}

public FormulaUsablePath(FormulaUsablePath from) : base(from._pathEntries)
{
}

public FormulaUsablePath(params string[] pathEntries) : base(pathEntries)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/OSPSuite.Core/Domain/FormulaUsablePathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace OSPSuite.Core.Domain
{
public static class FormulaUsablePathExtensions
{
public static TObjectPath WithAlias<TObjectPath>(this TObjectPath objectPath,string alias) where TObjectPath:IFormulaUsablePath
public static TObjectPath WithAlias<TObjectPath>(this TObjectPath objectPath, string alias) where TObjectPath : FormulaUsablePath
{
objectPath.Alias = alias;
return objectPath;
Expand Down
16 changes: 8 additions & 8 deletions src/OSPSuite.Core/Domain/Formulas/Formula.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface IFormula : IObjectBase, IWithDimension
/// Object path to IFormulaUsable-entities used in current formula
/// <para></para>
/// </summary>
IReadOnlyList<IFormulaUsablePath> ObjectPaths { get; }
IReadOnlyList<FormulaUsablePath> ObjectPaths { get; }

/// <summary>
/// Concrete IFormulaUsable-entities used by current formula
Expand Down Expand Up @@ -61,13 +61,13 @@ public interface IFormula : IObjectBase, IWithDimension
/// Adds a new path reference to the Formulas.
/// </summary>
/// <param name="newPath"> The new reference. </param>
void AddObjectPath(IFormulaUsablePath newPath);
void AddObjectPath(FormulaUsablePath newPath);

/// <summary>
/// Removes the specified path reference from formula.
/// </summary>
/// <param name="pathToRemove"> The reference to remove. </param>
void RemoveObjectPath(IFormulaUsablePath pathToRemove);
void RemoveObjectPath(FormulaUsablePath pathToRemove);

/// <summary>
/// Removes all object paths defined in the formula
Expand All @@ -78,7 +78,7 @@ public interface IFormula : IObjectBase, IWithDimension
public abstract class Formula : ObjectBase, IFormula
{
private readonly List<IObjectReference> _objectReferences = new List<IObjectReference>();
private List<IFormulaUsablePath> _objectPaths = new List<IFormulaUsablePath>();
private List<FormulaUsablePath> _objectPaths = new List<FormulaUsablePath>();
public virtual IDimension Dimension { get; set; } = Constants.Dimension.NO_DIMENSION;

public virtual IReadOnlyList<IObjectReference> ObjectReferences => _objectReferences;
Expand Down Expand Up @@ -113,7 +113,7 @@ private void onReferencePropertyChanged(object sender, PropertyChangedEventArgs
}
}

public virtual IReadOnlyList<IFormulaUsablePath> ObjectPaths
public virtual IReadOnlyList<FormulaUsablePath> ObjectPaths
{
get => _objectPaths;
set
Expand All @@ -137,7 +137,7 @@ private void checkAliases(IEnumerable<string> aliases)
/// Adds a new reference to the Formulas.
/// </summary>
/// <param name="newPath"> The new reference. </param>
public virtual void AddObjectPath(IFormulaUsablePath newPath)
public virtual void AddObjectPath(FormulaUsablePath newPath)
{
_objectPaths.Add(newPath);
}
Expand All @@ -146,7 +146,7 @@ public virtual void AddObjectPath(IFormulaUsablePath newPath)
/// Removes the specified reference from formula.
/// </summary>
/// <param name="pathToRemove"> The reference to remove. </param>
public virtual void RemoveObjectPath(IFormulaUsablePath pathToRemove)
public virtual void RemoveObjectPath(FormulaUsablePath pathToRemove)
{
_objectPaths.Remove(pathToRemove);
}
Expand All @@ -164,7 +164,7 @@ public override void UpdatePropertiesFrom(IUpdatable source, ICloneManager clone
var srcFormula = source as Formula;
if (srcFormula == null) return;

srcFormula.ObjectPaths.Each(path => _objectPaths.Add(path.Clone<IFormulaUsablePath>()));
srcFormula.ObjectPaths.Each(path => _objectPaths.Add(path.Clone<FormulaUsablePath>()));
Dimension = srcFormula.Dimension;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OSPSuite.Core/Domain/Formulas/FormulaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static bool IsCachable(this IFormula formula)
/// Returns the used object path with the given <paramref name="alias" /> in the <paramref name="formula" /> or null if
/// the <paramref name="alias" /> is not used.
/// </summary>
public static IFormulaUsablePath FormulaUsablePathBy(this IFormula formula, string alias)
public static FormulaUsablePath FormulaUsablePathBy(this IFormula formula, string alias)
{
return formula.ObjectPaths.FirstOrDefault(x => string.Equals(x.Alias, alias));
}
Expand Down
2 changes: 1 addition & 1 deletion src/OSPSuite.Core/Domain/Formulas/FormulaFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private ExplicitFormula createReferenceStartValueFormula(string formulaString, s
.WithFormulaString(formulaString);
}

private IFormulaUsablePath createVolumeReferencePath(params string[] pathToVolumeParameter)
private FormulaUsablePath createVolumeReferencePath(params string[] pathToVolumeParameter)
{
return _objectPathFactory.CreateFormulaUsablePathFrom(pathToVolumeParameter)
.WithAlias(Constants.VOLUME_ALIAS)
Expand Down
Loading

0 comments on commit 958e688

Please sign in to comment.