LightJason - AgentSpeak(L++)
IAgent.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.agent;
25 
26 import com.google.common.collect.ImmutableMultimap;
27 import com.google.common.collect.Multimap;
41 
42 import javax.annotation.Nonnegative;
43 import javax.annotation.Nonnull;
44 import javax.annotation.Nullable;
45 import java.io.Serializable;
46 import java.util.Arrays;
47 import java.util.Collections;
48 import java.util.Map;
49 import java.util.concurrent.Callable;
50 import java.util.stream.Stream;
51 
52 
58 public interface IAgent<T extends IAgent<?>> extends Serializable, Callable<T>
59 {
64  {
68  private static final long serialVersionUID = -3043602502559853983L;
69 
70  @Override
71  public final IAgent<?> call() throws Exception
72  {
73  return this;
74  }
75 
76  @Nonnull
77  @Override
78  @SafeVarargs
79  @SuppressWarnings( "varargs" )
80  public final <N extends IInspector> Stream<N> inspect( @Nonnull final N... p_inspector )
81  {
82  return Arrays.stream( p_inspector );
83  }
84 
85  @Nonnull
86  @Override
87  public final IFuzzyValue<Boolean> trigger( @Nonnull final ITrigger p_trigger, @Nullable final boolean... p_immediately )
88  {
89  return CFuzzyValue.from( true );
90  }
91 
92  @Nonnull
93  @Override
94  public final IView beliefbase()
95  {
96  return IView.EMPTY;
97  }
98 
99  @Nonnull
100  @Override
101  public final Multimap<IPath, ILiteral> runningplans()
102  {
103  return ImmutableMultimap.of();
104  }
105 
106  @Override
107  public final boolean sleeping()
108  {
109  return false;
110  }
111 
112  @Nonnull
113  @Override
114  public final IAgent<IAgent<?>> sleep( final long p_cycles, @Nullable final ITerm... p_term )
115  {
116  return this;
117  }
118 
119  @Nonnull
120  @Override
121  public final IAgent<IAgent<?>> sleep( final long p_cycles, @Nonnull final Stream<ITerm> p_term )
122  {
123  return this;
124  }
125 
126  @Nonnull
127  @Override
128  public final IAgent<IAgent<?>> wakeup( @Nullable final ITerm... p_term )
129  {
130  return this;
131  }
132 
133  @Nonnull
134  @Override
135  public final IAgent<IAgent<?>> wakeup( @Nonnull final Stream<ITerm> p_term )
136  {
137  return this;
138  }
139 
140  @Nonnull
141  @Override
142  public final Map<String, Object> storage()
143  {
144  return Collections.emptyMap();
145  }
146 
147  @Nonnull
148  @Override
149  public final IUnifier unifier()
150  {
151  return IUnifier.EMPTY;
152  }
153 
154  @Nonnegative
155  @Override
156  public final long cycletime()
157  {
158  return 0;
159  }
160 
161  @Nonnull
162  @Override
163  public final Multimap<ITrigger, IPlanStatistic> plans()
164  {
165  return ImmutableMultimap.of();
166  }
167 
168  @Nonnull
169  @Override
170  public final IFuzzyBundle<Boolean> fuzzy()
171  {
173  }
174 
175  @Nonnull
176  @Override
177  public final IVariableBuilder variablebuilder()
178  {
179  return IVariableBuilder.EMPTY;
180  }
181 
182  @Nonnull
183  @Override
184  public final Multimap<IPath, IRule> rules()
185  {
186  return ImmutableMultimap.of();
187  }
188 
189  @Nonnull
190  @Override
191  @SuppressWarnings( "unchecked" )
192  public final <N extends IAgent<?>> N raw()
193  {
194  return (N) this;
195  }
196 
197  @Override
198  public final int hashCode()
199  {
200  return 0;
201  }
202 
203  @Override
204  public final boolean equals( final Object p_object )
205  {
206  return ( p_object instanceof IAgent<?> ) && ( this.hashCode() == p_object.hashCode() );
207  }
208  };
209 
210 
217  @Nonnull
218  @SuppressWarnings( "unchecked" )
219  <N extends IInspector> Stream<N> inspect( @Nonnull final N... p_inspector );
220 
230  @Nonnull
231  IFuzzyValue<Boolean> trigger( @Nonnull final ITrigger p_trigger, @Nullable final boolean... p_immediately );
232 
238  @Nonnull
239  IView beliefbase();
240 
246  @Nonnull
247  Multimap<IPath, ILiteral> runningplans();
248 
254  boolean sleeping();
255 
263  @Nonnull
264  IAgent<T> sleep( final long p_cycles, @Nullable final ITerm... p_term );
265 
273  @Nonnull
274  IAgent<T> sleep( final long p_cycles, @Nonnull final Stream<ITerm> p_term );
275 
282  @Nonnull
283  IAgent<T> wakeup( @Nullable final ITerm... p_term );
284 
291  @Nonnull
292  IAgent<T> wakeup( @Nonnull final Stream<ITerm> p_term );
293 
294 
300  @Nonnull
301  Map<String, Object> storage();
302 
308  @Nonnull
309  IUnifier unifier();
310 
317  @Nonnegative
318  long cycletime();
319 
325  @Nonnull
326  Multimap<ITrigger, IPlanStatistic> plans();
327 
333  @Nonnull
335 
341  @Nonnull
343 
350  @Nonnull
351  Multimap<IPath, IRule> rules();
352 
359  @Nonnull
360  <N extends IAgent<?>> N raw();
361 
362 }
IAgent< T > wakeup( @Nullable final ITerm... p_term)
wake-up the agent by generating wakeup-goal
Multimap< ITrigger, IPlanStatistic > plans()
returns the internal map of plans
IVariableBuilder variablebuilder()
returns the variable builder function
IFuzzyBundle< Boolean > DEFAULTFUZZYBUNDLE
default fuzzy bundle
long cycletime()
returns the time in nano seconds at the last cycle
boolean sleeping()
returns sleeping state
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
Multimap< IPath, ILiteral > runningplans()
returns a map of the current running plans
< N extends IAgent<?> N raw()
cast the interface agent object to a specified agent object
Multimap< IPath, IRule > rules()
returns amultimap with literal-rule functor and rle objects
interface of an unification algorithm
Definition: IUnifier.java:43
view for a beliefbase that creates any access to the underlying data structures
Definition: IView.java:44
< N extends IInspector > Stream< N > inspect( @Nonnull final N... p_inspector)
inspector method
result for an immutable fuzzy value
Map< String, Object > storage()
storage access
interface for a variable builder which is called on each plan / rule execution
IAgent<?> EMPTY
empty agent
Definition: IAgent.java:63
IAgent< T > sleep(final long p_cycles, @Nullable final ITerm... p_term)
pushs the agent into sleeping state
IFuzzyValue< Boolean > trigger( @Nonnull final ITrigger p_trigger, @Nullable final boolean... p_immediately)
trigger an event
IView beliefbase()
returns the beliefbase
IUnifier unifier()
returns an unifier
IFuzzyBundle< Boolean > fuzzy()
return fuzzy operator
inspector interface to read agent internal data
Definition: IInspector.java:39