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