Skip to content

Commit bc63af1

Browse files
authored
[type:fix] fix code comment (#100)
1 parent 586722f commit bc63af1

File tree

14 files changed

+320
-337
lines changed

14 files changed

+320
-337
lines changed

array/array.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ package array
1919

2020
type any = interface{}
2121

22-
// NotEmpty array
22+
// NotEmpty judge array is not empty
23+
// @param arr array
24+
// @return bool not empty => true, empty => false
2325
func NotEmpty(arr ...any) bool {
2426
return !Empty(arr)
2527
}
2628

27-
// Empty array
29+
// Empty judge array is empty
30+
// @param arr array
31+
// @return bool empty => true, not empty => false
2832
func Empty(arr ...any) bool {
2933
return arr == nil || len(arr) == 0
3034
}

assert/assert.go

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
"testing"
2525
)
2626

27-
/*
28-
* Judge whether the value is nil
29-
* args Error prompt content
30-
*/
27+
// IsNull Judge whether the value is nil
28+
// @param t test
29+
// @param got want type
30+
// @param args error prompt content
3131
func IsNull(t *testing.T, got interface{}, args ...interface{}) {
3232
fn := func() {
3333
t.Errorf("! isNull")
@@ -39,38 +39,36 @@ func IsNull(t *testing.T, got interface{}, args ...interface{}) {
3939
assert(t, result, fn, 2)
4040
}
4141

42-
/*
43-
* Judge whether the value is true
44-
* args Error prompt content
45-
*/
42+
// IsTrue Judge whether the value is true
43+
// @param t test
44+
// @param result true
45+
// @param args error prompt content
4646
func IsTrue(t *testing.T, result bool, args ...interface{}) {
4747
tt(t, result, 1, args...)
4848
}
4949

50-
/*
51-
* Judge whether the value is false
52-
* args Error prompt content
53-
*/
50+
// IsFalse Judge whether the value is false
51+
// @param t test
52+
// @param result false
53+
// @param args error prompt content
5454
func IsFalse(t *testing.T, result bool, args ...interface{}) {
5555
tt(t, !result, 1, args...)
5656
}
5757

58-
/*
59-
* Judge whether the values are not equal
60-
* exp Comparison value
61-
* got Compared value
62-
* args Error prompt content
63-
*/
58+
// Equal Judge whether the values are not equal
59+
// @param t test
60+
// @param exp expect result
61+
// @param got compared value
62+
// @param args error prompt content
6463
func Equal(t *testing.T, exp, got interface{}, args ...interface{}) {
6564
equal(t, exp, got, 1, args...)
6665
}
6766

68-
/*
69-
* Judge whether the values are equal
70-
* exp Comparison value
71-
* got Compared value
72-
* args Error prompt content
73-
*/
67+
// NotEqual Judge whether the values are equal
68+
// @param t test
69+
// @param exp expect result
70+
// @param got compared value
71+
// @param args error prompt content
7472
func NotEqual(t *testing.T, exp, got interface{}, args ...interface{}) {
7573
fn := func() {
7674
t.Errorf("! Unexpected: <%#v>", exp)
@@ -82,6 +80,11 @@ func NotEqual(t *testing.T, exp, got interface{}, args ...interface{}) {
8280
assert(t, result, fn, 1)
8381
}
8482

83+
// assert assertion
84+
// @param t test
85+
// @param result result
86+
// @param f function
87+
// @param cd hierarchy
8588
func assert(t *testing.T, result bool, f func(), cd int) {
8689
if !result {
8790
_, file, line, _ := runtime.Caller(cd + 1)
@@ -91,6 +94,12 @@ func assert(t *testing.T, result bool, f func(), cd int) {
9194
}
9295
}
9396

97+
// equal judge equal
98+
// @param t test
99+
// @param exp expect result
100+
// @param got compared value
101+
// @param cd hierarchy
102+
// @param args error prompt content
94103
func equal(t *testing.T, exp, got interface{}, cd int, args ...interface{}) {
95104
fn := func() {
96105
t.Errorf("! Error unlike")
@@ -102,6 +111,11 @@ func equal(t *testing.T, exp, got interface{}, cd int, args ...interface{}) {
102111
assert(t, result, fn, cd+1)
103112
}
104113

114+
// tt test equal
115+
// @param t test
116+
// @param result wanted result
117+
// @param cd hierarchy
118+
// @param args error prompt content
105119
func tt(t *testing.T, result bool, cd int, args ...interface{}) {
106120
fn := func() {
107121
t.Errorf("! Failure")

gox/bytesx/bytesx.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@
1818
package bytesx
1919

2020
// SetAll set all bytes of the slice to value
21+
// SetAll set all bytes of the slice to value
22+
// @param b byte array
23+
// @param v param
2124
func SetAll(b []byte, v byte) {
2225
for i := 0; i < len(b); i++ {
2326
b[i] = v
2427
}
2528
}
2629

2730
// ZeroAll set all bytes of the slice to 0
31+
// @param b byte array
2832
func ZeroAll(b []byte) {
2933
SetAll(b, 0)
3034
}
3135

3236
// FromUint16LE convert uint16 to []byte in little endian
37+
// @param v param
38+
// @return []byte result
3339
func FromUint16LE(v uint16) []byte {
3440
return []byte{
3541
byte(v),

gox/containerx/listx/array_list.go

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,28 @@ const defaultArraylistSize = 10
2828

2929
// Arraylist array lst
3030
type Arraylist struct {
31-
elements []any
31+
elements []Any
3232
size int
3333
}
3434

35-
// New an array list
36-
func New(element ...any) *Arraylist {
35+
// New create an array list
36+
// @param element array element
37+
// @return *Arraylist
38+
func New(element ...Any) *Arraylist {
3739
lst := &Arraylist{}
38-
lst.elements = make([]any, defaultArraylistSize)
40+
lst.elements = make([]Any, defaultArraylistSize)
3941
if len(element) > 0 {
4042
lst.Add(element...)
4143
}
4244
return lst
4345
}
4446

45-
// Add element to array list
46-
func (lst *Arraylist) Add(element ...any) {
47+
// Add save element to array list
48+
// @receiver lst lst
49+
// @param element array element
50+
func (lst *Arraylist) Add(element ...Any) {
4751
if lst.size+len(element) >= len(lst.elements)-1 {
48-
newElements := make([]any, lst.size+len(element)+1)
52+
newElements := make([]Any, lst.size+len(element)+1)
4953
copy(newElements, lst.elements)
5054
lst.elements = newElements
5155
}
@@ -57,7 +61,11 @@ func (lst *Arraylist) Add(element ...any) {
5761
}
5862

5963
// RemoveAtIndex from array list at index
60-
func (lst *Arraylist) RemoveAtIndex(index int) any {
64+
// RemoveAtIndex remove from array list at index
65+
// @receiver lst lst
66+
// @param index array index
67+
// @return any
68+
func (lst *Arraylist) RemoveAtIndex(index int) Any {
6169
if index < 0 || index >= lst.size {
6270
return nil
6371
}
@@ -69,41 +77,63 @@ func (lst *Arraylist) RemoveAtIndex(index int) any {
6977
return current
7078
}
7179

72-
// Remove from array list
73-
func (lst *Arraylist) Remove(element any) bool {
80+
// Remove delete from array list
81+
// @receiver lst
82+
// @param element element
83+
// @return bool true or false
84+
func (lst *Arraylist) Remove(element Any) bool {
7485
return reflect.DeepEqual(lst.RemoveAtIndex(lst.IndexOf(element)), element)
7586
}
7687

77-
// Get element from array list at index
78-
func (lst *Arraylist) Get(index int) any {
88+
// Get get element from array list at index
89+
// @receiver lst
90+
// @param index element index
91+
// @return Any current result
92+
func (lst *Arraylist) Get(index int) Any {
7993
if index < 0 || index >= lst.size {
8094
return nil
8195
}
8296
return lst.elements[index]
8397
}
8498

85-
// IndexOf element from array list
86-
func (lst *Arraylist) IndexOf(element any) int {
99+
// IndexOf index element from array list
100+
// @receiver lst
101+
// @param element element
102+
// @return int current element index
103+
func (lst *Arraylist) IndexOf(element Any) int {
87104
_, index := lst.find(element)
88105
return index
89106
}
90107

91-
// Empty array list
108+
// Empty judge array is empty
109+
// @receiver lst
110+
// @return bool true => empty, false => not empty
92111
func (lst *Arraylist) Empty() bool {
93112
return lst == nil || lst.Size() == 0 || array.Empty(lst.elements)
94113
}
95114

96-
// Size of array list
115+
// Size calc array length
116+
// @receiver lst
117+
// @return int array length
97118
func (lst *Arraylist) Size() int {
98119
return lst.size
99120
}
100121

101-
// Contains element at array list or not
102-
func (lst *Arraylist) Contains(element any) (bool, int) {
122+
// Contains judge array exist element, and return exist result and index
123+
// @receiver lst
124+
// @param element element
125+
// @return bool exist result
126+
// @return int index
127+
func (lst *Arraylist) Contains(element Any) (bool, int) {
103128
return lst.find(element)
104129
}
105130

106-
func (lst *Arraylist) find(element any) (bool, int) {
131+
// find query element in array, and return exist and index
132+
// @receiver lst
133+
// @param element element
134+
// @return bool true => exist, false => not exist
135+
// @return int current element index
136+
func (lst *Arraylist) find(element Any) (bool, int) {
107137
for idx, current := range lst.elements {
108138
if current == element {
109139
return true, idx

0 commit comments

Comments
 (0)