LightJason - AgentSpeak(L++)
COperatorAssign.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.expressionbinary;
25 
32 
33 import javax.annotation.Nonnull;
34 import java.text.MessageFormat;
35 import java.util.List;
36 import java.util.stream.Stream;
37 
38 
42 public final class COperatorAssign implements IBinaryExpression
43 {
47  private static final long serialVersionUID = 720534461732785140L;
51  private final IVariable<?> m_lhs;
55  private final ITerm m_rhs;
59  private final EOperator m_operator;
60 
61 
69  public COperatorAssign( final IVariable<?> p_lhs, final ITerm p_rhs, final EOperator p_operator )
70  {
71  m_lhs = p_lhs;
72  m_operator = p_operator;
73  m_rhs = p_rhs;
74  }
75 
76  @Nonnull
77  @Override
78  public final IFuzzyValue<Boolean> execute( final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List<ITerm> p_argument,
79  @Nonnull final List<ITerm> p_return )
80  {
81  final IVariable<Number> l_lhs = CCommon.replaceFromContext( p_context, m_lhs ).term();
82  l_lhs.set( m_operator.apply( l_lhs.raw(), CCommon.replaceFromContext( p_context, m_rhs ).raw() ) );
83 
84  return CFuzzyValue.from( true );
85  }
86 
87  @Override
88  public final String toString()
89  {
90  return MessageFormat.format( "{0} {1} {2}", m_lhs, m_operator, m_rhs );
91  }
92 
93  @Nonnull
94  @Override
95  public final Stream<IVariable<?>> variables()
96  {
97  return Stream.concat(
98  Stream.of( m_lhs ),
99  m_rhs instanceof IVariable<?>
100  ? Stream.of( m_rhs.term() )
101  : Stream.empty()
102  );
103  }
104 }
IVariable< T > set( @Nullable final T p_value)
sets the value
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
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
final Stream< IVariable<?> > variables()
returns a stream with all used variables
final Number apply(final Number p_lhs, final Number p_rhs)
execution context with local data
Definition: IContext.java:42
COperatorAssign(final IVariable<?> p_lhs, final ITerm p_rhs, final EOperator p_operator)
ctor
default< T extends ITerm > T term()
casts the object to a term-type
Definition: ITerm.java:158
result for an immutable fuzzy value
< T > T raw()
cast to any raw value type