From ebb163db0ca7d4e51bf7eda5660ca79eeee1df0a Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Thu, 21 Oct 2021 13:04:02 +0200 Subject: [PATCH] Changed all string.Join by the new Extension Method Join() --- .../Models/HybridStrategyResponse.cs | 7 +++--- VectoCommon/VectoCommon/Models/IResponse.cs | 2 +- VectoCommon/VectoCommon/Models/WHRType.cs | 3 ++- VectoCommon/VectoCommon/Utils/Validation.cs | 12 +++++----- .../FileIO/XML/Common/AbstractXMLType.cs | 2 +- .../XMLDeclarationEngineDataProvider.cs | 15 +++++-------- .../ComponentData/ActuationsMapReader.cs | 3 +-- .../Reader/ComponentData/AlternatorReader.cs | 2 +- .../BatteryInternalResistanceReader.cs | 13 ++++++----- .../ComponentData/BatteryMaxCurrentReader.cs | 8 +++++-- .../Reader/ComponentData/BatterySOCReader.cs | 7 ++++-- .../ComponentData/CompressorMapReader.cs | 9 ++++---- .../ComponentData/DrivingCycleDataReader.cs | 8 +++---- .../ComponentData/ElectricConsumerReader.cs | 8 +++---- .../ComponentData/ElectricMotorMapReader.cs | 2 +- .../EnvironmentalContidionsMapReader.cs | 6 ++--- .../ComponentData/FullLoadCurveReader.cs | 2 +- .../ComponentData/PTOIdleLossMapReader.cs | 2 +- .../ComponentData/RetarderLossMapReader.cs | 4 ++-- .../ComponentData/SSMTechnologiesReader.cs | 7 +++--- .../Connector/Ports/Impl/BatteryResponse.cs | 2 +- .../Models/Connector/Ports/Impl/Response.cs | 2 +- .../Models/Declaration/WeightingGroups.cs | 2 +- .../Simulation/Impl/PCCSegmentPreprocessor.cs | 2 +- .../Simulation/Impl/SimulatorFactory.cs | 2 +- .../Data/AccelerationCurve.cs | 2 +- .../Impl/ATShiftStrategy.cs | 2 +- .../SimulationComponent/Impl/BatterySystem.cs | 2 +- .../ModalDataPostprocessingCorrection.cs | 6 ++--- .../OutputData/SummaryDataContainer.cs | 22 +++++++++---------- .../XML/Engineering/XMLEngineeringWriter.cs | 7 +++--- .../VectoCore/Utils/DataIntegrityHelper.cs | 4 ++-- VectoCore/VectoCore/Utils/DebugData.cs | 3 ++- VectoCore/VectoCore/Utils/DelaunayMap.cs | 6 ++--- VectoCore/VectoCore/Utils/VectoCSVFile.cs | 4 ++-- VectoCore/VectoCore/Utils/XMLHelper.cs | 2 +- VectoCore/VectoCore/Utils/XMLValidator.cs | 2 +- VectoCore/VectoCore/Utils/XPathHelper.cs | 10 ++++----- .../Algorithms/MeanShiftClusteringTest.cs | 9 ++++---- .../Integration/TorqueLimitsTest.cs | 2 +- .../Models/Declaration/DeclarationDataTest.cs | 8 +++---- .../DeclarationSegmentHeavyBusesTest.cs | 4 ++-- .../Models/Declaration/ShiftPolygonTest.cs | 2 +- .../SimulationComponent/BatterySystemTest.cs | 6 ++--- .../SimulationComponentData/ValidationTest.cs | 9 ++++---- .../VectoCoreTest/Utils/ResultFileHelper.cs | 19 ++++++++-------- .../VectoCoreTest/Utils/VectoMathTest.cs | 2 +- VectoCore/VectoCoreTest/XML/XMLReportTest.cs | 5 +++-- 48 files changed, 136 insertions(+), 134 deletions(-) diff --git a/VectoCommon/VectoCommon/Models/HybridStrategyResponse.cs b/VectoCommon/VectoCommon/Models/HybridStrategyResponse.cs index 980076d4b3..1cd19c094f 100644 --- a/VectoCommon/VectoCommon/Models/HybridStrategyResponse.cs +++ b/VectoCommon/VectoCommon/Models/HybridStrategyResponse.cs @@ -82,9 +82,8 @@ namespace TUGraz.VectoCommon.Models { return ToString().Equals(other.ToString(), StringComparison.InvariantCultureIgnoreCase); } - public override string ToString() - { - var setting = string.Join(", ", Setting.MechanicalAssistPower.Select(x => $"{x.Key}, {x.Value}")); + public override string ToString() { + var setting = Setting.MechanicalAssistPower.Select(x => $"{x.Key}, {x.Value}").Join(); return $"{U}: {setting} {Score} G{Gear}"; } } @@ -155,7 +154,7 @@ namespace TUGraz.VectoCommon.Models { } } - return string.Join("/", retVal); + return retVal.Join("/"); } public static bool InvalidEngineSpeed(this HybridConfigurationIgnoreReason x) diff --git a/VectoCommon/VectoCommon/Models/IResponse.cs b/VectoCommon/VectoCommon/Models/IResponse.cs index ad0e0d1d5d..d3e3e6e18b 100644 --- a/VectoCommon/VectoCommon/Models/IResponse.cs +++ b/VectoCommon/VectoCommon/Models/IResponse.cs @@ -44,7 +44,7 @@ namespace TUGraz.VectoCommon.Models public override string ToString() { var t = GetType(); - return $"{t.Name}{{{string.Join(", ", t.GetProperties().Select(p => $"{p.Name}: {p.GetValue(this)}"))}}}"; + return $"{t.Name}{{{t.GetProperties().Select(p => $"{p.Name}: {p.GetValue(this)}").Join()}}}"; } } diff --git a/VectoCommon/VectoCommon/Models/WHRType.cs b/VectoCommon/VectoCommon/Models/WHRType.cs index 9b4f8158cb..b6f260f8c6 100644 --- a/VectoCommon/VectoCommon/Models/WHRType.cs +++ b/VectoCommon/VectoCommon/Models/WHRType.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using TUGraz.VectoCommon.Utils; namespace TUGraz.VectoCommon.Models { @@ -27,7 +28,7 @@ namespace TUGraz.VectoCommon.Models { options.Add("electrical output"); } - return options.Count == 0 ? "none" : string.Join(", ", options); + return options.Count == 0 ? "none" : options.Join(); } public static bool IsElectrical(this WHRType whrType) diff --git a/VectoCommon/VectoCommon/Utils/Validation.cs b/VectoCommon/VectoCommon/Utils/Validation.cs index ebfe5f6b5d..459464c82f 100644 --- a/VectoCommon/VectoCommon/Utils/Validation.cs +++ b/VectoCommon/VectoCommon/Utils/Validation.cs @@ -206,8 +206,7 @@ namespace TUGraz.VectoCommon.Utils if (kvResults.Any()) { return new ValidationResult( string.Format("{1}[{0}] in {1} invalid: {2}", valueType.GetProperty("Key").GetValue(element), - validationContext.DisplayName, - string.Join("\n", kvResults))); + validationContext.DisplayName, kvResults.Join("\n"))); } } } @@ -215,8 +214,7 @@ namespace TUGraz.VectoCommon.Utils var results = element.Validate(mode, jobType, emPos, gbxType, isEmsCycle); if (results.Any()) { return new ValidationResult( - string.Format("{1}[{0}] in {1} invalid: {2}", i, validationContext.DisplayName, - string.Join("\n", results))); + $"{validationContext.DisplayName}[{i}] in {validationContext.DisplayName} invalid: {results.Join("\n")}"); } } i++; @@ -226,12 +224,12 @@ namespace TUGraz.VectoCommon.Utils if (!results.Any()) { return ValidationResult.Success; } - var messages = results.Select(r => String.Join(", ", r.MemberNames.Distinct())); + var messages = results.Select(r => r.MemberNames.Distinct().Join()); if (validationContext.MemberName == "Container" || validationContext.MemberName == "RunData") { - return new ValidationResult(string.Join("\n", results), messages); + return new ValidationResult(results.Join("\n"), messages); } return new ValidationResult( - $"{{{validationContext.DisplayName}}} invalid: {string.Join("\n", results)}", messages); + $"{{{validationContext.DisplayName}}} invalid: {results.Join("\n")}", messages); } return ValidationResult.Success; diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs index 9d38cd1952..a4c38f960e 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs @@ -83,7 +83,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Common { var node = GetNode(nodePath, required: fallbackValue == null); if (node == null && fallbackValue == null) { - throw new VectoException("Node {0} not found in input data", string.Join("/", nodePath)); + throw new VectoException("Node {0} not found in input data", nodePath.Join("/")); } return node?.InnerText.ToDouble() ?? fallbackValue.Value; diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationEngineDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationEngineDataProvider.cs index 933c79281c..2fd94d18f4 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationEngineDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationEngineDataProvider.cs @@ -110,7 +110,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider public virtual FuelType FuelType { get { - var value = GetString(XMLNames.Engine_FuelType).Replace(" ",""); + var value = GetString(XMLNames.Engine_FuelType).Replace(" ", ""); if ("LPG".Equals(value, StringComparison.InvariantCultureIgnoreCase)) { return FuelType.LPGPI; } @@ -164,7 +164,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider public XMLDeclarationEngineDataProviderV20( IXMLDeclarationVehicleData vehicle, XmlNode componentNode, string sourceFile) : base( - vehicle, componentNode, sourceFile) { } + vehicle, componentNode, sourceFile) + { } protected override XNamespace SchemaNamespace => NAMESPACE_URI; } @@ -336,13 +337,9 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider var missing = GetNodes( new[] { XMLNames.Engine_FuelConsumptionMap, XMLNames.Engine_FuelConsumptionMap_Entry }, whrFuelNode) .Cast<XmlNode>().Where(x => x.Attributes?[fcMapAttr] == null); - throw new VectoException( - "WHRData has to be provided for every entry in the FC-Map! {0}", - string.Join( - "; ", - missing.Select( - x => $"n: {x.Attributes?[XMLNames.Engine_FuelConsumptionMap_EngineSpeed_Attr]?.Value}, " + - $"T: {x.Attributes?[XMLNames.Engine_FuelConsumptionMap_Torque_Attr]?.Value}"))); + throw new VectoException("WHRData has to be provided for every entry in the FC-Map! {0}", + missing.Select(x => $"n: {x.Attributes?[XMLNames.Engine_FuelConsumptionMap_EngineSpeed_Attr]?.Value}, " + + $"T: {x.Attributes?[XMLNames.Engine_FuelConsumptionMap_Torque_Attr]?.Value}").Join("; ")); } if (correctionFactorNodes[0].ParentNode.ParentNode != whrFuelNode) { diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/ActuationsMapReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/ActuationsMapReader.cs index d4ada09049..150243d53d 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/ActuationsMapReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/ActuationsMapReader.cs @@ -31,8 +31,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData { if (!HeaderIsValid(data.Columns)) { throw new VectoException("Invalid header for pneumatic actuations. expected: {0}, got: {1}", - string.Join(", ", Header), - string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); + Header.Join(), data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); } var retVal = new Dictionary<MissionType, IActuations>(); diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/AlternatorReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/AlternatorReader.cs index 7919b1bd19..e9108102ed 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/AlternatorReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/AlternatorReader.cs @@ -76,7 +76,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData if (g.Any(x => x.Count() < 2)) { throw new ArgumentException( "Insufficient rows in csv to build a usable map for alternator {0}", - string.Join(", ", g.Where(x => x.Count() < 2).Select(x => x.Key))); + g.Where(x => x.Count() < 2).Select(x => x.Key).Join()); } return new CombinedAlternator(map, source); } diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryInternalResistanceReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryInternalResistanceReader.cs index 51f3494958..6c765c12bc 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryInternalResistanceReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryInternalResistanceReader.cs @@ -27,12 +27,13 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData if (data.Columns.Count == 2) { if (!data.Columns.Contains(Fields.StateOfCharge) || !data.Columns.Contains(Fields.InternalResistance)) { - data.Columns[0].ColumnName = Fields.StateOfCharge; - data.Columns[1].ColumnName = Fields.InternalResistance; LoggingObject.Logger<InternalResistanceMap>().Warn( "Internal Resistance Map Header is invalid. Expected: '{0}, {1}', Got: '{2}'. Falling back to column index.", - Fields.StateOfCharge, Fields.InternalResistance, - string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); + Fields.StateOfCharge, + Fields.InternalResistance, + data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); + data.Columns[0].ColumnName = Fields.StateOfCharge; + data.Columns[1].ColumnName = Fields.InternalResistance; } return new InternalResistanceMap(data.Rows.Cast<DataRow>().Select(row => { @@ -78,8 +79,8 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData } LoggingObject.Logger<InternalResistanceMap>().Warn( "Internal Resistance Map Header is invalid. Expected: '{0}', Got: '{1}'. Falling back to column index.", - string.Join(", ", col1.Select(x => x.Item2)), - string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); + col1.Select(x => x.Item2).Join(), + data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); } diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryMaxCurrentReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryMaxCurrentReader.cs index 5747491d5a..612baa2464 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryMaxCurrentReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/BatteryMaxCurrentReader.cs @@ -22,11 +22,15 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData } if (!data.Columns.Contains(Fields.StateOfCharge) || !data.Columns.Contains(Fields.MaxDischargeCurrent) || !data.Columns.Contains(Fields.MaxChargeCurrent)) { + LoggingObject.Logger<InternalResistanceMap>().Warn( + "Max Current Map Header is invalid. Expected: '{0}, {1}, {2}', Got: '{3}'. Falling back to column index.", + Fields.StateOfCharge, + Fields.MaxChargeCurrent, + Fields.MaxDischargeCurrent, + data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); data.Columns[0].ColumnName = Fields.StateOfCharge; data.Columns[1].ColumnName = Fields.MaxChargeCurrent; data.Columns[2].ColumnName = Fields.MaxDischargeCurrent; - LoggingObject.Logger<InternalResistanceMap>().Warn("Max Current Map Header is invalid. Expected: '{0}, {1}, {2}', Got: '{3}'. Falling back to column index.", - Fields.StateOfCharge, Fields.MaxChargeCurrent, Fields.MaxDischargeCurrent, string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); } return new MaxCurrentMap(data.Rows.Cast<DataRow>().Select(row => new MaxCurrentMap.MaxCurrentEntry() { SoC = row.ParseDouble(Fields.StateOfCharge) / 100, diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/BatterySOCReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/BatterySOCReader.cs index 3c6f5bd015..ac3b230f9e 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/BatterySOCReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/BatterySOCReader.cs @@ -30,8 +30,11 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData { { data.Columns[0].ColumnName = Fields.StateOfCharge; data.Columns[1].ColumnName = Fields.BatteryVoltage; - LoggingObject.Logger<SOCMap>().Warn("SoC-Map Header is invalid. Expected: '{0}, {1}', Got: '{2}'. Falling back to column index.", - Fields.StateOfCharge, Fields.BatteryVoltage, string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); + LoggingObject.Logger<SOCMap>().Warn( + "SoC-Map Header is invalid. Expected: '{0}, {1}', Got: '{2}'. Falling back to column index.", + Fields.StateOfCharge, + Fields.BatteryVoltage, + data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); } return new SOCMap(data.Rows.Cast<DataRow>().Select(row => new SOCMap.SOCMapEntry { diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/CompressorMapReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/CompressorMapReader.cs index 93e7c02fdd..98ff4d9dcc 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/CompressorMapReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/CompressorMapReader.cs @@ -12,7 +12,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData { public class CompressorMapReader { - public static readonly string[] Header = new[] { Fields.RPM, Fields.FlowRate, Fields.PowerOn, Fields.PowerOff }; + public static readonly string[] Header = { Fields.RPM, Fields.FlowRate, Fields.PowerOn, Fields.PowerOff }; public static ICompressorMap ReadFile(string filename, double dragCurveFactorClutch, string technology) { @@ -27,10 +27,9 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData public static IList<CompressorMapValues> Create(DataTable data, double dragCurveFactorClutch) { if (!HeaderIsValid(data.Columns)) { - throw new VectoException( - "Invalid column header. expected: {0}, got: {1}", - string.Join(", ", data.Columns.Cast<DataColumn>().Select(x => x.ColumnName)), - string.Join(", ", Header)); + throw new VectoException("Invalid column header. Expected: {0}, Got: {1}", + Header.Join(), + data.Columns.Cast<DataColumn>().Select(x => x.ColumnName).Join()); } if (data.Rows.Count < 3) { diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/DrivingCycleDataReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/DrivingCycleDataReader.cs index 0e902e94c8..fad460b71b 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/DrivingCycleDataReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/DrivingCycleDataReader.cs @@ -388,7 +388,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData var diff = headerStr.GroupBy(c => c).Where(g => g.Count() > 2).SelectMany(g => g).ToList(); if (diff.Any()) { if (throwExceptions) { - throw new VectoException("Column(s) defined more than once: " + string.Join(", ", diff.OrderBy(x => x))); + throw new VectoException($"Column(s) defined more than once: {diff.OrderBy(x => x).Join()}"); } return false; @@ -401,7 +401,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData diff = headerStr.Except(allowedCols.Select(x => x.ToLowerInvariant())).ToList(); if (diff.Any()) { if (throwExceptions) { - throw new VectoException("Column(s) not allowed: " + string.Join(", ", diff)); + throw new VectoException($"Column(s) not allowed: {diff.Join()}"); } return false; @@ -410,7 +410,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData diff = requiredCols.Select(x => x.ToLowerInvariant()).Except(headerStr).ToList(); if (diff.Any()) { if (throwExceptions) { - throw new VectoException("Column(s) required: " + string.Join(", ", diff)); + throw new VectoException($"Column(s) required: {diff.Join()}"); } return false; @@ -427,7 +427,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData if (colCount != 0 && colCount != cols.Length) { if (throwExceptions) { - throw new VectoException("Either all columns have to be defined or none of them: {0}", string.Join(", ", cols)); + throw new VectoException("Either all columns have to be defined or none of them: {0}", cols.Join()); } return false; diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricConsumerReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricConsumerReader.cs index 5e8bb8f525..adf8c13612 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricConsumerReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricConsumerReader.cs @@ -28,14 +28,14 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData public static ElectricalConsumerList Create(TableData data) { if (!HeaderValid(data.Columns)) { - throw new VectoException("Invalid header. Expected: {0}, got: {1}", - string.Join(", ", Header), - string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); + throw new VectoException("Invalid header. Expected: {0}, Got: {1}", + Header.Join(), + data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); } var retVal = new List<ElectricalConsumer>(); foreach (DataRow row in data.Rows) { - var consumer = new ElectricalConsumer() { + var consumer = new ElectricalConsumer { Category = row.Field<string>(Fields.Category), ConsumerName = row.Field<string>(Fields.Consumer), BaseVehicle = row.ParseBoolean(Fields.BaseVehicle), diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricMotorMapReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricMotorMapReader.cs index 87ce14fded..7b819b5d8a 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricMotorMapReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/ElectricMotorMapReader.cs @@ -24,7 +24,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData { if (!headerValid) { LoggingObject.Logger<FuelConsumptionMap>().Warn( - "Efficiency Map: Header Line is not valid. Expected: '{0}, {1}, {2}', Got: {3}. Falling back to default names.", + "Efficiency Map: Header Line is not valid. Expected: '{0}, {1}, {2}', Got: {3}. Falling back to column index.", Fields.MotorSpeed, Fields.Torque, Fields.PowerElectrical, diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/EnvironmentalContidionsMapReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/EnvironmentalContidionsMapReader.cs index f7dd3ee092..ee81cf6cdd 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/EnvironmentalContidionsMapReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/EnvironmentalContidionsMapReader.cs @@ -39,9 +39,9 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData if (!HeaderIsValid(data.Columns)) { throw new VectoException( - "Invalid Header for environmental conditions. Got: {0}, expected: {1}", - string.Join(", ", data.Columns.Cast<DataColumn>().Select(x => x.ColumnName)), - string.Join(", ", Header)); + "Invalid Header for environmental conditions. Expected: {0}, Got: {1}", + Header.Join(), + data.Columns.Cast<DataColumn>().Select(x => x.ColumnName).Join()); } foreach (DataRow row in data.Rows) { diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/FullLoadCurveReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/FullLoadCurveReader.cs index f7f914d3ef..f816b8fdbb 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/FullLoadCurveReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/FullLoadCurveReader.cs @@ -90,7 +90,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData .Select(g => g.Key).ToList(); if (duplicates.Count > 0) { throw new VectoException( - "Error reading full-load curve: multiple entries for engine speeds {0}", string.Join(", ", duplicates)); + "Error reading full-load curve: multiple entries for engine speeds {0}", duplicates.Join()); } return new EngineFullLoadCurve(entriesFld, tmp); } diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/PTOIdleLossMapReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/PTOIdleLossMapReader.cs index 86c7d840e7..e6f051bc78 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/PTOIdleLossMapReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/PTOIdleLossMapReader.cs @@ -69,7 +69,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData if (!(data.Columns.Contains(Fields.EngineSpeed) && data.Columns.Contains(Fields.PTOTorque))) { LoggingObject.Logger<RetarderLossMap>().Warn( - "PTO Idle LossMap: Header Line is not valid. Expected: '{0}, {1}', Got: '{2}'. Falling back to default names.", + "PTO Idle LossMap: Header Line is not valid. Expected: '{0}, {1}', Got: '{2}'. Falling back to column index.", Fields.EngineSpeed, Fields.PTOTorque, data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/RetarderLossMapReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/RetarderLossMapReader.cs index be825fece9..b4f60d0068 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/RetarderLossMapReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/RetarderLossMapReader.cs @@ -70,10 +70,10 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData if (!data.Columns.Contains(Fields.RetarderSpeed) || !data.Columns.Contains(Fields.TorqueLoss)) { LoggingObject.Logger<RetarderLossMap>().Warn( - "RetarderLossMap: Header Line is not valid. Expected: '{0}, {1}', Got: '{2}'. Falling back to default names.", + "RetarderLossMap: Header Line is not valid. Expected: '{0}, {1}', Got: '{2}'. Falling back to column index.", Fields.RetarderSpeed, Fields.TorqueLoss, - string.Join(", ", data.Columns.Cast<DataColumn>().Select(c => c.ColumnName))); + data.Columns.Cast<DataColumn>().Select(c => c.ColumnName).Join()); data.Columns[0].ColumnName = Fields.RetarderSpeed; data.Columns[1].ColumnName = Fields.TorqueLoss; } diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/SSMTechnologiesReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/SSMTechnologiesReader.cs index 6e9cc83ea5..ace65ad980 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/SSMTechnologiesReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/SSMTechnologiesReader.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.BusAuxiliaries.DownstreamModules.Impl.HVAC; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Utils; @@ -34,9 +35,9 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData public static List<SSMTechnology> Create(DataTable data, string fileName) { if (!HeaderIsValid(data.Columns)) { - throw new VectoException("invalid header for techlist file. expected: {0} got: {1}", - string.Join(", ", headerCols), string.Join(", ", data.Columns) - ); + throw new VectoException("invalid header for techlist file. Expected: {0}, Got: {1}", + headerCols.Join(), + data.Columns.Cast<DataColumn>().Join()); } var retVal = new List<SSMTechnology>(); diff --git a/VectoCore/VectoCore/Models/Connector/Ports/Impl/BatteryResponse.cs b/VectoCore/VectoCore/Models/Connector/Ports/Impl/BatteryResponse.cs index 9c9675d60b..a64d9ad980 100644 --- a/VectoCore/VectoCore/Models/Connector/Ports/Impl/BatteryResponse.cs +++ b/VectoCore/VectoCore/Models/Connector/Ports/Impl/BatteryResponse.cs @@ -89,7 +89,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl public override string ToString() { var t = GetType(); - return $"{t.Name}{{{string.Join(", ", t.GetProperties().Select(p => $"{p.Name}: {p.GetValue(this)}"))}}}"; + return $"{t.Name}{{{t.GetProperties().Select(p => $"{p.Name}: {p.GetValue(this)}").Join()}}}"; } } diff --git a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs index ab6c8ffcfd..1953ba8a19 100644 --- a/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs +++ b/VectoCore/VectoCore/Models/Connector/Ports/Impl/Response.cs @@ -110,7 +110,7 @@ namespace TUGraz.VectoCore.Models.Connector.Ports.Impl public override string ToString() { var t = GetType(); - return $"{t.Name}{{{string.Join(", ", t.GetProperties().Select(p => $"{p.Name}: {p.GetValue(this)}"))}}}"; + return $"{t.Name}{{{t.GetProperties().Select(p => $"{p.Name}: {p.GetValue(this)}").Join()}}}"; } } diff --git a/VectoCore/VectoCore/Models/Declaration/WeightingGroups.cs b/VectoCore/VectoCore/Models/Declaration/WeightingGroups.cs index c09199e027..ba02d6eb54 100644 --- a/VectoCore/VectoCore/Models/Declaration/WeightingGroups.cs +++ b/VectoCore/VectoCore/Models/Declaration/WeightingGroups.cs @@ -99,7 +99,7 @@ namespace TUGraz.VectoCore.Models.Declaration case WeightingGroup.Group9LH: case WeightingGroup.Group10RD: case WeightingGroup.Group10LH: - return string.Join("-", Regex.Split(group.ToString().Replace(Prefix, ""), @"(\d+|\w+)").Where(x => !string.IsNullOrWhiteSpace(x))); + return Regex.Split(group.ToString().Replace(Prefix, ""), @"(\d+|\w+)").Where(x => !string.IsNullOrWhiteSpace(x)).Join("-"); default: return Constants.NOT_AVAILABLE; } diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/PCCSegmentPreprocessor.cs b/VectoCore/VectoCore/Models/Simulation/Impl/PCCSegmentPreprocessor.cs index 0362e869ec..fa963140e5 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/PCCSegmentPreprocessor.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/PCCSegmentPreprocessor.cs @@ -34,7 +34,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl var preProcessor = new PCCEcoRollEngineStopPreprocessor(Container, slopes, PCCDriverData.MinSpeed, maxSpeed); preProcessor.RunPreprocessing(); - DebugWriteLine("Slopes:\n" + string.Join("\n", slopes.Select(p => $"{p.Key.AsKmph:F}\t{p.Value.ToInclinationPercent():P}"))); + DebugWriteLine($"Slopes:\n{slopes.Select(p => $"{p.Key.AsKmph:F}\t{p.Value.ToInclinationPercent():P}").Join("\n")}"); var runData = Container.RunData; diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index a92f711d82..6b902d12c2 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -288,7 +288,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl var validationErrors = run.Validate(_mode, jobType, emPosition, gearboxtype, isEms); if (validationErrors.Any()) { throw new VectoException("Validation of Run-Data Failed: " + - string.Join("\n", validationErrors.Select(r => r.ErrorMessage + string.Join("; ", r.MemberNames)))); + $"{validationErrors.Select(r => r.ErrorMessage + r.MemberNames.Join("; ")).Join("\n")}"); } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/AccelerationCurve.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/AccelerationCurve.cs index 784b775cc3..6807e36b06 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Data/AccelerationCurve.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/AccelerationCurve.cs @@ -49,7 +49,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data if (smallValues.Count >= 2) { Log.Error( "Found small velocity entries in Driver-Acceleration/Deceleration file. Values dismissed:" + - string.Join(", ", smallValues.Skip(1).Select(e => e.Key.AsKmph.ToString("F1")))); + smallValues.Skip(1).Select(e => e.Key.AsKmph.ToString("F1")).Join()); foreach (var kv in smallValues.Skip(1)) { _entries.Remove(kv); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs index 87a05b118f..34bb373eaf 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ATShiftStrategy.cs @@ -83,7 +83,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl EngineInertia = dataBus.RunData.EngineData?.Inertia ?? 0.SI<KilogramSquareMeter>(); if (Gears.Any(x => !x.TorqueConverterLocked.HasValue)) { - throw new VectoException("Gear list must have TC info for all gears! {0}", string.Join(", ", Gears)); + throw new VectoException("Gear list must have TC info for all gears! {0}", Gears.Join()); } MaxStartGear = Gears.Any() ? Gears.First() : new GearshiftPosition(0); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs index 8ea633a720..638a043f1a 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BatterySystem.cs @@ -283,7 +283,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } if (limitBB.Count > 0) { - Log.Debug($"BB ${string.Join(", ", limitBB.Keys)} are at max - recalculating power distribution"); + Log.Debug($"BB ${limitBB.Keys.Join()} are at max - recalculating power distribution"); } } while (!(distributedPower + (limitBB.Sum(x => x.Value) ?? 0.SI<Watt>())) .IsEqual(powerDemand, 1e-3.SI<Watt>())); diff --git a/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs b/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs index 5f0645b84e..c43e7a352c 100644 --- a/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs +++ b/VectoCore/VectoCore/OutputData/ModalDataPostprocessingCorrection.cs @@ -181,8 +181,8 @@ namespace TUGraz.VectoCore.OutputData // case C3a if (runData.ElectricMachinesData.Count != 1) { throw new VectoException("exactly 1 electric machine is required. got {0} ({1})", - runData.ElectricMachinesData.Count, - string.Join(",", runData.ElectricMachinesData.Select(x => x.Item1.ToString()))); + runData.ElectricMachinesData.Count, + runData.ElectricMachinesData.Select(x => x.Item1.ToString()).Join()); } var emPos = runData.ElectricMachinesData.First().Item1; @@ -269,7 +269,7 @@ namespace TUGraz.VectoCore.OutputData if (runData.ElectricMachinesData.Count != 1) { throw new VectoException("exactly 1 electric machine is required. got {0} ({1})", runData.ElectricMachinesData.Count, - string.Join(",", runData.ElectricMachinesData.Select(x => x.Item1.ToString()))); + runData.ElectricMachinesData.Select(x => x.Item1.ToString()).Join()); } var emPos = runData.ElectricMachinesData.First().Item1; diff --git a/VectoCore/VectoCore/OutputData/SummaryDataContainer.cs b/VectoCore/VectoCore/OutputData/SummaryDataContainer.cs index 6a49ebb3f4..9cb330b27c 100644 --- a/VectoCore/VectoCore/OutputData/SummaryDataContainer.cs +++ b/VectoCore/VectoCore/OutputData/SummaryDataContainer.cs @@ -310,7 +310,7 @@ namespace TUGraz.VectoCore.OutputData passengerCount = runData.VehicleData.PassengerCount; } - row[Fields.VEHICLE_FUEL_TYPE] = string.Join(", ", modData.FuelData.Select(x => x.GetLabel())); + row[Fields.VEHICLE_FUEL_TYPE] = modData.FuelData.Select(x => x.GetLabel().Join()); var totalTime = modData.Duration; row[Fields.TIME] = (ConvertedSI)totalTime; @@ -347,7 +347,7 @@ namespace TUGraz.VectoCore.OutputData fuel => modData.TimeIntegral<Kilogram>(modData.GetColumnName(fuel.FuelData, ModalResultField.FCWHTCc)) / modData.TimeIntegral<Kilogram>(modData.GetColumnName(fuel.FuelData, ModalResultField.FCMap))) .Select(dummy => (double)dummy).ToArray(); - row[Fields.ENGINE_ACTUAL_CORRECTION_FACTOR] = string.Join(" / ", fuelsWhtc); + row[Fields.ENGINE_ACTUAL_CORRECTION_FACTOR] = fuelsWhtc.Join(" / "); } row[Fields.P_WHEEL_POS] = modData.PowerWheelPositive().ConvertToKiloWatt(); @@ -840,7 +840,7 @@ namespace TUGraz.VectoCore.OutputData row[Fields.ENGINE_MANUFACTURER] = data.Manufacturer; row[Fields.ENGINE_MODEL] = data.ModelName; row[Fields.ENGINE_CERTIFICATION_NUMBER] = data.CertificationNumber; - row[Fields.ENGINE_FUEL_TYPE] = string.Join(" / ", data.Fuels.Select(x => x.FuelData.GetLabel())); + row[Fields.ENGINE_FUEL_TYPE] = data.Fuels.Select(x => x.FuelData.GetLabel()).Join(" / "); row[Fields.ENGINE_RATED_POWER] = data.RatedPowerDeclared != null && data.RatedPowerDeclared > 0 ? data.RatedPowerDeclared.ConvertToKiloWatt() : data.FullLoadCurves[0].MaxPower.ConvertToKiloWatt(); @@ -850,12 +850,12 @@ namespace TUGraz.VectoCore.OutputData : (ConvertedSI)data.FullLoadCurves[0].RatedSpeed.AsRPM.SI<Scalar>(); row[Fields.ENGINE_DISPLACEMENT] = data.Displacement.ConvertToCubicCentiMeter(); - row[Fields.ENGINE_WHTC_URBAN] = string.Join(" / ", data.Fuels.Select(x => x.WHTCUrban)); - row[Fields.ENGINE_WHTC_RURAL] = string.Join(" / ", data.Fuels.Select(x => x.WHTCRural)); - row[Fields.ENGINE_WHTC_MOTORWAY] = string.Join(" / ", data.Fuels.Select(x => x.WHTCMotorway)); - row[Fields.ENGINE_BF_COLD_HOT] = string.Join(" / ", data.Fuels.Select(x => x.ColdHotCorrectionFactor)); - row[Fields.ENGINE_CF_REG_PER] = string.Join(" / ", data.Fuels.Select(x => x.CorrectionFactorRegPer)); - row[Fields.ENGINE_ACTUAL_CORRECTION_FACTOR] = string.Join(" / ", data.Fuels.Select(x => x.FuelConsumptionCorrectionFactor)); + row[Fields.ENGINE_WHTC_URBAN] = data.Fuels.Select(x => x.WHTCUrban).Join(" / "); + row[Fields.ENGINE_WHTC_RURAL] = data.Fuels.Select(x => x.WHTCRural).Join(" / "); + row[Fields.ENGINE_WHTC_MOTORWAY] = data.Fuels.Select(x => x.WHTCMotorway).Join(" / "); + row[Fields.ENGINE_BF_COLD_HOT] = data.Fuels.Select(x => x.ColdHotCorrectionFactor).Join(" / "); + row[Fields.ENGINE_CF_REG_PER] = data.Fuels.Select(x => x.CorrectionFactorRegPer).Join(" / "); + row[Fields.ENGINE_ACTUAL_CORRECTION_FACTOR] = data.Fuels.Select(x => x.FuelConsumptionCorrectionFactor).Join(" / "); } private static void WriteAxleWheelsData(List<Axle> data, DataRow row) @@ -913,7 +913,7 @@ namespace TUGraz.VectoCore.OutputData col.SetOrdinal(Table.Columns[Fields.CARGO_VOLUME].Ordinal); } - row[colName] = aux.Technology == null ? "" : string.Join("; ", aux.Technology); + row[colName] = aux.Technology == null ? "" : aux.Technology.Join("; "); } if (busAux == null) { @@ -923,7 +923,7 @@ namespace TUGraz.VectoCore.OutputData row[string.Format(Fields.AUX_TECH_FORMAT, Constants.Auxiliaries.IDs.HeatingVentilationAirCondition)] = busAux.SSMInputs is ISSMDeclarationInputs inputs ? inputs.HVACTechnology : "engineering mode"; row[string.Format(Fields.AUX_TECH_FORMAT, Constants.Auxiliaries.IDs.ElectricSystem)] = - string.Join("/", busAux.ElectricalUserInputsConfig.AlternatorType.GetLabel()); + busAux.ElectricalUserInputsConfig.AlternatorType.GetLabel().Join("/"); row[string.Format(Fields.AUX_TECH_FORMAT, Constants.Auxiliaries.IDs.PneumaticSystem)] = runData.JobType == VectoSimulationJobType.BatteryElectricVehicle ? "-" : busAux.PneumaticUserInputsConfig.CompressorMap.Technology; } diff --git a/VectoCore/VectoCore/OutputData/XML/Engineering/XMLEngineeringWriter.cs b/VectoCore/VectoCore/OutputData/XML/Engineering/XMLEngineeringWriter.cs index 523c1d2bbd..7a264233ed 100644 --- a/VectoCore/VectoCore/OutputData/XML/Engineering/XMLEngineeringWriter.cs +++ b/VectoCore/VectoCore/OutputData/XML/Engineering/XMLEngineeringWriter.cs @@ -38,6 +38,7 @@ using Ninject; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.OutputData.XML.Engineering.Factory; using TUGraz.VectoCore.OutputData.XML.Engineering.Interfaces; using TUGraz.VectoCore.Utils; @@ -127,10 +128,8 @@ namespace TUGraz.VectoCore.OutputData.XML.Engineering private XAttribute GetSchemaLocations() { var xsns = RegisterNamespace(XMLDefinitions.XML_SCHEMA_NAMESPACE); - - return new XAttribute( - xsns + "schemaLocation", - string.Join(" ", NamespaceLocationMap.Where(x => _namespaces.ContainsKey(x.Key)).Select(x => $"{x.Key} {x.Value}"))); + return new XAttribute(xsns + "schemaLocation", + NamespaceLocationMap.Where(x => _namespaces.ContainsKey(x.Key)).Select(x => $"{x.Key} {x.Value}").Join(" ")); } public WriterConfiguration Configuration { get; set; } diff --git a/VectoCore/VectoCore/Utils/DataIntegrityHelper.cs b/VectoCore/VectoCore/Utils/DataIntegrityHelper.cs index edc9e98a1e..2c02bc0442 100644 --- a/VectoCore/VectoCore/Utils/DataIntegrityHelper.cs +++ b/VectoCore/VectoCore/Utils/DataIntegrityHelper.cs @@ -31,6 +31,7 @@ using System.Security.Cryptography; using System.Text; +using TUGraz.VectoCommon.Utils; namespace TUGraz.VectoCore.Utils { @@ -38,8 +39,7 @@ namespace TUGraz.VectoCore.Utils { public static string ComputeDigestValue(string[] lines) { - var hash = System.Convert.ToBase64String(GetHash(string.Join("\n", lines))); - + var hash = System.Convert.ToBase64String(GetHash(lines.Join("\n"))); return $"SHA256: {hash}"; } diff --git a/VectoCore/VectoCore/Utils/DebugData.cs b/VectoCore/VectoCore/Utils/DebugData.cs index e1c69f24b9..59b053efe0 100644 --- a/VectoCore/VectoCore/Utils/DebugData.cs +++ b/VectoCore/VectoCore/Utils/DebugData.cs @@ -31,6 +31,7 @@ using System.Collections.Generic; using System.Diagnostics; +using TUGraz.VectoCommon.Utils; namespace TUGraz.VectoCore.Utils { @@ -54,7 +55,7 @@ namespace TUGraz.VectoCore.Utils public override string ToString() { #if DEBUG - return string.Join("\n", Data); + return Data.Join("\n"); #else return "-"; #endif diff --git a/VectoCore/VectoCore/Utils/DelaunayMap.cs b/VectoCore/VectoCore/Utils/DelaunayMap.cs index 15555fb7e9..84afb4eb92 100644 --- a/VectoCore/VectoCore/Utils/DelaunayMap.cs +++ b/VectoCore/VectoCore/Utils/DelaunayMap.cs @@ -163,7 +163,7 @@ namespace TUGraz.VectoCore.Utils } if (duplicates.Any()) { throw new VectoException("{0}: Input Data for Delaunay map contains duplicates! \n{1}", _mapName, - string.Join("\n", duplicates.Select(pt => $"{pt.Key.X} / {pt.Key.Y}"))); + duplicates.Select(pt => $"{pt.Key.X} / {pt.Key.Y}").Join("\n")); } } @@ -220,8 +220,8 @@ namespace TUGraz.VectoCore.Utils var frame = new StackFrame(2); var method = frame.GetMethod(); System.Diagnostics.Debug.Assert(method.DeclaringType != null, "method.DeclaringType != null"); - var type = string.Join("", method.DeclaringType.Name.Split(Path.GetInvalidFileNameChars())); - var methodName = string.Join("", method.Name.Split(Path.GetInvalidFileNameChars())); + var type = method.DeclaringType.Name.Split(Path.GetInvalidFileNameChars()).Join(""); + var methodName = method.Name.Split(Path.GetInvalidFileNameChars()).Join(""); Directory.CreateDirectory("delaunay"); chart.SaveImage($"delaunay\\{type}_{methodName}_{superTriangle.GetHashCode()}_{i}.png", ChartImageFormat.Png); diff --git a/VectoCore/VectoCore/Utils/VectoCSVFile.cs b/VectoCore/VectoCore/Utils/VectoCSVFile.cs index e4974252db..3f7928e12a 100644 --- a/VectoCore/VectoCore/Utils/VectoCSVFile.cs +++ b/VectoCore/VectoCore/Utils/VectoCSVFile.cs @@ -208,7 +208,7 @@ namespace TUGraz.VectoCore.Utils } } var header = table.Columns.Cast<DataColumn>().Select(col => col.Caption ?? col.ColumnName); - entries.Add(string.Join(Delimiter, header)); + entries.Add(header.Join(Delimiter)); var columnFormatter = new Func<ConvertedSI, string>[table.Columns.Count]; for (var i = 0; i < table.Columns.Count; i++) { @@ -241,7 +241,7 @@ namespace TUGraz.VectoCore.Utils formattedList[i] = $"\"{formattedList[i]}\""; } } - entries.Add(string.Join(Delimiter, formattedList)); + entries.Add(formattedList.Join(Delimiter)); } if (addDigest) { diff --git a/VectoCore/VectoCore/Utils/XMLHelper.cs b/VectoCore/VectoCore/Utils/XMLHelper.cs index 49d6fff697..d9cdfdd8aa 100644 --- a/VectoCore/VectoCore/Utils/XMLHelper.cs +++ b/VectoCore/VectoCore/Utils/XMLHelper.cs @@ -187,7 +187,7 @@ namespace TUGraz.VectoCore.Utils public static string QueryLocalName(params string[] nodePath) { - return "./" + string.Join("/", nodePath.Where(x => x != null).Select(x => $"/*[local-name()='{x}']").ToArray()); + return "./" + nodePath.Where(x => x != null).Select(x => $"/*[local-name()='{x}']").Join("/"); } diff --git a/VectoCore/VectoCore/Utils/XMLValidator.cs b/VectoCore/VectoCore/Utils/XMLValidator.cs index e477b6710b..2fc93738b9 100644 --- a/VectoCore/VectoCore/Utils/XMLValidator.cs +++ b/VectoCore/VectoCore/Utils/XMLValidator.cs @@ -99,7 +99,7 @@ namespace TUGraz.VectoCore.Utils _validationErrorAction(args?.Severity ?? XmlSeverityType.Error, new ValidationEvent { ValidationEventArgs = args }); } - public string ValidationError => _validationErrors.Any() ? string.Join(Environment.NewLine, _validationErrors) : null; + public string ValidationError => _validationErrors.Any() ? _validationErrors.Join(Environment.NewLine) : null; public static void CallBackExceptionOnError(XmlSeverityType severity, ValidationEvent evt) { diff --git a/VectoCore/VectoCore/Utils/XPathHelper.cs b/VectoCore/VectoCore/Utils/XPathHelper.cs index 3f18f3a79d..a9177e08ce 100644 --- a/VectoCore/VectoCore/Utils/XPathHelper.cs +++ b/VectoCore/VectoCore/Utils/XPathHelper.cs @@ -32,6 +32,7 @@ using System.Linq; using System.Xml; using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; namespace TUGraz.VectoCore.Utils @@ -49,12 +50,9 @@ namespace TUGraz.VectoCore.Utils : Constants.XML.EngineeringNSPrefix; } - public string Query(params string[] xpathSections) - { - return string.Join("/", - xpathSections.Select( - x => string.IsNullOrWhiteSpace(x) || x.StartsWith("..") || x.Contains(":") || x.StartsWith("@") ? x : NSPrefix(x))) - ; + public string Query(params string[] xpathSections) { + return xpathSections.Select( + x => string.IsNullOrWhiteSpace(x) || x.StartsWith("..") || x.Contains(":") || x.StartsWith("@") ? x : NSPrefix(x)).Join("/"); } public string QueryConstraint(string elementName, string name, string value, diff --git a/VectoCore/VectoCoreTest/Algorithms/MeanShiftClusteringTest.cs b/VectoCore/VectoCoreTest/Algorithms/MeanShiftClusteringTest.cs index 8bc4baba60..2ddaed78ae 100644 --- a/VectoCore/VectoCoreTest/Algorithms/MeanShiftClusteringTest.cs +++ b/VectoCore/VectoCoreTest/Algorithms/MeanShiftClusteringTest.cs @@ -33,6 +33,7 @@ using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Algorithms @@ -60,14 +61,14 @@ namespace TUGraz.VectoCore.Tests.Algorithms //Console.WriteLine(string.Join(", ", entries)); - var clusterer = new MeanShiftClustering() { + var clusterer = new MeanShiftClustering { ClusterCount = 8 }; var clusters = clusterer.FindClusters(entries.ToArray(), 10); //Console.WriteLine(clusterer.IterationCount); - Console.WriteLine(string.Join(", ", centers)); - Console.WriteLine(string.Join(", ", clusters)); + Console.WriteLine(centers.Join()); + Console.WriteLine(clusters.Join()); Assert.AreEqual(centers.Length, clusters.Length); foreach (var center in centers) { @@ -87,7 +88,7 @@ namespace TUGraz.VectoCore.Tests.Algorithms var clusterer = new MeanShiftClustering(); var clusters = clusterer.FindClusters(entries.ToArray(), 0.1); - Console.WriteLine(string.Join(", ", clusters)); + Console.WriteLine(clusters.Join()); } } } diff --git a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs index 92b1d4a78c..5a1ef16883 100644 --- a/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs +++ b/VectoCore/VectoCoreTest/Integration/TorqueLimitsTest.cs @@ -262,7 +262,7 @@ namespace TUGraz.VectoCore.Tests.Integration Assert.IsTrue(jobContainer.Runs.All(r => r.Success), string.Concat(jobContainer.Runs.Select(r => r.ExecException))); var view = new DataView(sumData.Table, "", SummaryDataContainer.Fields.SORT, DataViewRowState.CurrentRows).ToTable(); - Console.WriteLine(string.Join("; ", view.AsEnumerable().Select(x => x[string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble()))); + Console.WriteLine(view.AsEnumerable().Select(x => x[string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble()).Join("; ")); Assert.AreEqual(203.978084968944, view.Rows[0][string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble(), 1e-3); Assert.AreEqual(243.590313650134, view.Rows[1][string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble(), 1e-3); Assert.AreEqual(174.648229443338, view.Rows[2][string.Format(SummaryDataContainer.Fields.FCMAP_KM, "")].ToString().ToDouble(), 1e-3); diff --git a/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs b/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs index 255c280cec..5719c0f557 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs @@ -2022,11 +2022,11 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration Assert.AreEqual(missionType, m.MissionType); Assert.AreEqual(cosswindCorrection, m.CrossWindCorrectionParameters); CollectionAssert.AreEqual(axleWeightDistribution, m.AxleWeightDistribution, - "Axle distribution not equal.\nexpected: {0}\nactual: {1}", string.Join(",", axleWeightDistribution), - string.Join(",", m.AxleWeightDistribution)); + "Axle distribution not equal.\nexpected: {0}\nactual: {1}", axleWeightDistribution.Join(), + m.AxleWeightDistribution.Join()); CollectionAssert.AreEqual(trailerAxleWeightDistribution, m.Trailer.Select(t => t.TrailerAxleWeightShare), - "Trailer axle distribution not equal.\nexpected: {0}\nactual: {1}", string.Join(",", trailerAxleWeightDistribution), - string.Join(",", m.Trailer.Select(t => t.TrailerAxleWeightShare))); + "Trailer axle distribution not equal.\nexpected: {0}\nactual: {1}", trailerAxleWeightDistribution.Join(), + m.Trailer.Select(t => t.TrailerAxleWeightShare).Join()); Assert.AreEqual(bodyCurbWeight.SI<Kilogram>(), m.BodyCurbWeight); CollectionAssert.AreEqual(trailerCurbWeight, m.Trailer.Select(t => t.TrailerCurbWeight.Value())); CollectionAssert.AreEqual(trailerType, m.Trailer.Select(t => t.TrailerType)); diff --git a/VectoCore/VectoCoreTest/Models/Declaration/DeclarationSegmentHeavyBusesTest.cs b/VectoCore/VectoCoreTest/Models/Declaration/DeclarationSegmentHeavyBusesTest.cs index c3c33b3ec2..82a3184342 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/DeclarationSegmentHeavyBusesTest.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/DeclarationSegmentHeavyBusesTest.cs @@ -691,8 +691,8 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration Assert.AreEqual(lowLoad, m.LowLoad.Value(), 1e-9); foreach (var tuple in axleWeightDistribution.ZipAll(m.AxleWeightDistribution, Tuple.Create)) { - Assert.AreEqual(tuple.Item1, tuple.Item2, 1e-0, "Axle distribution not equal.\nexpected: {0}\nactual: {1}", string.Join(",", axleWeightDistribution), - string.Join(",", m.AxleWeightDistribution)); + Assert.AreEqual(tuple.Item1, tuple.Item2, 1e-0, "Axle distribution not equal.\nexpected: {0}\nactual: {1}", + axleWeightDistribution.Join(), m.AxleWeightDistribution.Join()); } foreach (var entry in expVehicleEquipment) { diff --git a/VectoCore/VectoCoreTest/Models/Declaration/ShiftPolygonTest.cs b/VectoCore/VectoCoreTest/Models/Declaration/ShiftPolygonTest.cs index 44b0a43b6a..903e964704 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/ShiftPolygonTest.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/ShiftPolygonTest.cs @@ -842,7 +842,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration InputDataHelper.InputDataAsStream("engine torque,downshift rpm [rpm],upshift rpm [rpm] ", vgbs))); var results = shiftPolygon.Validate(ExecutionMode.Engineering, VectoSimulationJobType.ConventionalVehicle, null, GearboxType.MT, false); - Assert.IsFalse(results.Any(), string.Join("\n", results.Select(r => r.ErrorMessage))); + Assert.IsFalse(results.Any(), results.Select(r => r.ErrorMessage).Join("\n")); } [ diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponent/BatterySystemTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponent/BatterySystemTest.cs index 85cd34b222..e513e94a44 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponent/BatterySystemTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponent/BatterySystemTest.cs @@ -166,7 +166,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent } var socs = bat.Batteries.SelectMany(x => x.Value.Batteries.Select(y => y.StateOfCharge)).ToArray(); - Console.WriteLine(string.Join(", ", socs)); + Console.WriteLine(socs.Join()); for (var i = 0; i < socs.Length; i++) { Assert.AreEqual(expectedSoC[i], socs[i], 1e-9, $"Bat_{i} SoC"); } @@ -234,7 +234,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent } var socs = bat.Batteries.SelectMany(x => x.Value.Batteries.Select(y => y.StateOfCharge)).ToArray(); - Console.WriteLine(string.Join(", ", socs)); + Console.WriteLine(socs.Join()); Console.WriteLine(bat.StateOfCharge); for (var i = 0; i < socs.Length; i++) { Assert.AreEqual(expectedSoC[i], socs[i], 1e-9, $"Bat_{i} SoC"); @@ -303,7 +303,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent } var socs = bat.Batteries.SelectMany(x => x.Value.Batteries.Select(y => y.StateOfCharge)).ToArray(); - Console.WriteLine(string.Join(", ", socs)); + Console.WriteLine(socs.Join()); Console.WriteLine(bat.StateOfCharge); for (var i = 0; i < socs.Length; i++) { Assert.AreEqual(expectedSoC[i], socs[i], 1e-9, $"Bat_{i} SoC"); diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs index 16602da9db..2857d8a00c 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs @@ -108,7 +108,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData data.FullLoadCurves[0].EngineData = data; var results = data.Validate(ExecutionMode.Declaration, VectoSimulationJobType.ConventionalVehicle, null, null, false); - Assert.IsFalse(results.Any(), "Validation Failed: " + string.Join("; ", results.Select(r => r.ErrorMessage))); + Assert.IsFalse(results.Any(), "Validation Failed: " + results.Select(r => r.ErrorMessage).Join("; ")); Assert.IsTrue(data.IsValid()); } @@ -144,7 +144,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var engineData = dao.CreateEngineData(data, data.EngineModes.First()); var results = engineData.Validate(ExecutionMode.Engineering, VectoSimulationJobType.ConventionalVehicle, null, null, false); - Assert.IsFalse(results.Any(), "Validation failed: " + string.Join("; ", results.Select(r => r.ErrorMessage))); + Assert.IsFalse(results.Any(), "Validation failed: " + results.Select(r => r.ErrorMessage).Join("; ")); Assert.IsTrue(engineData.IsValid()); } @@ -190,7 +190,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var engineData = dao.CreateEngineData(vehicle, data.EngineModes.First(), new Mission() {MissionType = MissionType.LongHaul}); var results = engineData.Validate(ExecutionMode.Declaration, VectoSimulationJobType.ConventionalVehicle, null, null, false); - Assert.IsFalse(results.Any(), "Validation failed: " + string.Join("; ", results.Select(r => r.ErrorMessage))); + Assert.IsFalse(results.Any(), "Validation failed: " + results.Select(r => r.ErrorMessage).Join("; ")); Assert.IsTrue(engineData.IsValid()); } @@ -360,8 +360,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData // every field and property should be tested except private parent fields and properties and // (4*4+1) * 2 = 17*2= 34 - 4 private parent fields (+2 public field and property which are tested twice) = 32 - Assert.AreEqual(32, results.Count, - "Validation Error: " + string.Join("\n_eng_avg", results.Select(r => r.ErrorMessage))); + Assert.AreEqual(32, results.Count, "Validation Error: " + results.Select(r => r.ErrorMessage).Join("\n_eng_avg")); } [TestCase] diff --git a/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs b/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs index 0f36502f3b..1502ea3b16 100644 --- a/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs +++ b/VectoCore/VectoCoreTest/Utils/ResultFileHelper.cs @@ -107,10 +107,11 @@ namespace TUGraz.VectoCore.Tests.Utils } CollectionAssert.AreEqual(expectedCols, actualCols, - string.Format("Moddata {3}: Columns differ:\nExpected: {0}\nMissing:{1},\nToo Much:{2}", - string.Join(", ", expectedCols), - string.Join(", ", expectedCols.Except(actualCols)), - string.Join(", ", actualCols.Except(expectedCols)), result.actualFile)); + "Moddata {0}: Columns differ:\nExpected: {1}\nMissing:{2},\nToo Much:{3}", + result.actualFile, + expectedCols.Join(), + expectedCols.Except(actualCols).Join(), + actualCols.Except(expectedCols).Join()); for (var i = 0; testRowcount && i < expected.Rows.Count; i++) { var expectedRow = expected.Rows[i]; @@ -138,11 +139,11 @@ namespace TUGraz.VectoCore.Tests.Utils var expectedCols = expected.Columns.Cast<DataColumn>().Select(x => x.ColumnName).OrderBy(x => x).ToList(); CollectionAssert.AreEqual(expectedCols, actualCols, - string.Format("SUM FILE {3}: Columns differ:\nExpected: {0}\nMissing:{1},\nToo Much:{2}", - string.Join(", ", expectedCols), - string.Join(", ", expectedCols.Except(actualCols)), - string.Join(", ", actualCols.Except(expectedCols)), - actualFile)); + "SUM FILE {0}: Columns differ:\nExpected: {1}\nMissing:{2},\nToo Much:{3}", + actualFile, + expectedCols.Join(), + expectedCols.Except(actualCols).Join(), + actualCols.Except(expectedCols).Join()); for (var i = 0; i < expected.Rows.Count; i++) { var expectedRow = expected.Rows[i]; diff --git a/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs b/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs index 2d7f9c6d95..630a838fff 100644 --- a/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs +++ b/VectoCore/VectoCoreTest/Utils/VectoMathTest.cs @@ -119,7 +119,7 @@ namespace TUGraz.VectoCore.Tests.Utils { var results = VectoMath.Polynom4Solver(a, b, c, d, e); - Console.WriteLine(string.Join(", ", results)); + Console.WriteLine(results.Join()); Assert.AreEqual(expected.Length, results.Length); diff --git a/VectoCore/VectoCoreTest/XML/XMLReportTest.cs b/VectoCore/VectoCoreTest/XML/XMLReportTest.cs index d88ce535c1..7f595f7ff6 100644 --- a/VectoCore/VectoCoreTest/XML/XMLReportTest.cs +++ b/VectoCore/VectoCoreTest/XML/XMLReportTest.cs @@ -35,6 +35,7 @@ using System.Xml; using Ninject; using NUnit.Framework; using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.XML; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.OutputData; @@ -96,13 +97,13 @@ namespace TUGraz.VectoCore.Tests.XML var validator1 = new XMLValidator(XmlReader.Create(customerRecord), validationErrorAction: (s,e) => { validationMsg1.Add(e?.ValidationEventArgs?.Message ?? "no schema found?"); }); - Assert.IsTrue(validator1.ValidateXML(XmlDocumentType.CustomerReport), string.Join("\n", validationMsg1)); + Assert.IsTrue(validator1.ValidateXML(XmlDocumentType.CustomerReport), validationMsg1.Join("\n")); var validationMsg2 = new List<string> {manufacturerRecord}; var validator2 = new XMLValidator(XmlReader.Create(manufacturerRecord), validationErrorAction: (s,e) => { validationMsg2.Add(e?.ValidationEventArgs?.Message ?? "no schema found"); }); - Assert.IsTrue(validator2.ValidateXML(XmlDocumentType.ManufacturerReport), string.Join("\n", validationMsg2)); + Assert.IsTrue(validator2.ValidateXML(XmlDocumentType.ManufacturerReport), validationMsg2.Join("\n")); } } } \ No newline at end of file -- GitLab