24 package org.lightjason.agentspeak.language.execution.action;
26 import org.apache.commons.lang3.StringUtils;
39 import javax.annotation.Nonnull;
40 import java.text.MessageFormat;
41 import java.util.Collection;
42 import java.util.Collections;
43 import java.util.LinkedList;
44 import java.util.List;
46 import java.util.Objects;
47 import java.util.stream.Collectors;
48 import java.util.stream.IntStream;
49 import java.util.stream.Stream;
80 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
83 return m_execution.
execute( p_parallel, p_context, p_argument, p_return );
96 return MessageFormat.format(
"{0}", m_execution );
107 private static final long serialVersionUID = 6984535096829821628L;
126 return m_value.hashCode();
132 return MessageFormat.format(
"{0}", m_value );
136 public final boolean equals(
final Object p_object )
138 return ( p_object instanceof
IExecution ) && ( this.
hashCode() == p_object.hashCode() );
144 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
147 p_return.add( m_value );
181 private static final long serialVersionUID = 5531271525053969711L;
206 m_parallel = p_literal.hasAt();
210 m_action = p_actions.get( p_literal.fqnfunctor() );
211 if ( Objects.isNull( m_action ) )
220 m_arguments = Collections.unmodifiableMap( this.createSubExecutions( p_literal.orderedvalues().collect( Collectors.toList() ), p_actions ) );
226 return m_action.hashCode() + m_arguments.hashCode();
232 return MessageFormat.format(
"{0}({1})", m_action, StringUtils.join( m_arguments.values(),
", " ) );
236 public final boolean equals(
final Object p_object )
238 return ( p_object instanceof
IExecution ) && ( this.
hashCode() == p_object.hashCode() );
244 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
248 m_parallel, p_context,
249 this.subexecute( p_context, m_arguments ),
269 private Map<Integer, IExecution>
createSubExecutions( @Nonnull
final Collection<? extends ITerm> p_elements,
270 @Nonnull
final Map<IPath, IAction> p_actions )
273 final List<? extends ITerm> l_elements =
new LinkedList<>( p_elements );
274 return IntStream.range( 0, l_elements.size() )
281 final ITerm l_term = l_elements.get( i );
282 return l_term instanceof ILiteral
283 ? new CActionWrapper( l_term.term(), p_actions )
284 : new CTermWrapper<>( l_term );
298 private List<ITerm>
subexecute( @Nonnull
final IContext p_context, @Nonnull
final Map<Integer, IExecution> p_execution )
300 return Collections.unmodifiableList(
CCommon.replaceFromContext(
303 ? p_execution.entrySet().parallelStream()
304 : p_execution.entrySet()
308 final List<ITerm> l_return =
new LinkedList<>();
309 i.getValue().execute( m_parallel, p_context, Collections.emptyList(), l_return );
310 return l_return.stream();
312 .collect( Collectors.toList() )
final Stream< IVariable<?> > variables()
returns a stream with all used variables
final Map< Integer, IExecution > m_arguments
arguments as map with index for prevent result order on parallel execution
static final long serialVersionUID
serial id
proxy action to encapsulate all actions
final T m_value
term value
IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
Stream< IVariable<?> > getVariableSet(final T p_value)
returns a variable set based on the generic type
inner class for encapsulating action execution
Stream< IVariable<?> > variables()
returns a stream with all used variables
illegal argument exception
internal execution interface
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
common structure for execution definition
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
final IExecution m_execution
execution
final boolean equals(final Object p_object)
default Stream< IVariable<?> > variables()
returns a stream with all used variables
execution context with local data
external action interface
final boolean m_parallel
parallel execution flag
final Stream< IVariable<?> > variables()
returns a stream with all used variables
final IAction m_action
action
CActionWrapper( @Nonnull final ILiteral p_literal, @Nonnull final Map< IPath, IAction > p_actions)
ctor
CProxyAction( @Nonnull final Map< IPath, IAction > p_actions, @Nonnull final ILiteral p_literal)
ctor
result for an immutable fuzzy value
default int minimalArgumentNumber()
minimum number of arguments
Map< Integer, IExecution > createSubExecutions( @Nonnull final Collection<? extends ITerm > p_elements, @Nonnull final Map< IPath, IAction > p_actions)
builds the map of execution arguments
CTermWrapper( @Nonnull final T p_value)
ctor
final boolean equals(final Object p_object)
class for any helper calls
final Stream< IVariable<?> > variables()
returns a stream with all used variables
inner class for encapsulating term values (variable / raw terms)
IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
List< ITerm > subexecute( @Nonnull final IContext p_context, @Nonnull final Map< Integer, IExecution > p_execution)
execute inner structures