util

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2022 License: Apache-2.0 Imports: 6 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBool added in v1.2.0

func DecodeBool(v interface{}) (bool, bool)

func DecodeInt added in v1.2.0

func DecodeInt(v interface{}, def int) (int, bool)

func DecodeString added in v1.2.0

func DecodeString(v interface{}, def string) string

func ForEachInterface added in v1.2.0

func ForEachInterface(v interface{}, f func(interface{}) error) error

ForEachInterface will invoke a function for every entry in v if v is a slice

func IfMap added in v1.2.0

func IfMap(v interface{}, f func(map[interface{}]interface{}) error) error

IfMap will invoke a function if v is a map

func IfMapEntry added in v1.2.0

func IfMapEntry(m map[interface{}]interface{}, n interface{}, f func(interface{}) error) error

IfMapEntry invokes a function if a map contains an entry

func IfMapEntryBool added in v1.2.0

func IfMapEntryBool(m map[interface{}]interface{}, n string) bool

func IfMapEntryInt added in v1.2.0

func IfMapEntryInt(m map[interface{}]interface{}, n string) int

func IfMapEntryString added in v1.2.0

func IfMapEntryString(m map[interface{}]interface{}, n string) string

Types

type Collection

type Collection interface {
	// Clear removes all entries from the set
	Clear()
	// IsEmpty returns true if the set is empty
	IsEmpty() bool
	// Size returns the size of the set
	Size() int
}

type Iterable

type Iterable interface {
	// ForEach calls a function for each entry in the collection.
	// WARNING: For synchronized sets the function is called from inside the lock so the set cannot be modified for the
	// duration of this call. See ForEachAsync
	ForEach(f func(interface{}))
	// ForEachAsync calls a function for each entry in the collection.
	// WARNING: This can be expensive as it calls Slice() first to get a copy of the set before iterating over the
	// entries. However, it does mean the set can be modified during the call.
	ForEachAsync(f func(interface{}))
	// ForEachFailFast calls a function for each entry in the collection.
	// WARNING: For synchronized sets the function is called from inside the lock so the set cannot be modified for the
	// duration of this call. See ForEachAsync
	ForEachFailFast(f func(interface{}) error) error
	Iterator() Iterator
	ReverseIterator() Iterator
}

type Iterator

type Iterator interface {
	Iterable
	HasNext() bool
	Next() interface{}
}

func NewIterator

func NewIterator(v ...interface{}) Iterator

type List

type List interface {
	Collection
	Iterable
	// Add an entry in the list
	Add(interface{}) bool
	// Add an entry at the specified position in the list
	AddIndex(int, interface{})
	// Contains returns true if the set contains the value
	Contains(interface{}) bool
	// Get returns the element at a specific index
	Get(int) interface{}
	// IndexOf returns the index of the first occurrence of the specified element or -1 if not present.
	IndexOf(interface{}) int
	// Remove removes the supplied entry
	Remove(interface{}) bool
	// RemoveIndex removes the entry at the specific index
	RemoveIndex(i int) bool
	// FindIndexOf returns the index of the first occurrence that matches the provided predicate
	FindIndexOf(Predicate) int
}

func NewList

func NewList() List

type LogStream added in v1.2.0

type LogStream struct {
	// contains filtered or unexported fields
}

func (*LogStream) Close added in v1.2.0

func (e *LogStream) Close() error

func (*LogStream) Flush added in v1.2.0

func (e *LogStream) Flush()

func (*LogStream) Write added in v1.2.0

func (e *LogStream) Write(p []byte) (int, error)

type Map

type Map interface {
	Collection
	// ContainsKey returns true if the map contains a key
	ContainsKey(k string) bool
	// Get returns a value from the map or nil if absent
	Get(k string) interface{}
	// Get returns a value from the map or nil if absent
	Get2(k string) (interface{}, bool)
	// Put sets a value into the map returning the existing entry or nil of absent
	Put(k string, v interface{}) interface{}
	// PutIfAbsent sets a value in the map if the key does not already exist.
	PutIfAbsent(k string, v interface{}) interface{}
	// Remove removes a key, returning the value present
	Remove(k string) interface{}
	// RemoveIfEquals removes a key if it's the same value.
	// Similar to java.util.Map.Remove(k,v)
	RemoveIfEquals(k string, v interface{}) bool
	// ReplaceIfEquals replaces a entry for a key if it's current value is the one specified
	// Similar to java.util.Map.replace(k,old,new)
	ReplaceIfEquals(k string, oldValue interface{}, newValue interface{}) bool
	// Replace replaces a entry for a key if it currently has a value.
	// Similar to java.util.Map.replace(k,v)
	Replace(k string, v interface{}) bool
	// ComputeIfAbsent a value if the specified key is not already associated with a value (or is mapped to nil).
	// The returned value will be the value in the map (or the new one inserted)
	ComputeIfAbsent(k string, f func(string) interface{}) interface{}
	// ComputeIfPresent will call a function if a value exists in the map.
	// The returned value from the function will be the new value for the key in the map
	// & will be the returned value from this call.
	ComputeIfPresent(k string, f func(string, interface{}) interface{}) interface{}
	// Compute will call a function with the current value in the map (will be nil if absent)
	// The returned value from the function will be the new value for the key in the map
	// & will be the returned value from this call.
	Compute(k string, f func(string, interface{}) interface{}) interface{}
	// Merge will ether use the supplied value as the new value if an entry does not exist (or is nil)
	// otherwise will use the supplied function to return the value to be set.
	// For example, in Java: map.merge(key, msg, String::concat) would set to msg if key was absent,
	// or the existing value with msg concatenated.
	Merge(k string, v interface{}, f func(interface{}, interface{}) interface{}) interface{}
	// ForEach will call a function for each key,value pair in the map.
	// WARNING: For synchronized maps the function will be called from within the lock so the supplied
	// function cannot modify the map. See ForEachAsync
	ForEach(f func(string, interface{}))
	// ForEachAsync will call a function for each key, value pair in the map.
	// Unlike ForEach this makes a copy of the key's internally then traverses it, calling the function
	// outside of any lock as long as the value exists at the time the function would be called.
	// This allows for the map to be modified whilst the ForEachAsync is iterating.
	// WARNING: This is expensive as it makes a copy of the keys into a slice
	ForEachAsync(f func(string, interface{}))
	// Keys returns a slice of all keys currently in the map. The entries in this slice is only guaranteed to be correct
	// for the moment the function was called. The map can be changed afterwards
	Keys() []string
	// ExecIfPresent will execute a function if a value exists in the map
	ExecIfPresent(k string, f func(interface{}))
}

Map is a go equivalent to the Java Map interface

func NewSyncMap

func NewSyncMap() Map

NewSyncMap creates a new Synchronous Map

type Predicate

type Predicate func(interface{}) bool

type PriorityEntry

type PriorityEntry struct {
	Priority int
	Element  interface{}
}

type PriorityQueue

type PriorityQueue struct {
	// contains filtered or unexported fields
}

func (*PriorityQueue) Add

func (p *PriorityQueue) Add(e interface{})

func (*PriorityQueue) AddPriority

func (p *PriorityQueue) AddPriority(priority int, e interface{})

func (*PriorityQueue) Drain

func (p *PriorityQueue) Drain(f func(interface{}) error) error

Drain will call a function for each entry in the PriorityQueue, removing the entry from the head of the queue.

func (*PriorityQueue) ForEach

func (p *PriorityQueue) ForEach(f func(interface{}) error) error

ForEach will call a function for each entry in the PriorityQueue. The Queue is not modified during this call.

func (*PriorityQueue) IsEmpty

func (p *PriorityQueue) IsEmpty() bool

func (*PriorityQueue) Pop

func (p *PriorityQueue) Pop() (interface{}, bool)

Pop removes the first entry from the queue.

type Queue

type Queue interface {
	Collection
	Iterable
	// Offer an entry to the queue. Returns true if the queue accepted the entry
	Offer(interface{}) bool
	// Poll removes the first entry in the queue or returns nil if empty
	Poll() interface{}
	// Peek returns the first entry like Poll() but does not remove the entry.
	Peek() interface{}
}

A queue is a slice which can have entries appended/removed from it. The type of queue, e.g. FIFO or LIFO is dependent on the implementation.

type Set

type Set interface {
	Collection
	Iterable
	// Add adds an entry to the set
	Add(interface{}) bool
	// AddAll adds all supplied values to the set
	AddAll(v ...interface{}) bool
	// Contains returns true if the set contains the value
	Contains(interface{}) bool
	// Remove removes the supplied entry
	Remove(interface{}) bool
	// Slice returns a slice containing a snapshot of all entries in the set
	Slice() []interface{}
}

Set is a go equivalent to the Java Set interface

func NewHashSet

func NewHashSet() Set

NewHashSet creates a new Set. This set is not synchronised

func NewSyncSet

func NewSyncSet() Set

NewSyncSet creates a new Synchronous Set

type SortedMap added in v1.2.0

type SortedMap map[string]interface{}

func NewSortedMap added in v1.2.0

func NewSortedMap() *SortedMap

func (*SortedMap) AddAll added in v1.2.0

func (m *SortedMap) AddAll(source map[string]interface{}) *SortedMap

AddAll will add all entries in the source map to this instance

func (*SortedMap) Decode added in v1.2.0

func (m *SortedMap) Decode(source interface{}) *SortedMap

Decode will add all entries in the source to this instance if it's a map. If not it does nothing.

func (*SortedMap) DecodeMap added in v1.2.0

func (m *SortedMap) DecodeMap(source map[interface{}]interface{}) *SortedMap

DecodeMap will add all entries in the source map to this instance.

func (*SortedMap) ForEach added in v1.2.0

func (m *SortedMap) ForEach(f func(string, interface{}) error) error

func (*SortedMap) Keys added in v1.2.0

func (m *SortedMap) Keys() strings.StringSlice

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL