gitlab.com/evatix-go/core@v1.3.55/coreinstruction/LineIdentifier.go (about) 1 package coreinstruction 2 3 import ( 4 "gitlab.com/evatix-go/core/constants" 5 "gitlab.com/evatix-go/core/reqtype" 6 ) 7 8 type LineIdentifier struct { 9 LineNumber int `json:"LineNumber,omitempty"` 10 LineModifyAs reqtype.Request `json:"LineModifyAs,omitempty"` 11 } 12 13 func (it *LineIdentifier) IsInvalidLineNumber() bool { 14 return it == nil || it.LineNumber < 0 15 } 16 17 func (it *LineIdentifier) IsInvalidLineNumberUsingLastLineNumber(lastLineNumber int) bool { 18 return it == nil || it.LineNumber < 0 || it.LineNumber > lastLineNumber 19 } 20 21 func (it *LineIdentifier) HasLineNumber() bool { 22 return it != nil && it.LineNumber > constants.InvalidValue 23 } 24 25 func (it *LineIdentifier) IsNewLineRequest() bool { 26 return it.LineModifyAs.IsCreate() 27 } 28 29 func (it *LineIdentifier) IsDeleteLineRequest() bool { 30 return it.HasLineNumber() && 31 it.LineModifyAs.IsDelete() || 32 it.LineModifyAs.IsDrop() 33 } 34 35 func (it *LineIdentifier) IsModifyLineRequest() bool { 36 return it.HasLineNumber() && 37 it.LineModifyAs.IsUpdate() 38 } 39 40 func (it *LineIdentifier) IsAddNewOrModifyLineRequest() bool { 41 return it.IsNewLineRequest() || it.IsModifyLineRequest() 42 } 43 44 func (it *LineIdentifier) ToBaseLineIdentifier() *BaseLineIdentifier { 45 if it == nil { 46 return nil 47 } 48 49 return NewBaseLineIdentifier(it.LineNumber, it.LineModifyAs) 50 } 51 52 func (it *LineIdentifier) Clone() *LineIdentifier { 53 if it == nil { 54 return nil 55 } 56 57 return &LineIdentifier{ 58 LineNumber: it.LineNumber, 59 LineModifyAs: it.LineModifyAs, 60 } 61 }