24 package org.lightjason.agentspeak.beliefbase.view;
35 import javax.annotation.Nonnull;
36 import javax.annotation.Nullable;
37 import java.text.MessageFormat;
38 import java.util.Arrays;
39 import java.util.Objects;
40 import java.util.stream.Stream;
73 this( p_name, p_beliefbase, null );
83 @SuppressWarnings(
"unchecked" )
86 if ( p_name.isEmpty() )
90 m_beliefbase = p_beliefbase;
123 public final IView add( @Nonnull
final Stream<ILiteral> p_literal )
134 return this.
add( Arrays.stream( p_literal ) );
139 @SuppressWarnings(
"varargs" )
147 .filter( j -> i.beliefbase().equals( this.
beliefbase() ) )
160 @SuppressWarnings(
"varargs" )
163 Arrays.
stream( p_view ).forEach( m_beliefbase::remove );
169 public final IView remove( @Nonnull
final Stream<ILiteral> p_literal )
180 return this.
remove( Arrays.stream( p_literal ) );
187 if ( ( Objects.isNull( p_path ) ) || ( p_path.length == 0 ) )
190 Arrays.stream( p_path ).parallel()
199 return !p_path.empty()
200 && ( p_path.size() == 1
202 : this.
leafview( this.
walk( p_path.subpath( 0, p_path.size() - 1 ) ) )
203 .
containsView( p_path.subpath( p_path.size() - 1, p_path.size() ) )
210 return !p_path.empty()
211 || ( p_path.size() == 1
213 : this.
leafview( this.
walk( p_path.subpath( 0, p_path.size() - 1 ) ) )
227 public final Stream<ILiteral>
stream( @Nullable
final IPath... p_path )
231 return ( ( Objects.isNull( p_path ) ) || ( p_path.length == 0 )
233 : Arrays.stream( p_path )
235 ).map( i -> i.shallowcopy( l_path ) );
240 public final Stream<ILiteral>
stream(
final boolean p_negated, @Nullable
final IPath... p_path )
244 return ( ( Objects.isNull( p_path ) ) || ( p_path.length == 0 )
249 : Arrays.stream( p_path )
251 .filter( j -> j.negated() == p_negated )
252 ).map( i -> i.shallowcopy( l_path ) );
259 return this.
walkdown( p_path, p_generator );
268 .forEach( i -> this.
walk( i, p_generator ) );
279 @SuppressWarnings(
"varargs" )
282 if ( p_path.empty() )
283 return Stream.of(
this );
286 final String l_root = p_path.get( 0 );
288 synchronized ( this )
294 Objects.isNull( p_generator ) || p_generator.length == 0
296 : p_generator[0].apply( l_root,
this )
299 if ( Objects.isNull( l_view ) )
300 return Stream.
empty();
304 return Stream.concat(
306 l_view.
walk( p_path.subpath( 1 ), p_generator )
320 .reduce( ( i, j ) -> j )
351 public final Stream<IView>
root()
354 ? Stream.concat( Stream.of(
this ), Stream.of( this.
parent() ).flatMap(
IView::root ) )
392 public final boolean equals(
final Object p_object )
394 return ( p_object instanceof
IView ) && ( this.
hashCode() == p_object.hashCode() );
400 return MessageFormat.format(
"{0} ({1}): [{2}]", this.
name(), super.toString(),
m_beliefbase );
Stream< IView > streamView()
returns a stream over all views
final IBeliefbase m_beliefbase
reference to the beliefbase context
final Stream< ITrigger > trigger()
retruns all trigger of the beliefbase
final Stream< ILiteral > stream(final boolean p_negated, @Nullable final IPath... p_path)
returns stream of literal
final Stream< IView > walk( @Nonnull final IPath p_path, @Nullable final IViewGenerator... p_generator)
streams path walking
IBeliefbase clear()
clears all elements
illegal argument exception
IAgent<?> update( @Nonnull final IAgent<?> p_agent)
updates all items
ILiteral add( @Nonnull final ILiteral p_literal)
adds a literal
CView( @Nonnull final String p_name, @Nonnull final IBeliefbase p_beliefbase)
ctor
final boolean containsView( @Nonnull final IPath p_path)
view existing check
final int size()
returns the size of literals
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
Stream< ILiteral > stream( @Nullable final IPath... p_path)
returns stream of literal
class to create a path structure
final boolean empty()
checks if the structure empty
IView leafview( @Nonnull final Stream< IView > p_stream)
returns the leaf of a view path
final IView generate( @Nonnull final IViewGenerator p_generator, @Nonnull final IPath... p_paths)
generates path structure
boolean empty()
checks if the structure empty
final IView m_parent
parent name
IBeliefbase beliefbase()
returns the beliefbase
view for a beliefbase that creates any access to the underlying data structures
Stream< ITrigger > trigger( @Nonnull final IView p_view)
returns all trigger of the beliefbase
final String m_name
view name
final IView remove( @Nonnull final IView... p_view)
removes a view in the current structure
boolean containsLiteral( @Nonnull final String p_key)
contains a multi-element
final IView parent()
returns the parent of the view
final IPath path()
returns the full path
IView viewOrDefault( @Nonnull final String p_key, @Nullable final IView p_default)
returns a view element
Stream< IView > walkdown( @Nonnull final IPath p_path, @Nullable final IViewGenerator... p_generator)
inner walking structure of views
final IAgent<?> update( @Nonnull final IAgent<?> p_agent)
updates all items
interface of beliefbase definition, that create the trigger events for the agent
String name()
returns only the element name
final IBeliefbase beliefbase()
returns the beliefbase
ILiteral remove( @Nonnull final ILiteral p_literal)
removes a literal
final Stream< IView > root()
returns a stream to the root node,
final boolean hasParent()
check if the view has got a parent
Stream< IView > root()
returns a stream to the root node,
Collection< ILiteral > literal( @Nonnull final String p_key)
returns a literal by the name
interface for generating non-existing beliefbases views
final IView add( @Nonnull final Stream< ILiteral > p_literal)
adds a literal in the current structure
Stream< ILiteral > streamLiteral()
returns a stream over all literals
class for any helper calls
final IView add( @Nonnull final ILiteral... p_literal)
adds a literal in the current structure
Stream< IView > walk( @Nonnull final IPath p_path, @Nullable final IViewGenerator... p_generator)
streams path walking
int size()
returns the size of literals
final boolean containsLiteral( @Nonnull final IPath p_path)
checks if a literal exists
final String name()
returns only the element name
IPath remove(final int p_index)
removes an element
boolean containsView( @Nonnull final String p_key)
contains a single-element
static Collector< String, IPath, IPath > collect()
returns a collector to build a path from strings
final boolean equals(final Object p_object)
final IView clear( @Nullable final IPath... p_path)
clears all elements
final Stream< ILiteral > stream( @Nullable final IPath... p_path)
returns stream of literal