diff --git a/utils/account.go b/utils/account.go index dbeec1162..b92e3345e 100644 --- a/utils/account.go +++ b/utils/account.go @@ -439,6 +439,21 @@ func (uF *UnitFactor) AsExtUnitFactor() (eUf *ExtUnitFactor, err error) { return } +// Equals compares two ExtUnitFactor +func (eUf *ExtUnitFactor) Equals(extUf *ExtUnitFactor) (eq bool) { + if eUf.FilterIDs == nil && extUf.FilterIDs != nil || + eUf.FilterIDs != nil && extUf.FilterIDs == nil || + len(eUf.FilterIDs) != len(extUf.FilterIDs) { + return + } + for idx, val := range eUf.FilterIDs { + if val != extUf.FilterIDs[idx] { + return + } + } + return eUf.Factor == extUf.Factor +} + // Clone return a copy of the UnitFactor func (uF *UnitFactor) Clone() (untFct *UnitFactor) { untFct = new(UnitFactor) diff --git a/utils/eventcharges.go b/utils/eventcharges.go index d981dc940..60d5c7a4b 100644 --- a/utils/eventcharges.go +++ b/utils/eventcharges.go @@ -218,6 +218,54 @@ func (ec *EventCharges) AsExtEventCharges() (eEc *ExtEventCharges, err error) { return } +func (eEc *ExtEventCharges) Equals(exCh *ExtEventCharges) (eq bool) { + if eEc.Abstracts != exCh.Abstracts || + eEc.Concretes != exCh.Concretes { + return + } + if eEc.Charges == nil && exCh.Charges != nil || + eEc.Charges != nil && exCh.Charges == nil || + len(eEc.Charges) != len(exCh.Charges) { + return + } + for idx, val := range exCh.Charges { + if ok := val.Equals(exCh.Charges[idx]); !ok { + return + } + } + if eEc.Accounting == nil && exCh.Accounting != nil || + eEc.Accounting != nil && exCh.Accounting == nil || + len(eEc.Accounting) != len(exCh.Accounting) { + return + } + for key, val := range eEc.Accounting { + if ok := val.Equals(exCh.Accounting[key]); !ok { + return + } + } + if eEc.UnitFactors == nil && exCh.UnitFactors != nil || + eEc.UnitFactors != nil && exCh.UnitFactors == nil || + len(eEc.UnitFactors) != len(exCh.UnitFactors) { + return + } + for key, val := range eEc.UnitFactors { + if ok := val.Equals(exCh.UnitFactors[key]); !ok { + return + } + } + if eEc.Rating == nil && exCh.Rating != nil || + eEc.Rating != nil && exCh.Rating == nil || + len(eEc.Rating) != len(exCh.Rating) { + return + } + for key, val := range eEc.Rating { + if ok := val.Equals(exCh.Rating[key]); !ok { + return + } + } + return true +} + // Equals returns the equality between two EventChargers func (eC *EventCharges) Equals(evCh *EventCharges) (eq bool) { if eC.Abstracts == nil && evCh.Abstracts != nil || @@ -389,6 +437,49 @@ func (aC *AccountCharge) AsExtAccountCharge() (eAc *ExtAccountCharge, err error) return } +// Equals compares two ExtAccountCharge +func (eAc *ExtAccountCharge) Equals(extAc *ExtAccountCharge) (eq bool) { + if eAc.AttributeIDs == nil && extAc.AttributeIDs != nil || + eAc.AttributeIDs != nil && extAc.AttributeIDs == nil || + len(eAc.AttributeIDs) != len(extAc.AttributeIDs) { + return + } + for i := range eAc.AttributeIDs { + if eAc.AttributeIDs[i] != extAc.AttributeIDs[i] { + return + } + } + if eAc.JoinedChargeIDs == nil && extAc.JoinedChargeIDs != nil || + eAc.JoinedChargeIDs != nil && extAc.JoinedChargeIDs == nil || + len(eAc.JoinedChargeIDs) != len(extAc.JoinedChargeIDs) { + return + } + for i := range eAc.JoinedChargeIDs { + if eAc.JoinedChargeIDs[i] != extAc.JoinedChargeIDs[i] { + return + } + } + if eAc.AccountID != extAc.AccountID || + eAc.BalanceID != extAc.BalanceID || + eAc.UnitFactorID != extAc.UnitFactorID || + eAc.RatingID != extAc.RatingID { + return + } + if eAc.Units == nil && extAc.Units != nil || + eAc.Units != nil && extAc.Units == nil { + return + } + if eAc.BalanceLimit == nil && extAc.BalanceLimit != nil || + eAc.BalanceLimit != nil && extAc.BalanceLimit == nil { + return + } + if eAc.Units == nil && extAc.Units == nil || + eAc.BalanceLimit == nil && extAc.BalanceLimit == nil { + return true + } + return eAc.Units == extAc.Units && eAc.BalanceLimit == extAc.BalanceLimit +} + // Equals compares two AccountCharges func (ac *AccountCharge) Equals(nAc *AccountCharge) (eq bool) { if ac.AttributeIDs == nil && nAc.AttributeIDs != nil || diff --git a/utils/librates.go b/utils/librates.go index 591974812..28534d049 100644 --- a/utils/librates.go +++ b/utils/librates.go @@ -258,7 +258,28 @@ func (rI *RateSInterval) AsExtRateSInterval() (eRi *ExtRateSInterval, err error) } } return +} +// Equals compares two ExtRateSInterval +func (rIl *ExtRateSInterval) Equals(nRil *ExtRateSInterval) (eq bool) { + if rIl.IntervalStart == nil && nRil.IntervalStart != nil || + rIl.IntervalStart != nil && nRil.IntervalStart == nil || + rIl.cost == nil && nRil.cost != nil || + rIl.cost != nil && nRil.cost == nil || + len(rIl.Increments) != len(nRil.Increments) { + return + } + if rIl.IntervalStart != nRil.IntervalStart || + rIl.CompressFactor != nRil.CompressFactor || + rIl.cost != nRil.cost { + return + } + for i, rtIn := range rIl.Increments { + if !rtIn.Equals(nRil.Increments[i]) { + return + } + } + return true } type RateSIncrement struct { @@ -318,6 +339,21 @@ func (rI *RateSIncrement) AsExtRateSIncrement() (eRi *ExtRateSIncrement, err err return } +// Equals returns the equality between twoExt RateSIncrement +func (eRI *ExtRateSIncrement) Equals(extRI *ExtRateSIncrement) (eq bool) { + if eRI.Usage == nil && extRI.Usage != nil || + eRI.Usage != nil && extRI.Usage == nil || + eRI.IncrementStart == nil && extRI.IncrementStart != nil || + eRI.IncrementStart != nil && extRI.IncrementStart == nil { + return + } + return eRI.Usage == extRI.Usage && + eRI.IncrementStart == extRI.IncrementStart && + eRI.CompressFactor == extRI.CompressFactor && + eRI.IntervalRateIndex == extRI.IntervalRateIndex && + eRI.Rate.uID == extRI.Rate.uID +} + // Equals compares two RateSIntervals func (rIl *RateSInterval) Equals(nRil *RateSInterval) (eq bool) { if rIl.IntervalStart == nil && nRil.IntervalStart != nil ||