Merge pull request #2 from ClusterCockpit/make-access-public

Make all interface methods public
This commit is contained in:
Thomas Gruber 2023-05-04 16:55:38 +02:00 committed by GitHub
commit b1f37c852b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 17 deletions

View File

@ -17,10 +17,10 @@ type Unit interface {
String() string String() string
Short() string Short() string
AddUnitDenominator(div Measure) AddUnitDenominator(div Measure)
getPrefix() Prefix GetPrefix() Prefix
getMeasure() Measure GetMeasure() Measure
getUnitDenominator() Measure GetUnitDenominator() Measure
setPrefix(p Prefix) SetPrefix(p Prefix)
} }
var INVALID_UNIT = NewUnit("foobar") var INVALID_UNIT = NewUnit("foobar")
@ -55,19 +55,19 @@ func (u *unit) AddUnitDenominator(div Measure) {
u.divMeasure = div u.divMeasure = div
} }
func (u *unit) getPrefix() Prefix { func (u *unit) GetPrefix() Prefix {
return u.prefix return u.prefix
} }
func (u *unit) setPrefix(p Prefix) { func (u *unit) SetPrefix(p Prefix) {
u.prefix = p u.prefix = p
} }
func (u *unit) getMeasure() Measure { func (u *unit) GetMeasure() Measure {
return u.measure return u.measure
} }
func (u *unit) getUnitDenominator() Measure { func (u *unit) GetUnitDenominator() Measure {
return u.divMeasure return u.divMeasure
} }
@ -162,8 +162,8 @@ func GetPrefixStringPrefixStringFactor(in string, out string) func(value interfa
func GetUnitPrefixFactor(in Unit, out Prefix) (func(value interface{}) interface{}, Unit) { func GetUnitPrefixFactor(in Unit, out Prefix) (func(value interface{}) interface{}, Unit) {
outUnit := NewUnit(in.Short()) outUnit := NewUnit(in.Short())
if outUnit.Valid() { if outUnit.Valid() {
outUnit.setPrefix(out) outUnit.SetPrefix(out)
conv := GetPrefixPrefixFactor(in.getPrefix(), out) conv := GetPrefixPrefixFactor(in.GetPrefix(), out)
return conv, outUnit return conv, outUnit
} }
return nil, INVALID_UNIT return nil, INVALID_UNIT
@ -187,14 +187,14 @@ func GetUnitStringPrefixStringFactor(in string, out string) (func(value interfac
// It is basically a wrapper for GetPrefixPrefixFactor with some special cases for temperature // It is basically a wrapper for GetPrefixPrefixFactor with some special cases for temperature
// conversion between Fahrenheit and Celsius. // conversion between Fahrenheit and Celsius.
func GetUnitUnitFactor(in Unit, out Unit) (func(value interface{}) interface{}, error) { func GetUnitUnitFactor(in Unit, out Unit) (func(value interface{}) interface{}, error) {
if in.getMeasure() == TemperatureC && out.getMeasure() == TemperatureF { if in.GetMeasure() == TemperatureC && out.GetMeasure() == TemperatureF {
return convertTempC2TempF, nil return convertTempC2TempF, nil
} else if in.getMeasure() == TemperatureF && out.getMeasure() == TemperatureC { } else if in.GetMeasure() == TemperatureF && out.GetMeasure() == TemperatureC {
return convertTempF2TempC, nil return convertTempF2TempC, nil
} else if in.getMeasure() != out.getMeasure() || in.getUnitDenominator() != out.getUnitDenominator() { } else if in.GetMeasure() != out.GetMeasure() || in.GetUnitDenominator() != out.GetUnitDenominator() {
return func(value interface{}) interface{} { return 1.0 }, fmt.Errorf("invalid measures in in and out Unit") return func(value interface{}) interface{} { return 1.0 }, fmt.Errorf("invalid measures in in and out Unit")
} }
return GetPrefixPrefixFactor(in.getPrefix(), out.getPrefix()), nil return GetPrefixPrefixFactor(in.GetPrefix(), out.GetPrefix()), nil
} }
// NewUnit creates a new unit out of a string representing a unit like 'Mbyte/s' or 'GHz'. // NewUnit creates a new unit out of a string representing a unit like 'Mbyte/s' or 'GHz'.

View File

@ -67,7 +67,7 @@ func TestUnitsExact(t *testing.T) {
{"F/B", NewUnit("flops/Bytes")}, {"F/B", NewUnit("flops/Bytes")},
} }
compareUnitExact := func(in, out Unit) bool { compareUnitExact := func(in, out Unit) bool {
if in.getMeasure() == out.getMeasure() && in.getUnitDenominator() == out.getUnitDenominator() && in.getPrefix() == out.getPrefix() { if in.GetMeasure() == out.GetMeasure() && in.GetUnitDenominator() == out.GetUnitDenominator() && in.GetPrefix() == out.GetPrefix() {
return true return true
} }
return false return false
@ -99,8 +99,8 @@ func TestUnitUnitConversion(t *testing.T) {
{"mb", NewUnit("MBytes"), 1.0}, {"mb", NewUnit("MBytes"), 1.0},
} }
compareUnitWithPrefix := func(in, out Unit, factor float64) bool { compareUnitWithPrefix := func(in, out Unit, factor float64) bool {
if in.getMeasure() == out.getMeasure() && in.getUnitDenominator() == out.getUnitDenominator() { if in.GetMeasure() == out.GetMeasure() && in.GetUnitDenominator() == out.GetUnitDenominator() {
if f := GetPrefixPrefixFactor(in.getPrefix(), out.getPrefix()); f(1.0) == factor { if f := GetPrefixPrefixFactor(in.GetPrefix(), out.GetPrefix()); f(1.0) == factor {
return true return true
} else { } else {
fmt.Println(f(1.0)) fmt.Println(f(1.0))