gitlab.com/evatix-go/core@v1.3.55/coredata/corerange/StartEndInt.go (about) 1 package corerange 2 3 import ( 4 "fmt" 5 6 "gitlab.com/evatix-go/core/constants" 7 ) 8 9 type StartEndInt struct { 10 Start int `json:"Start"` 11 End int `json:"End"` 12 } 13 14 func (it *StartEndInt) IsInvalidStart() bool { 15 return it == nil || it.Start <= 0 16 } 17 18 func (it *StartEndInt) IsStartEndBothDefined() bool { 19 return it != nil && it.HasStart() && it.HasEnd() 20 } 21 22 func (it *StartEndInt) IsInvalidStartEndBoth() bool { 23 return it.IsInvalidStart() && it.IsInvalidEnd() 24 } 25 26 func (it *StartEndInt) IsInvalidAnyStartEnd() bool { 27 return it.IsInvalidStart() || it.IsInvalidEnd() 28 } 29 30 func (it *StartEndInt) IsStartGraterThan(val int) bool { 31 return it != nil && it.Start > val 32 } 33 34 func (it *StartEndInt) IsEndGraterThan(val int) bool { 35 return it != nil && it.End > val 36 } 37 38 func (it *StartEndInt) HasStart() bool { 39 return it != nil && it.Start > 0 40 } 41 42 func (it *StartEndInt) IsInvalidEnd() bool { 43 return it == nil || it.End <= 0 44 } 45 46 func (it *StartEndInt) HasEnd() bool { 47 return it != nil && it.End > 0 48 } 49 50 func (it *StartEndInt) StringUsingFormat(format string) string { 51 return fmt.Sprintf(format, it.Start, it.End) 52 } 53 54 func (it *StartEndInt) StringSpace() string { 55 return fmt.Sprintf("%d %d", it.Start, it.End) 56 } 57 58 func (it *StartEndInt) StringHyphen() string { 59 return fmt.Sprintf("%d-%d", it.Start, it.End) 60 } 61 62 func (it *StartEndInt) StringColon() string { 63 return fmt.Sprintf("%d:%d", it.Start, it.End) 64 } 65 66 func (it *StartEndInt) RangeInt(minMax *MinMaxInt) *RangeInt { 67 return NewRangeInt(it.StringColon(), constants.Colon, minMax) 68 } 69 70 func (it *StartEndInt) RangeInt16(minMax *MinMaxInt16) *RangeInt16 { 71 return NewRangeInt16(it.StringColon(), constants.Colon, minMax) 72 } 73 74 func (it *StartEndInt) RangeInt8(minMax *MinMaxInt8) *RangeInt8 { 75 return NewRangeInt8(it.StringColon(), constants.Colon, minMax) 76 }