2022-03-23 10:15:18 +08:00
|
|
|
package lang
|
|
|
|
|
|
|
|
import "strconv"
|
|
|
|
|
|
|
|
type Int8 int8
|
|
|
|
|
2022-04-23 11:30:34 +08:00
|
|
|
type AsInt8 interface {
|
|
|
|
Object
|
|
|
|
AsInt8() Int8
|
|
|
|
}
|
|
|
|
|
|
|
|
func CastInt8(v any) (int8, bool) {
|
|
|
|
switch i := v.(type) {
|
|
|
|
case int8:
|
|
|
|
return i, true
|
|
|
|
case AsInt8:
|
|
|
|
return i.AsInt8().V(), true
|
|
|
|
default:
|
|
|
|
return 0, false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func EqualsInt8(i1 AsInt8, i2 any) bool {
|
|
|
|
i2, ok := CastInt8(i2)
|
|
|
|
return ok && i2 == i1.AsInt8().V()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i Int8) V() int8 {
|
2022-03-23 10:15:18 +08:00
|
|
|
return int8(i)
|
|
|
|
}
|
|
|
|
|
2022-04-23 11:30:34 +08:00
|
|
|
func (i *Int8) P() *int8 {
|
|
|
|
return (*int8)(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i Int8) AsInt8() Int8 {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:15:18 +08:00
|
|
|
func (i Int8) String() string {
|
|
|
|
return strconv.FormatInt(int64(i), 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i Int8) AsObject() Object {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i Int8) Equals(e Object) bool {
|
2022-04-23 11:30:34 +08:00
|
|
|
return EqualsInt8(i, e)
|
2022-03-23 10:15:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i Int8) ToString() String {
|
|
|
|
return NewString(i.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i Int8) HashCode() int32 {
|
|
|
|
return int32(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i Int8) Compare(t Int8) int {
|
|
|
|
switch {
|
|
|
|
case i > t:
|
|
|
|
return 1
|
|
|
|
case i == t:
|
|
|
|
return 0
|
|
|
|
default:
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|