mirror of
https://github.com/tursom/GoCollections.git
synced 2025-03-15 10:10:13 +08:00
64 lines
938 B
Go
64 lines
938 B
Go
/*
|
|
* Copyright (c) 2022 tursom. All rights reserved.
|
|
* Use of this source code is governed by a GPL-3
|
|
* license that can be found in the LICENSE file.
|
|
*/
|
|
|
|
package lang
|
|
|
|
type String struct {
|
|
string
|
|
hashCode int32
|
|
}
|
|
|
|
func NewString(str string) String {
|
|
return String{string: str}
|
|
}
|
|
|
|
func (i String) AsString() string {
|
|
return i.string
|
|
}
|
|
|
|
func (i String) GoString() string {
|
|
return i.string
|
|
}
|
|
|
|
func (i String) String() string {
|
|
return i.string
|
|
}
|
|
|
|
func (i String) AsObject() Object {
|
|
return i
|
|
}
|
|
|
|
func (i String) Equals(e Object) bool {
|
|
i2, ok := e.(String)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return i == i2
|
|
}
|
|
|
|
func (i String) ToString() String {
|
|
return i
|
|
}
|
|
|
|
func (i String) HashCode() int32 {
|
|
if i.hashCode != 0 {
|
|
return i.hashCode
|
|
}
|
|
i.hashCode = HashString(i.string)
|
|
return i.hashCode
|
|
}
|
|
|
|
func (i String) Compare(t String) int {
|
|
switch {
|
|
case i.string > t.string:
|
|
return 1
|
|
case i == t:
|
|
return 0
|
|
default:
|
|
return -1
|
|
}
|
|
}
|