LightJason - AgentSpeak(L++)
IBasePlanBundleGenerator.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.generator;
25 
26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
33 
34 import javax.annotation.Nonnull;
35 import javax.annotation.Nullable;
36 import java.io.InputStream;
37 import java.util.Objects;
38 import java.util.Set;
39 import java.util.stream.IntStream;
40 import java.util.stream.Stream;
41 
42 
46 @SuppressFBWarnings( "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" )
47 public abstract class IBasePlanBundleGenerator implements IPlanBundleGenerator
48 {
53 
54 
62  public IBasePlanBundleGenerator( @Nonnull final InputStream p_stream, @Nonnull final Set<IAction> p_actions ) throws Exception
63  {
64  final IASTVisitorPlanBundle l_visitor = new CParserPlanBundle( p_actions ).parse( p_stream );
65 
66  m_configuration = new CDefaultPlanBundleConfiguration(
67  l_visitor.plans(),
68  l_visitor.rules(),
69  l_visitor.initialbeliefs()
70  );
71  }
72 
78  protected IBasePlanBundleGenerator( @Nonnull final IPlanBundleConfiguration p_configuration )
79  {
80  m_configuration = p_configuration;
81  }
82 
83  @Nonnull
84  @Override
85  public final Stream<IPlanBundle> generatemultiple( final int p_number, @Nullable final Object... p_data )
86  {
87  return IntStream.range( 0, p_number )
88  .parallel()
89  .mapToObj( i -> this.generatesingle( p_data ) )
90  .filter( Objects::nonNull );
91  }
92 
93 }
final IASTVisitorPlanBundle parse(final InputStream p_stream)
final IPlanBundleConfiguration m_configuration
configuration
generator interface to generate plan bundles
external action interface
Definition: IAction.java:38
IBasePlanBundleGenerator( @Nonnull final InputStream p_stream, @Nonnull final Set< IAction > p_actions)
ctor
Set< IRule > rules()
returns the rules / principles
Set< IPlan > plans()
get a multimap with event-plan matching
Set< ILiteral > initialbeliefs()
returns initial beliefs
final Stream< IPlanBundle > generatemultiple(final int p_number, @Nullable final Object... p_data)
visitor interface of the abstract-syntax-tree (AST) for a plan bundle
IBasePlanBundleGenerator( @Nonnull final IPlanBundleConfiguration p_configuration)
ctor