gitlab.com/evatix-go/core@v1.3.55/coredata/corerange/MinMaxInt16.go (about)

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