github.com/whatap/golib@v0.0.22/util/list/AnyList.go (about) 1 package list 2 3 import ( 4 "math" 5 6 "github.com/whatap/golib/io" 7 "github.com/whatap/golib/lang/value" 8 "github.com/whatap/golib/util/compare" 9 ) 10 11 const ( 12 ANYLIST_DEFAULT_CAPACITY = 10 13 ANYLIST_MAX_SIZE = math.MaxInt32 - 8 14 15 ANYLIST_INT = 1 16 ANYLIST_LONG = 2 17 ANYLIST_FLOAT = 3 18 ANYLIST_DOUBLE = 4 19 ANYLIST_STRING = 5 20 ) 21 22 type AnyList interface { 23 GetType() byte 24 25 SetInt(i, v int) 26 SetFloat(i int, v float32) 27 SetLong(i int, v int64) 28 SetDouble(i int, v float64) 29 SetString(i int, v string) 30 31 AddInt(v int) 32 AddFloat(v float32) 33 AddLong(v int64) 34 AddDouble(v float64) 35 AddString(v string) 36 37 GetInt(i int) int 38 GetFloat(i int) float32 39 GetDouble(i int) float64 40 GetLong(i int) int64 41 GetString(i int) string 42 GetObject(i int) interface{} 43 GetValue(i int) value.Value 44 45 Write(out *io.DataOutputX) 46 Read(in *io.DataInputX) 47 48 Size() int 49 50 Sorting(asc bool) []int 51 SortingAnyList(asc bool, child AnyList, childAsc bool) []int 52 Filtering(index []int) AnyList 53 } 54 55 func CompareChild(child AnyList, ord bool, i1 int, i2 int) int { 56 if child.GetType() == ANYLIST_STRING { 57 if ord { 58 return compare.CompareToString(child.GetString(i1), child.GetString(i2)) 59 } else { 60 return compare.CompareToString(child.GetString(i2), child.GetString(i1)) 61 } 62 } else { 63 if ord { 64 return compare.CompareToDouble(child.GetDouble(i1), child.GetDouble(i2)) 65 } else { 66 return compare.CompareToDouble(child.GetDouble(i2), child.GetDouble(i1)) 67 } 68 } 69 }