blob: 64cd8e7c0c4ff5488cd18305f627a3719a829f0f [file] [log] [blame]
Matteo Scandoloa4285862020-12-01 18:10:10 -08001/*
2Copyright 2019 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package value
18
19type listUnstructured []interface{}
20
21func (l listUnstructured) Length() int {
22 return len(l)
23}
24
25func (l listUnstructured) At(i int) Value {
26 return NewValueInterface(l[i])
27}
28
29func (l listUnstructured) AtUsing(a Allocator, i int) Value {
30 return a.allocValueUnstructured().reuse(l[i])
31}
32
33func (l listUnstructured) Equals(other List) bool {
34 return l.EqualsUsing(HeapAllocator, other)
35}
36
37func (l listUnstructured) EqualsUsing(a Allocator, other List) bool {
38 return ListEqualsUsing(a, &l, other)
39}
40
41func (l listUnstructured) Range() ListRange {
42 return l.RangeUsing(HeapAllocator)
43}
44
45func (l listUnstructured) RangeUsing(a Allocator) ListRange {
46 if len(l) == 0 {
47 return EmptyRange
48 }
49 r := a.allocListUnstructuredRange()
50 r.list = l
51 r.i = -1
52 return r
53}
54
55type listUnstructuredRange struct {
56 list listUnstructured
57 vv *valueUnstructured
58 i int
59}
60
61func (r *listUnstructuredRange) Next() bool {
62 r.i += 1
63 return r.i < len(r.list)
64}
65
66func (r *listUnstructuredRange) Item() (index int, value Value) {
67 if r.i < 0 {
68 panic("Item() called before first calling Next()")
69 }
70 if r.i >= len(r.list) {
71 panic("Item() called on ListRange with no more items")
72 }
73 return r.i, r.vv.reuse(r.list[r.i])
74}