LightJason - AgentSpeak(L++)
CProxyReturnExpression.java
Go to the documentation of this file.
1 /*
2  * @cond LICENSE
3  * ######################################################################################
4  * # LGPL License #
5  * # #
6  * # This file is part of the LightJason AgentSpeak(L++) #
7  * # Copyright (c) 2015-19, LightJason (info@lightjason.org) #
8  * # This program is free software: you can redistribute it and/or modify #
9  * # it under the terms of the GNU Lesser General Public License as #
10  * # published by the Free Software Foundation, either version 3 of the #
11  * # License, or (at your option) any later version. #
12  * # #
13  * # This program is distributed in the hope that it will be useful, #
14  * # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16  * # GNU Lesser General Public License for more details. #
17  * # #
18  * # You should have received a copy of the GNU Lesser General Public License #
19  * # along with this program. If not, see http://www.gnu.org/licenses/ #
20  * ######################################################################################
21  * @endcond
22  */
23 
24 package org.lightjason.agentspeak.language.execution.expression;
25 
32 
33 import javax.annotation.Nonnull;
34 import java.util.LinkedList;
35 import java.util.List;
36 import java.util.stream.Stream;
37 
38 
42 public final class CProxyReturnExpression<T extends IExecution> implements IExpression
43 {
47  private static final long serialVersionUID = 8081637540101991377L;
51  private final T m_execution;
52 
58  @Nonnull
59  public CProxyReturnExpression( final T p_execution )
60  {
61  m_execution = p_execution;
62  }
63 
64  @Nonnull
65  @Override
66  public final IFuzzyValue<Boolean> execute( final boolean p_parallel, @Nonnull final IContext p_context,
67  @Nonnull final List<ITerm> p_argument, @Nonnull final List<ITerm> p_return )
68  {
69  final List<ITerm> l_returnarguments = new LinkedList<>();
70  final IFuzzyValue<Boolean> l_return = m_execution.execute( p_parallel, p_context, p_argument, l_returnarguments );
71 
72  // compare returning arguments, on empty return execution result, otherwise return arguments
73  if ( l_returnarguments.isEmpty() )
74  p_return.add( CRawTerm.from( l_return.value() ) );
75  else
76  p_return.addAll( l_returnarguments );
77 
78  return l_return;
79  }
80 
81  @Nonnull
82  @Override
83  public final Stream<IVariable<?>> variables()
84  {
85  return m_execution.variables();
86  }
87 
88  @Override
89  public final int hashCode()
90  {
91  return m_execution.hashCode();
92  }
93 
94  @Override
95  public final boolean equals( final Object p_object )
96  {
97  return ( p_object instanceof IExpression ) && ( m_execution.equals( p_object ) );
98  }
99 
100  @Override
101  public final String toString()
102  {
103  return m_execution.toString();
104  }
105 
106 }
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
final Stream< IVariable<?> > variables()
returns a stream with all used variables
execution context with local data
Definition: IContext.java:42
result for an immutable fuzzy value
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
Definition: CRawTerm.java:104
term structure for simple datatypes
Definition: CRawTerm.java:45