From 304437b834e8c87687f68333ae67a13ee1377a73 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Wed, 12 Jun 2019 21:47:51 +0200 Subject: Adjust Codestyle --- dsa/DSALib/Auxiliary/Calculator/Argument.cs | 15 +++---- dsa/DSALib/Auxiliary/Calculator/ISolvable.cs | 6 +-- dsa/DSALib/Auxiliary/Calculator/Operator.cs | 18 +++----- dsa/DSALib/Auxiliary/Calculator/Ops.cs | 6 +-- dsa/DSALib/Auxiliary/Calculator/StringSolver.cs | 60 +++++++++---------------- 5 files changed, 35 insertions(+), 70 deletions(-) (limited to 'dsa/DSALib/Auxiliary/Calculator') diff --git a/dsa/DSALib/Auxiliary/Calculator/Argument.cs b/dsa/DSALib/Auxiliary/Calculator/Argument.cs index e681377..d6be0c8 100644 --- a/dsa/DSALib/Auxiliary/Calculator/Argument.cs +++ b/dsa/DSALib/Auxiliary/Calculator/Argument.cs @@ -1,16 +1,13 @@ using System; -namespace DSALib.Auxiliary.Calculator -{ +namespace DSALib.Auxiliary.Calculator { /// /// Provides an ISolvable class to save numbers. The class handles Argument checking and conversion from string to int. /// - public class Argument : ISolvable - { + public class Argument : ISolvable { private readonly int value; - public Argument(string value) - { + public Argument(string value) { // check whether the value given is an empty string if (string.IsNullOrEmpty(value)) throw new ArgumentException("Argument kann nicht mit einem leeren string instanziert werden. ", @@ -22,13 +19,11 @@ namespace DSALib.Auxiliary.Calculator this.value = result; } - public int Solve() - { + public int Solve() { return value; } - public override string ToString() - { + public override string ToString() { return value.ToString(); } } diff --git a/dsa/DSALib/Auxiliary/Calculator/ISolvable.cs b/dsa/DSALib/Auxiliary/Calculator/ISolvable.cs index 844e9b3..b2ea779 100644 --- a/dsa/DSALib/Auxiliary/Calculator/ISolvable.cs +++ b/dsa/DSALib/Auxiliary/Calculator/ISolvable.cs @@ -1,10 +1,8 @@ -namespace DSALib.Auxiliary.Calculator -{ +namespace DSALib.Auxiliary.Calculator { /// /// Object has to be able to return an integer as it's value /// - public interface ISolvable - { + public interface ISolvable { int Solve(); } } \ No newline at end of file diff --git a/dsa/DSALib/Auxiliary/Calculator/Operator.cs b/dsa/DSALib/Auxiliary/Calculator/Operator.cs index e6aeec6..f3d5c9f 100644 --- a/dsa/DSALib/Auxiliary/Calculator/Operator.cs +++ b/dsa/DSALib/Auxiliary/Calculator/Operator.cs @@ -1,17 +1,14 @@ using System; using DSALibv.Auxiliary.Calculator; -namespace DSALib.Auxiliary.Calculator -{ +namespace DSALib.Auxiliary.Calculator { /// /// The Operator Class represents a binary operator with tow Arguments and an Operation type /// - public class Operator : ISolvable - { + public class Operator : ISolvable { private readonly ISolvable arg1, arg2; - public Operator(ISolvable arg1, ISolvable arg2, Ops operatorType) - { + public Operator(ISolvable arg1, ISolvable arg2, Ops operatorType) { this.arg1 = arg1; this.arg2 = arg2; OperatorType = operatorType; @@ -19,11 +16,9 @@ namespace DSALib.Auxiliary.Calculator public Ops OperatorType { get; set; } - public int Solve() - { + public int Solve() { int result; - switch (OperatorType) - { + switch (OperatorType) { case Ops.Dice: result = Dice.Roll(arg1.Solve(), arg2.Solve()); break; @@ -43,8 +38,7 @@ namespace DSALib.Auxiliary.Calculator return result; } - public override string ToString() - { + public override string ToString() { return $"({arg1} {OperatorType} {arg2})"; } } diff --git a/dsa/DSALib/Auxiliary/Calculator/Ops.cs b/dsa/DSALib/Auxiliary/Calculator/Ops.cs index 93046d0..cf1a8e7 100644 --- a/dsa/DSALib/Auxiliary/Calculator/Ops.cs +++ b/dsa/DSALib/Auxiliary/Calculator/Ops.cs @@ -1,10 +1,8 @@ -namespace DSALibv.Auxiliary.Calculator -{ +namespace DSALibv.Auxiliary.Calculator { /// /// The Different Operations, witch can be performed in execution-order /// - public enum Ops - { + public enum Ops { Dice, Multiply, Subtract, diff --git a/dsa/DSALib/Auxiliary/Calculator/StringSolver.cs b/dsa/DSALib/Auxiliary/Calculator/StringSolver.cs index 45d6a54..d46f8bc 100644 --- a/dsa/DSALib/Auxiliary/Calculator/StringSolver.cs +++ b/dsa/DSALib/Auxiliary/Calculator/StringSolver.cs @@ -3,24 +3,20 @@ using System.Collections.Generic; using System.Linq; using DSALibv.Auxiliary.Calculator; -namespace DSALib.Auxiliary.Calculator -{ +namespace DSALib.Auxiliary.Calculator { /// /// The StringSolver divides the calculation string into operations and SubStringSolvers if the string contains /// parentheses /// - public class StringSolver : ISolvable - { + public class StringSolver : ISolvable { private readonly List arguments = new List(); private readonly string input; - public StringSolver(string input) - { + public StringSolver(string input) { this.input = input; } - public int Solve() - { + public int Solve() { var workInput = "0+" + input.Replace(" ", string.Empty).ToLower(); workInput = ExpandParentheses(workInput); @@ -34,8 +30,7 @@ namespace DSALib.Auxiliary.Calculator return ((ISolvable) arguments.First()).Solve(); } - public override string ToString() - { + public override string ToString() { return "(0+" + input.Replace(" ", string.Empty).ToLower() + ")"; } @@ -43,23 +38,19 @@ namespace DSALib.Auxiliary.Calculator GetInner(ref string input) // extract the inner bracket an remove the section from the input string { var depth = 0; - for (var index = 1; index < input.Length; index++) - { + for (var index = 1; index < input.Length; index++) { var c = input[index]; - switch (c) - { + switch (c) { case '(': depth++; break; case ')': - if (depth == 0) - { + if (depth == 0) { var split = input.Substring(1, index - 1); input = input.Substring(index + 1); return split.Equals(string.Empty) ? "0" : split; } - else - { + else { depth--; } @@ -70,10 +61,8 @@ namespace DSALib.Auxiliary.Calculator throw new ArgumentException("Invalid brace sequence"); } - private static Ops GetOps(char c) - { - switch (c) - { + private static Ops GetOps(char c) { + switch (c) { case 'd': case 'w': return Ops.Dice; @@ -101,14 +90,11 @@ namespace DSALib.Auxiliary.Calculator return input; } - private void AtomizeOperations(string workInput) - { - for (var index = 0; index < workInput.Length; index++) - { + private void AtomizeOperations(string workInput) { + for (var index = 0; index < workInput.Length; index++) { var c = workInput[index]; - if (char.IsNumber(c)) - { + if (char.IsNumber(c)) { // if char number, check if at end of string, else continue looping if (index == workInput.Length - 1) // if at end of string; add remaining number to arguments @@ -117,8 +103,7 @@ namespace DSALib.Auxiliary.Calculator continue; } - switch (c) - { + switch (c) { case ')': throw new ArgumentException("Invalid brace sequence"); case '(': @@ -136,12 +121,10 @@ namespace DSALib.Auxiliary.Calculator } } - private void NestOperations() - { + private void NestOperations() { foreach (Ops currentOp in Enum.GetValues(typeof(Ops))) // cycle through operators in operational order - for (var index = 0; index < arguments.Count; index++) - { + for (var index = 0; index < arguments.Count; index++) { var arg = arguments[index]; if (arg.GetType() != typeof(Ops)) continue; @@ -162,19 +145,16 @@ namespace DSALib.Auxiliary.Calculator } } - private void HandleSpecialFormatting(ref int index, Ops op) - { + private void HandleSpecialFormatting(ref int index, Ops op) { var arg1 = arguments[index - 1]; - if (arg1.GetType() == typeof(Ops)) - { + if (arg1.GetType() == typeof(Ops)) { if (op == Ops.Dice) arguments.Insert(index++, new Argument("1")); // w6 -> 1w6 if (op == Ops.Subtract) arguments.Insert(index++, new Argument("0")); // +-3 -> +0-3 } var arg2 = arguments[index + 1]; // 3+-5 -> 3+(0-5) - if (arg2.GetType() == typeof(Ops)) - { + if (arg2.GetType() == typeof(Ops)) { arguments[index + 1] = new Operator(new Argument("0"), (ISolvable) arguments[index + 2], (Ops) arg2); arguments.RemoveAt(index + 2); } -- cgit v1.2.3-54-g00ecf