LightJason - AgentSpeak(L++)
action/builtin/storage/IStorage.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.storage;
25 
27 
28 import javax.annotation.Nonnull;
29 import javax.annotation.Nullable;
30 import java.util.Arrays;
31 import java.util.Objects;
32 import java.util.Set;
33 import java.util.concurrent.ConcurrentSkipListSet;
34 import java.util.function.Function;
35 import java.util.stream.Collectors;
36 import java.util.stream.Stream;
37 
38 
42 public abstract class IStorage extends IBuiltinAction
43 {
47  private static final long serialVersionUID = -2187242564778364709L;
51  protected final Function<String, Boolean> m_resolver;
52 
56  protected IStorage()
57  {
58  this( i -> false );
59  }
60 
67  protected IStorage( @Nonnull final Function<String, Boolean> p_resolver )
68  {
69  m_resolver = p_resolver;
70  }
71 
77  protected IStorage( @Nullable final String... p_forbidden )
78  {
79  this(
80  ( Objects.isNull( p_forbidden ) ) || ( p_forbidden.length == 0 )
81  ? Stream.empty()
82  : Arrays.stream( p_forbidden )
83  );
84  }
85 
91  protected IStorage( @Nonnull final Stream<String> p_fordbidden )
92  {
93  final Set<String> l_names = p_fordbidden.collect( Collectors.toCollection( ConcurrentSkipListSet::new ) );
94  m_resolver = l_names::contains;
95  }
96 
103  @Nonnull
104  public final Stream<Boolean> forbiddenkeys( @Nonnull final Stream<String> p_keys )
105  {
106  return p_keys.map( m_resolver );
107  }
108 
115  @Nonnull
116  public final Stream<Boolean> forbiddenkeys( @Nonnull final String... p_keys )
117  {
118  return this.forbiddenkeys( Arrays.stream( p_keys ) );
119  }
120 
121 }
base class of build-in actions for setting name by package/classname (without prefix character) ...
final Stream< Boolean > forbiddenkeys( @Nonnull final Stream< String > p_keys)
returns a stream which keys are forbidden
final Function< String, Boolean > m_resolver
set with forbidden keys
IStorage( @Nonnull final Function< String, Boolean > p_resolver)
ctor
final Stream< Boolean > forbiddenkeys( @Nonnull final String... p_keys)
returns a stream which keys are forbidden
IStorage( @Nonnull final Stream< String > p_fordbidden)
ctor