Beispiel #1
0
//Less is the Weight interface function implementation
func (sw1 *SingleWeight) Less(w Weight) bool {
	sw2 := w.(*SingleWeight)

	if sw1.Value == sw2.Value {
		return false
	}

	switch sw1.Value.(type) {
	case string:
		if sw1.Value.(string) < sw2.Value.(string) {
			return true
		}
	case uint, uint8, uint16, uint32, uint64:
		if reflect.ValueOf(sw1.Value).Uint() < reflect.ValueOf(sw2.Value).Uint() {
			return true
		}
	case int, int8, int16, int32, int64:
		if reflect.ValueOf(sw1.Value).Int() < reflect.ValueOf(sw2.Value).Int() {
			return true
		}
	case float32, float64:
		if reflect.ValueOf(sw1.Value).Float() < reflect.ValueOf(sw2.Value).Float() {
			return true
		}
	default:
		trace.Log("Not comparable type in SingleWeight.Value", sw1.Value)
	}
	return false
}
Beispiel #2
0
// CreateParameters generates Parameters interface
// from the common key-value map
func CreateParameters(data map[string]Parameter) Parameters {
	params := parametersRecord{data, 0, 0}

	if _, ok := data["Type"]; ok {
		if requestType, ok := data["Type"].(uint); ok {
			params.requestType = requestType
		} else {
			trace.Log("Parameters 'Type' value type must be 'uint'")
		}
	}

	if _, ok := data["Time"]; ok {
		if requestTime, ok := data["Time"].(int64); ok {
			params.requestTime = int64(requestTime)
		} else {
			trace.Log("Parameters 'Time' value type must be 'int64'")
		}
	}

	return &params
}
Beispiel #3
0
//Add is the Weight interface implementation
func (pw1 *ParamsWeight) Add(w Weight) {
	pw2 := w.(*ParamsWeight)

	pw1Params := pw1.Params.All()

	for key, value := range pw2.Params.All() {
		if _, ok := pw1Params[key]; ok {
			trace.Log("Key ", key, " already exists into initial parameters set. ", pw1.Params, pw2.Params)
		}
		pw1Params[key] = value
	}

	pw1.Params = CreateParameters(pw1Params)
}
Beispiel #4
0
//Add is a Weight interface implementation
func (sw1 *SingleWeight) Add(w Weight) {
	sw2 := w.(*SingleWeight)

	switch sw1.Value.(type) {
	case string:
		sw1.Value = sw1.Value.(string) + sw2.Value.(string)
	case uint, uint8, uint16, uint32, uint64:
		sw1.Value = reflect.ValueOf(sw1.Value).Uint() + reflect.ValueOf(sw2.Value).Uint()
	case int, int8, int16, int32, int64:
		sw1.Value = reflect.ValueOf(sw1.Value).Int() + reflect.ValueOf(sw2.Value).Int()
	case float32, float64:
		sw1.Value = reflect.ValueOf(sw1.Value).Float() + reflect.ValueOf(sw2.Value).Float()
	default:
		trace.Log("Not comparable type in SingleWeight.Value", sw1.Value)
	}
}