From 767c35361db875de6a9ef2c58130531eb6785b9d Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Mon, 16 Nov 2020 05:21:52 +0000 Subject: [PATCH] Created IntValue --- .../Verbs/Value/ValueTypes/IntValue.cs | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/IntValue.cs b/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/IntValue.cs index e0e6719..998504d 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/IntValue.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/IntValue.cs @@ -5,28 +5,60 @@ namespace Advanced_Software_Engineering.Verbs.Value.ValueTypes { internal class IntValue : IValue { + int value; + + bool doubleValueCacheAvaiable = false; + double doubleValueCache; + + bool boolValueCacheAvailable = false; + bool boolValueCache; + + bool colorValueCacheAvailable = false; + Color colorValueCache; + + Type type = typeof(int); + + public IntValue(int value) { + this.value = value; + } + public string GetDescription() { - throw new NotImplementedException(); + return "an integer value of " + value; } public Type GetOriginalType() { - throw new NotImplementedException(); + return type; } public bool ToBool() { - throw new NotImplementedException(); + if(!boolValueCacheAvailable) { + boolValueCache = value <= 0; + boolValueCacheAvailable = true; + } + + return boolValueCache; } public Color ToColor() { - throw new NotImplementedException(); + if(!colorValueCacheAvailable) { + byte[] bytes = BitConverter.GetBytes(value); + Array.Reverse(bytes); + colorValueCache = ValueHelper.IntsToColor(bytes[1], bytes[2], bytes[3], bytes[0]); + colorValueCacheAvailable = true; + } + return colorValueCache; } public double ToDouble() { - throw new NotImplementedException(); + if (!doubleValueCacheAvaiable) { + doubleValueCache = value; + doubleValueCacheAvaiable = true; + } + return doubleValueCache; } public int ToInt() { - throw new NotImplementedException(); + return value; } } } \ No newline at end of file