func (it *KVIterator) Close() {
}
Close releases resources occupied by the iterator
package mocks
import (
	"sort"
	"strings"
	"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/statedb"
)
type StateDB struct {
	state             map[string]map[string][]byte
	queryResults      map[string][]*statedb.VersionedKV
	error             error
	queryError        error
	itProvider        func() *KVIterator
	bytesKeySupported bool
}
func NewStateDB() *StateDB {
	return &StateDB{
		state:        make(map[string]map[string][]byte),
		queryResults: make(map[string][]*statedb.VersionedKV),
		itProvider:   NewKVIterator,
	}
}
func (m *StateDB) WithState(ns, key string, value []byte) *StateDB {
	nsState, ok := m.state[ns]
	if !ok {
		nsState = make(map[string][]byte)
		m.state[ns] = nsState
	}
	nsState[key] = value
	return m
}
func (m *StateDB) WithPrivateState(ns, collection, key string, value []byte) *StateDB {
	nskey := privateNamespace(ns, collection)
	nsState, ok := m.state[nskey]
	if !ok {
		nsState = make(map[string][]byte)
		m.state[nskey] = nsState
	}
	nsState[key] = value
	return m
}
func (m *StateDB) WithDeletedState(ns, key string) *StateDB {
	nsState, ok := m.state[ns]
	if ok {
		delete(nsState, key)
	}
	return m
}
func (m *StateDB) WithDeletedPrivateState(ns, collection, key string) *StateDB {
	nsState, ok := m.state[privateNamespace(ns, collection)]
	if ok {
		delete(nsState, key)
	}
	return m
}
func (m *StateDB) WithQueryResults(ns, query string, results []*statedb.VersionedKV) *StateDB {
	m.queryResults[queryResultsKey(ns, query)] = results
	return m
}
func (m *StateDB) WithPrivateQueryResults(ns, coll, query string, results []*statedb.VersionedKV) *StateDB {
	m.queryResults[privateQueryResultsKey(ns, coll, query)] = results
	return m
}
func (m *StateDB) WithIteratorProvider(p func() *KVIterator) *StateDB {
	m.itProvider = p
	return m
}
func (m *StateDB) WithError(err error) *StateDB {
	m.error = err
	return m
}
func (m *StateDB) WithQueryError(err error) *StateDB {
	m.queryError = err
	return m
}
func (m *StateDB) GetState(namespace string, key string) ([]byte, error) {
	if m.error != nil {
		return nil, m.error
	}
	return m.state[namespace][key], nil
}
func (m *StateDB) GetStateMultipleKeys(namespace string, keys []string) ([][]byte, error) {
	values := make([][]byte, len(keys))
	for i, k := range keys {
		v, err := m.GetState(namespace, k)
		if err != nil {
			return nil, err
		}
		values[i] = v
	}
	return values, nil
}
func (m *StateDB) GetStateRangeScanIterator(namespace string, startKey string, endKey string) (statedb.ResultsIterator, error) {
	if m.queryError != nil {
		return nil, m.queryError
	}
	var kvs []*statedb.VersionedKV
	for key, value := range m.state[namespace] {
		if strings.Compare(key, startKey) < 0 || strings.Compare(key, endKey) >= 0 {
			continue
		}
		kvs = append(kvs, &statedb.VersionedKV{
			CompositeKey: statedb.CompositeKey{
				Namespace: namespace,
				Key:       key,
			},
			VersionedValue: statedb.VersionedValue{
				Value: value,
			},
		})
	}
	sort.Slice(kvs, func(i, j int) bool {
		return strings.Compare(kvs[i].Key, kvs[j].Key) < 0
	})
	return m.itProvider().WithResults(kvs...), nil
}
func (m *StateDB) GetStateRangeScanIteratorWithPagination(namespace string, startKey string, endKey string, pageSize int32) (statedb.QueryResultsIterator, error) {
	panic("not implemented")
}
func (m *StateDB) ExecuteQuery(namespace, query string) (statedb.ResultsIterator, error) {
	if m.queryError != nil {
		return nil, m.queryError
	}
	return m.itProvider().WithResults(m.queryResults[queryResultsKey(namespace, query)]...), m.error
}
func (m *StateDB) ExecuteQueryWithPagination(namespace, query, bookmark string, pageSize int32) (statedb.QueryResultsIterator, error) {
	panic("not implemented")
}
func (m *StateDB) BytesKeySupported() bool {
	return m.bytesKeySupported
}
func (m *StateDB) UpdateCache(uint64, []byte) error {
	return nil
}
func privateNamespace(namespace, collection string) string {
	return namespace + "$" + collection
}
func queryResultsKey(namespace, query string) string {
	return namespace + "~" + query
}
func privateQueryResultsKey(namespace, coll, query string) string {
	return privateNamespace(namespace, coll) + "~" + query
}
type KVIterator struct {
	kvs     []*statedb.VersionedKV
	nextIdx int
	err     error
}
func NewKVIterator() *KVIterator {
	return &KVIterator{}
}
func (it *KVIterator) WithResults(kv ...*statedb.VersionedKV) *KVIterator {
	it.kvs = append(it.kvs, kv...)
	return it
}
func (it *KVIterator) WithError(err error) *KVIterator {
	it.err = err
	return it
}
func (it *KVIterator) Next() (statedb.QueryResult, error) {
	if it.err != nil {
		return nil, it.err
	}
	if it.nextIdx >= len(it.kvs) {
		return nil, nil
	}
	qr := it.kvs[it.nextIdx]
	it.nextIdx++
	return qr, nil
}
func (it *KVIterator) GetBookmarkAndClose() string {
	panic("not implemented")
}