mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add clone function for EventCharges
This commit is contained in:
committed by
Dan Christian Bogos
parent
874aff7695
commit
cb3531d61b
@@ -237,19 +237,16 @@ func (cI *CostIncrement) Clone() (cIcln *CostIncrement) {
|
||||
return
|
||||
}
|
||||
|
||||
// Clone return a copy of the UnitFactor
|
||||
func (uF *UnitFactor) Clone() (untFct *UnitFactor) {
|
||||
untFct = new(UnitFactor)
|
||||
// Clone returns a copy of uF
|
||||
func (uF *UnitFactor) Clone() *UnitFactor {
|
||||
cln := new(UnitFactor)
|
||||
if uF.FilterIDs != nil {
|
||||
untFct.FilterIDs = make([]string, len(uF.FilterIDs))
|
||||
for i, value := range uF.FilterIDs {
|
||||
untFct.FilterIDs[i] = value
|
||||
}
|
||||
cln.FilterIDs = CloneStringSlice(uF.FilterIDs)
|
||||
}
|
||||
if uF.Factor != nil {
|
||||
untFct.Factor = uF.Factor.Clone()
|
||||
cln.Factor = uF.Factor.Clone()
|
||||
}
|
||||
return
|
||||
return cln
|
||||
}
|
||||
|
||||
// UnitFactor is a multiplicator for the usage received
|
||||
|
||||
@@ -44,12 +44,69 @@ type EventCharges struct {
|
||||
Accounts map[string]*Account
|
||||
}
|
||||
|
||||
// Clone returns a copy of ec
|
||||
func (ec *EventCharges) Clone() *EventCharges {
|
||||
cln := new(EventCharges)
|
||||
if ec.Abstracts != nil {
|
||||
cln.Abstracts = ec.Abstracts.Clone()
|
||||
}
|
||||
if ec.Concretes != nil {
|
||||
cln.Concretes = ec.Concretes.Clone()
|
||||
}
|
||||
if ec.Charges != nil {
|
||||
cln.Charges = make([]*ChargeEntry, len(ec.Charges))
|
||||
for i, value := range ec.Charges {
|
||||
cln.Charges[i] = value.Clone()
|
||||
}
|
||||
}
|
||||
if ec.Accounting != nil {
|
||||
cln.Accounting = make(map[string]*AccountCharge)
|
||||
for key, value := range ec.Accounting {
|
||||
cln.Accounting[key] = value.Clone()
|
||||
}
|
||||
}
|
||||
if ec.UnitFactors != nil {
|
||||
cln.UnitFactors = make(map[string]*UnitFactor)
|
||||
for key, value := range ec.UnitFactors {
|
||||
cln.UnitFactors[key] = value.Clone()
|
||||
}
|
||||
}
|
||||
if ec.Rating != nil {
|
||||
cln.Rating = make(map[string]*RateSInterval)
|
||||
for key, value := range ec.Rating {
|
||||
cln.Rating[key] = value.Clone()
|
||||
}
|
||||
}
|
||||
if ec.Rates != nil {
|
||||
cln.Rates = make(map[string]*IntervalRate)
|
||||
for key, value := range ec.Rates {
|
||||
cln.Rates[key] = value.Clone()
|
||||
}
|
||||
}
|
||||
if ec.Accounts != nil {
|
||||
cln.Accounts = make(map[string]*Account)
|
||||
for key, value := range ec.Accounts {
|
||||
cln.Accounts[key] = value.Clone()
|
||||
}
|
||||
}
|
||||
|
||||
return cln
|
||||
}
|
||||
|
||||
// ChargeEntry is a reference towards Accounting or Rating ID (depending on request type)
|
||||
type ChargeEntry struct {
|
||||
ChargingID string
|
||||
CompressFactor int
|
||||
}
|
||||
|
||||
// Clone returns a copy of ce
|
||||
func (ce *ChargeEntry) Clone() *ChargeEntry {
|
||||
return &ChargeEntry{
|
||||
ChargingID: ce.ChargingID,
|
||||
CompressFactor: ce.CompressFactor,
|
||||
}
|
||||
}
|
||||
|
||||
// Merge will merge the event charges into existing
|
||||
func (ec *EventCharges) Merge(eCs ...*EventCharges) {
|
||||
//ec.SyncIDs(eCs...) // so we can compare properly
|
||||
@@ -258,6 +315,29 @@ type AccountCharge struct {
|
||||
JoinedChargeIDs []string // identificator of extra account charges
|
||||
}
|
||||
|
||||
// Clone returns a copy of ac
|
||||
func (ac *AccountCharge) Clone() *AccountCharge {
|
||||
cln := &AccountCharge{
|
||||
AccountID: ac.AccountID,
|
||||
BalanceID: ac.BalanceID,
|
||||
UnitFactorID: ac.UnitFactorID,
|
||||
RatingID: ac.RatingID,
|
||||
}
|
||||
if ac.Units != nil {
|
||||
cln.Units = ac.Units.Clone()
|
||||
}
|
||||
if ac.BalanceLimit != nil {
|
||||
cln.BalanceLimit = ac.BalanceLimit.Clone()
|
||||
}
|
||||
if ac.AttributeIDs != nil {
|
||||
cln.AttributeIDs = CloneStringSlice(ac.AttributeIDs)
|
||||
}
|
||||
if ac.JoinedChargeIDs != nil {
|
||||
cln.JoinedChargeIDs = CloneStringSlice(ac.JoinedChargeIDs)
|
||||
}
|
||||
return cln
|
||||
}
|
||||
|
||||
// Equals compares two AccountCharges
|
||||
func (ac *AccountCharge) equals(nAc *AccountCharge) (eq bool) {
|
||||
if ac == nil && nAc == nil {
|
||||
|
||||
@@ -81,6 +81,27 @@ type IntervalRate struct {
|
||||
Increment *Decimal // RateIncrement
|
||||
}
|
||||
|
||||
// Clone returns a copy of iR
|
||||
func (iR *IntervalRate) Clone() *IntervalRate {
|
||||
cln := new(IntervalRate)
|
||||
if iR.IntervalStart != nil {
|
||||
cln.IntervalStart = iR.IntervalStart.Clone()
|
||||
}
|
||||
if iR.FixedFee != nil {
|
||||
cln.FixedFee = iR.FixedFee.Clone()
|
||||
}
|
||||
if iR.RecurrentFee != nil {
|
||||
cln.RecurrentFee = iR.RecurrentFee.Clone()
|
||||
}
|
||||
if iR.Unit != nil {
|
||||
cln.Unit = iR.Unit.Clone()
|
||||
}
|
||||
if iR.Increment != nil {
|
||||
cln.Increment = iR.Increment.Clone()
|
||||
}
|
||||
return cln
|
||||
}
|
||||
|
||||
// Equals returns the equality between two IntervalRate
|
||||
func (iR *IntervalRate) Equals(inRt *IntervalRate) (eq bool) {
|
||||
if iR == nil && inRt == nil {
|
||||
@@ -165,6 +186,27 @@ type RateSInterval struct {
|
||||
cost *decimal.Big // unexported total interval cost
|
||||
}
|
||||
|
||||
// Clone returns a copy of rI
|
||||
func (rI *RateSInterval) Clone() *RateSInterval {
|
||||
cln := &RateSInterval{
|
||||
CompressFactor: rI.CompressFactor,
|
||||
}
|
||||
if rI.IntervalStart != nil {
|
||||
cln.IntervalStart = rI.IntervalStart.Clone()
|
||||
}
|
||||
if rI.Increments != nil {
|
||||
cln.Increments = make([]*RateSIncrement, len(rI.Increments))
|
||||
for i, value := range rI.Increments {
|
||||
cln.Increments[i] = value.Clone()
|
||||
}
|
||||
}
|
||||
if rI.cost != nil {
|
||||
tmp := &decimal.Big{}
|
||||
cln.cost = tmp.Copy(rI.cost)
|
||||
}
|
||||
return cln
|
||||
}
|
||||
|
||||
// AsRatesIntervalsCost converts RateSInterval to RateSIntervalCost
|
||||
// The difference between this 2 is that RateSIntervalCost don't need IntervalStart
|
||||
func (rI *RateSInterval) AsRatesIntervalsCost() (rIc *RateSIntervalCost) {
|
||||
@@ -190,6 +232,26 @@ type RateSIncrement struct {
|
||||
cost *decimal.Big // unexported total increment cost
|
||||
}
|
||||
|
||||
// Clone returns a copy of rI
|
||||
func (rI *RateSIncrement) Clone() *RateSIncrement {
|
||||
cln := &RateSIncrement{
|
||||
RateIntervalIndex: rI.RateIntervalIndex,
|
||||
RateID: rI.RateID,
|
||||
CompressFactor: rI.CompressFactor,
|
||||
}
|
||||
if rI.IncrementStart != nil {
|
||||
cln.IncrementStart = rI.IncrementStart.Clone()
|
||||
}
|
||||
if rI.Usage != nil {
|
||||
cln.Usage = rI.Usage.Clone()
|
||||
}
|
||||
if rI.cost != nil {
|
||||
tmp := &decimal.Big{}
|
||||
cln.cost = tmp.Copy(rI.cost)
|
||||
}
|
||||
return cln
|
||||
}
|
||||
|
||||
// Equals compares two RateSIntervals
|
||||
func (rIl *RateSInterval) Equals(nRil *RateSInterval, rIlRef, nRilRef map[string]*IntervalRate) (eq bool) {
|
||||
if rIl == nil && nRil == nil {
|
||||
|
||||
Reference in New Issue
Block a user