LightJason - AgentSpeak(L++)
CBeliefAction.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.action;
25 
32 
33 import javax.annotation.Nonnull;
34 import java.text.MessageFormat;
35 import java.util.List;
36 
37 
41 public final class CBeliefAction extends IBaseExecution<ILiteral>
42 {
46  private static final long serialVersionUID = -2856258502338708361L;
50  private final EAction m_action;
51 
58  public CBeliefAction( @Nonnull final ILiteral p_literal, @Nonnull final EAction p_action )
59  {
60  super( p_literal );
61  m_action = p_action;
62  }
63 
64  @Override
65  public final String toString()
66  {
67  return MessageFormat.format( "{0}{1}", m_action, m_value );
68  }
69 
70  @Nonnull
71  @Override
72  public final IFuzzyValue<Boolean> execute( final boolean p_parallel, @Nonnull final IContext p_context,
73  @Nonnull final List<ITerm> p_argument, @Nonnull final List<ITerm> p_return )
74  {
75  switch ( m_action )
76  {
77  case ADD:
78  p_context.agent().beliefbase().add( m_value.unify( p_context ) );
79  break;
80 
81  case DELETE:
82  p_context.agent().beliefbase().remove( m_value.unify( p_context ) );
83  break;
84 
85  default:
86  throw new IllegalArgumentException( CCommon.languagestring( this, "unknownaction", m_action ) );
87  }
88 
89  return CFuzzyValue.from( true );
90  }
91 
95  public enum EAction
96  {
97  ADD( "+" ),
98  DELETE( "-" );
102  private final String m_name;
103 
109  EAction( @Nonnull final String p_name )
110  {
111  m_name = p_name;
112  }
113 
114  @Override
115  public final String toString()
116  {
117  return m_name;
118  }
119  }
120 }
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)
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
CBeliefAction( @Nonnull final ILiteral p_literal, @Nonnull final EAction p_action)
ctor
static< T > String languagestring(final T p_source, final String p_label, final Object... p_parameter)
returns the language depend string on any object
execution context with local data
Definition: IContext.java:42
result for an immutable fuzzy value