24 package org.lightjason.agentspeak.beliefbase.storage;
26 import javax.annotation.Nonnull;
27 import java.text.MessageFormat;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.LinkedHashMap;
32 import java.util.concurrent.ConcurrentHashMap;
33 import java.util.stream.Collectors;
34 import java.util.stream.Stream;
52 private final Map<String, N>
m_multielements = Collections.synchronizedMap(
new LinkedHashMap<>() );
70 return m_multielements.values().stream();
77 return m_singleelements.values().stream();
83 return m_multielements.containsKey( p_key );
89 return m_singleelements.containsKey( p_key );
93 public final boolean putMultiElement( @Nonnull
final String p_key,
final N p_value )
95 return !p_value.equals( m_multielements.put( p_key, p_value ) );
101 return !p_value.equals( m_singleelements.put( p_key, p_value ) );
107 return !p_value.equals( m_singleelements.putIfAbsent( p_key, p_value ) );
113 return p_value.equals( m_multielements.remove( p_key ) );
119 return m_singleelements.remove( p_key ) != null;
125 return m_singleelements.get( p_key );
131 return m_singleelements.getOrDefault( p_key, p_default );
138 return Stream.of( m_multielements.get( p_key ) ).collect( Collectors.toSet() );
144 m_multielements.clear();
145 m_singleelements.clear();
151 return m_multielements.isEmpty() && m_singleelements.isEmpty();
157 return m_multielements.size();
164 return MessageFormat.format(
"[multi elements: {0}, single elements: {1}]", m_multielements, m_singleelements );
final Map< String, N > m_multielements
map with elements
final M getSingleElement( @Nonnull final String p_key)
returns a single-element by the name
final boolean putMultiElement( @Nonnull final String p_key, final N p_value)
puts a multi-element into the storage
final M getSingleElementOrDefault( @Nonnull final String p_key, final M p_default)
returns a single-element by the name
default structure of a storage
final boolean containsMultiElement( @Nonnull final String p_key)
contains a multi-element
final boolean putSingleElementIfAbsent( @Nonnull final String p_key, final M p_value)
puts a single-element if it is absent
final Stream< M > streamSingleElements()
returns a stream over all single-elements
final Collection< N > getMultiElement( @Nonnull final String p_key)
returns a collection of multi-elementy by name
final int size()
number of multi elements
final boolean containsSingleElement( @Nonnull final String p_key)
contains a single-element
final Stream< N > streamMultiElements()
returns a stream over all multi-elements
final boolean removeMultiElement( @Nonnull final String p_key, final N p_value)
removes a multi-element from the storage
final Map< String, M > m_singleelements
map with single elements
thread-safe storage of the data of single- and multi-elements, a multi-element can be stored once and...
final boolean removeSingleElement( @Nonnull final String p_key)
removes a single-element from the storage
final boolean empty()
checks if a storage is empty
final void clear()
clears all elements
final boolean putSingleElement( @Nonnull final String p_key, final M p_value)
puts a single-element into the storage