gitlab.com/evatix-go/core@v1.3.55/coredata/corerange/MinMaxInt8.go (about) 1 package corerange 2 3 import "gitlab.com/evatix-go/core/constants" 4 5 type MinMaxInt8 struct { 6 Min, Max int8 7 } 8 9 func (it *MinMaxInt8) CreateMinMaxInt() *MinMaxInt { 10 return &MinMaxInt{ 11 Min: int(it.Min), 12 Max: int(it.Min), 13 } 14 } 15 16 func (it *MinMaxInt8) CreateRangeInt(rawString, separator string) *RangeInt { 17 return NewRangeInt( 18 rawString, 19 separator, 20 it.CreateMinMaxInt()) 21 } 22 23 func (it *MinMaxInt8) CreateRangeInt8(rawString, separator string) *RangeInt8 { 24 return NewRangeInt( 25 rawString, 26 separator, 27 it.CreateMinMaxInt()). 28 CreateRangeInt8() 29 } 30 31 func (it *MinMaxInt8) CreateRangeInt16(rawString, separator string) *RangeInt16 { 32 return NewRangeInt( 33 rawString, 34 separator, 35 it.CreateMinMaxInt()). 36 CreateRangeInt16() 37 } 38 39 func (it *MinMaxInt8) Difference() int8 { 40 return it.Max - it.Min 41 } 42 43 func (it *MinMaxInt8) DifferenceAbsolute() int8 { 44 diff := it.Difference() 45 46 if diff < 0 { 47 return diff 48 } 49 50 return diff 51 } 52 53 func (it *MinMaxInt8) IsMinEqual(val int8) bool { 54 return it != nil && it.Min == val 55 } 56 57 func (it *MinMaxInt8) IsMinAboveEqual(val int8) bool { 58 return it != nil && it.Min >= val 59 } 60 61 func (it *MinMaxInt8) IsMinAbove(val int8) bool { 62 return it != nil && it.Min > val 63 } 64 65 func (it *MinMaxInt8) IsMinLess(val int8) bool { 66 return it != nil && it.Min < val 67 } 68 69 func (it *MinMaxInt8) IsMinLessEqual(val int8) bool { 70 return it != nil && it.Min <= val 71 } 72 73 func (it *MinMaxInt8) IsMaxEqual(val int8) bool { 74 return it != nil && it.Max == val 75 } 76 77 func (it *MinMaxInt8) IsMaxAboveEqual(val int8) bool { 78 return it != nil && it.Max >= val 79 } 80 81 func (it *MinMaxInt8) IsMaxAbove(val int8) bool { 82 return it != nil && it.Max > val 83 } 84 85 func (it *MinMaxInt8) IsMaxLess(val int8) bool { 86 return it != nil && it.Max < val 87 } 88 89 func (it *MinMaxInt8) IsMaxLessEqual(val int8) bool { 90 return it != nil && it.Max <= val 91 } 92 93 func (it *MinMaxInt8) RangeLengthInt() int { 94 return int(it.RangeLength()) 95 } 96 97 // RangeLength (5 - 3 = 2) + 1 98 func (it *MinMaxInt8) RangeLength() int8 { 99 return it.DifferenceAbsolute() + 1 100 } 101 102 // RangesInt 103 // 104 // returns empty integers if IsInvalid 105 // return range int values 106 func (it *MinMaxInt8) RangesInt() []int { 107 actualRanges := it.Ranges() 108 rangesIntegers := make( 109 []int, 110 it.RangeLengthInt()) 111 112 for i, actualValue := range actualRanges { 113 rangesIntegers[i] = int(actualValue) 114 } 115 116 return rangesIntegers 117 } 118 119 // Ranges 120 // 121 // returns empty integers if IsInvalid 122 // return range int values 123 func (it *MinMaxInt8) Ranges() []int8 { 124 length := it.RangeLength() 125 start := it.Min 126 slice := make([]int8, constants.Zero, length) 127 var i int8 128 129 for i = 0; i < length; i++ { 130 slice[i] = start + i 131 } 132 133 return slice 134 } 135 136 // IsWithinRange r.Min >= value && value <= r.Max 137 func (it *MinMaxInt8) IsWithinRange(value int8) bool { 138 return it.Min >= value && value <= it.Max 139 } 140 141 // IsInvalidValue !r.IsWithinRange(value) 142 func (it *MinMaxInt8) IsInvalidValue(value int8) bool { 143 return !it.IsWithinRange(value) 144 } 145 146 func (it MinMaxInt8) IsOutOfRange(value int8) bool { 147 return !it.IsWithinRange(value) 148 } 149 150 func (it *MinMaxInt8) ClonePtr() *MinMaxInt8 { 151 if it == nil { 152 return nil 153 } 154 155 return &MinMaxInt8{ 156 Min: it.Min, 157 Max: it.Max, 158 } 159 } 160 161 func (it *MinMaxInt8) Clone() MinMaxInt8 { 162 return MinMaxInt8{ 163 Min: it.Min, 164 Max: it.Max, 165 } 166 } 167 168 func (it *MinMaxInt8) IsEqual(right *MinMaxInt8) bool { 169 if it == nil && right == nil { 170 return true 171 } 172 173 if it == nil || right == nil { 174 return true 175 } 176 177 if it == right { 178 return true 179 } 180 181 return it.Max == right.Max && 182 it.Min == right.Min 183 }