This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrow.go
123 lines (109 loc) · 2.25 KB
/
row.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2017 M. Shulhan <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file.
package tabula
//
// Row represent slice of record.
//
type Row []*Record
//
// Len return number of record in row.
//
func (row *Row) Len() int {
return len(*row)
}
//
// PushBack will add new record to the end of row.
//
func (row *Row) PushBack(r *Record) {
*row = append(*row, r)
}
//
// Types return type of all records.
//
func (row *Row) Types() (types []int) {
for _, r := range *row {
types = append(types, r.Type())
}
return
}
//
// Clone create and return a clone of row.
//
func (row *Row) Clone() *Row {
clone := make(Row, len(*row))
for x, rec := range *row {
clone[x] = rec.Clone()
}
return &clone
}
//
// IsNilAt return true if there is no record value in row at `idx`, otherwise
// return false.
//
func (row *Row) IsNilAt(idx int) bool {
if idx < 0 {
return true
}
if idx >= len(*row) {
return true
}
if (*row)[idx] == nil {
return true
}
return (*row)[idx].IsNil()
}
//
// SetValueAt will set the value of row at cell index `idx` with record `rec`.
//
func (row *Row) SetValueAt(idx int, rec *Record) {
(*row)[idx] = rec
}
//
// GetRecord will return pointer to record at index `i`, or nil if index
// is out of range.
//
func (row *Row) GetRecord(i int) *Record {
if i < 0 {
return nil
}
if i >= row.Len() {
return nil
}
return (*row)[i]
}
//
// GetValueAt return the value of row record at index `idx`. If the index is
// out of range it will return nil and false
//
func (row *Row) GetValueAt(idx int) (interface{}, bool) {
if row.Len() <= idx {
return nil, false
}
return (*row)[idx].Interface(), true
}
//
// GetIntAt return the integer value of row record at index `idx`.
// If the index is out of range it will return 0 and false.
//
func (row *Row) GetIntAt(idx int) (int64, bool) {
if row.Len() <= idx {
return 0, false
}
return (*row)[idx].Integer(), true
}
//
// IsEqual return true if row content equal with `other` row, otherwise return
// false.
//
func (row *Row) IsEqual(other *Row) bool {
if len(*row) != len(*other) {
return false
}
for x, xrec := range *row {
if !xrec.IsEqual((*other)[x]) {
return false
}
}
return true
}