LightJason - AgentSpeak(L++)
CCreateStatistic.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.action.builtin.math.statistic;
25 
26 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
27 import org.apache.commons.math3.stat.descriptive.StatisticalSummary;
28 import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
29 import org.apache.commons.math3.stat.descriptive.SynchronizedDescriptiveStatistics;
30 import org.apache.commons.math3.stat.descriptive.SynchronizedSummaryStatistics;
39 
40 import javax.annotation.Nonnull;
41 import java.util.List;
42 import java.util.Locale;
43 import java.util.stream.Stream;
44 
45 
56 public final class CCreateStatistic extends IBuiltinAction
57 {
61  private static final long serialVersionUID = -8275199738531829131L;
62 
67  {
68  super( 3 );
69  }
70 
71  @Nonnull
72  @Override
73  public final IFuzzyValue<Boolean> execute( final boolean p_parallel, @Nonnull final IContext p_context,
74  @Nonnull final List<ITerm> p_argument, @Nonnull final List<ITerm> p_return )
75  {
76 
77  (
78  p_argument.size() == 0
79  ? Stream.of( EType.SUMMARY )
80  : CCommon.flatten( p_argument ).map( ITerm::<String>raw ).map( EType::from )
81  ).map( i -> i.generate( p_parallel ) )
82  .map( CRawTerm::from ).forEach( p_return::add );
83 
84  return CFuzzyValue.from( true );
85  }
86 
87 
91  private enum EType
92  {
95 
102  @Nonnull
103  public static EType from( @Nonnull final String p_value )
104  {
105  return EType.valueOf( p_value.trim().toUpperCase( Locale.ROOT ) );
106  }
107 
114  @Nonnull
115  public final StatisticalSummary generate( @Nonnull final Boolean p_parallel )
116  {
117  switch ( this )
118  {
119  case SUMMARY:
120  return p_parallel
121  ? new SynchronizedSummaryStatistics()
122  : new SummaryStatistics();
123 
124  case DESCRIPTIVE:
125  return p_parallel
126  ? new SynchronizedDescriptiveStatistics()
127  : new DescriptiveStatistics();
128 
129  default:
130  throw new CIllegalStateException( org.lightjason.agentspeak.common.CCommon.languagestring( this, "unknown", this ) );
131  }
132  }
133  }
134 }
base class of build-in actions for setting name by package/classname (without prefix character) ...
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
final StatisticalSummary generate( @Nonnull final Boolean p_parallel)
returns the statistic object
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
static Stream< ITerm > flatten( @Nonnull final Collection<? extends ITerm > p_terms)
flat term-in-term collection into a straight term list
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
result for an immutable fuzzy value
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
Definition: CRawTerm.java:104
static EType from( @Nonnull final String p_value)
additional factory
term structure for simple datatypes
Definition: CRawTerm.java:45