24 package org.lightjason.agentspeak.action.builtin;
27 import com.google.common.collect.HashMultimap;
28 import com.google.common.collect.Multimap;
29 import com.google.common.collect.Multimaps;
30 import org.apache.commons.lang.RandomStringUtils;
31 import org.junit.Assert;
32 import org.junit.Test;
47 import java.util.ArrayList;
48 import java.util.Collections;
49 import java.util.List;
51 import java.util.Random;
52 import java.util.stream.Collectors;
53 import java.util.stream.IntStream;
54 import java.util.stream.Stream;
69 final List<ITerm> l_return =
new ArrayList<>();
73 Collections.emptyList(),
77 Assert.assertEquals( l_return.size(), 1 );
78 Assert.assertTrue( l_return.get( 0 ).raw() instanceof Multimap<?, ?> );
79 Assert.assertTrue( l_return.get( 0 ).<Multimap<?, ?>>raw().isEmpty() );
88 final List<ITerm> l_return =
new ArrayList<>();
92 Collections.emptyList(),
96 Assert.assertEquals( l_return.size(), 1 );
97 Assert.assertEquals( l_return.get( 0 ).raw().getClass(), Multimaps.synchronizedSetMultimap( HashMultimap.create() ).getClass() );
107 final Multimap<Object, Object> l_map = HashMultimap.create();
112 l_map.put(
"c", 10 );
114 final List<ITerm> l_return =
new ArrayList<>();
119 Stream.of( l_map ).map(
CRawTerm::from ).collect( Collectors.toList() ),
125 Stream.of( l_map ).map(
CRawTerm::from ).collect( Collectors.toList() ),
130 Assert.assertEquals( l_return.size(), 2 );
131 Assert.assertArrayEquals( l_return.get( 0 ).<List<?>>raw().toArray(), Stream.of(
"a",
"b",
"c" ).toArray() );
132 Assert.assertArrayEquals( l_return.get( 1 ).<List<?>>raw().toArray(), Stream.of( 1, 2, 3, 1, 10 ).toArray() );
141 final Multimap<Integer, String> l_map = HashMultimap.create();
142 final List<ITerm> l_return =
new ArrayList<>();
144 final Random l_random =
new Random();
145 IntStream.range( 0, 5 ).map( i -> l_random.nextInt( 8 ) )
146 .forEach( i -> l_map.put( i, RandomStringUtils.random( 10,
"abcdefghijklmnop" ) ) );
150 Stream.of( l_map ).map(
CRawTerm::from ).collect( Collectors.toList() ),
154 Assert.assertEquals( l_return.size(), 1 );
155 Assert.assertTrue( l_return.get( 0 ).raw() instanceof Map<?, ?> );
156 Assert.assertArrayEquals( l_return.get( 0 ).<Map<?, ?>>raw().keySet().toArray(), l_map.keySet().toArray() );
158 Assert.assertArrayEquals(
160 l_map.values().toArray()
171 final Multimap<Integer, String> l_map1 = HashMultimap.create();
172 final Multimap<Integer, String> l_map2 = HashMultimap.create();
176 Stream.of( 1,
"foo", l_map1, l_map2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
177 Collections.emptyList()
180 Assert.assertArrayEquals( l_map1.keys().toArray(), Stream.of( 1 ).toArray() );
181 Assert.assertArrayEquals( l_map2.keys().toArray(), Stream.of( 1 ).toArray() );
183 Assert.assertArrayEquals( l_map1.values().toArray(), Stream.of(
"foo" ).toArray() );
184 Assert.assertArrayEquals( l_map1.values().toArray(), Stream.of(
"foo" ).toArray() );
194 final Multimap<Integer, String> l_map = HashMultimap.create();
198 Stream.of( l_map, 1,
"xxx", 2,
"blub", 3,
"xxx", 3,
"yyy" ).map(
CRawTerm::from ).collect( Collectors.toList() ),
199 Collections.emptyList()
202 Assert.assertEquals( l_map.size(), 4 );
203 Assert.assertArrayEquals( l_map.keySet().toArray(), Stream.of( 1, 2, 3 ).toArray() );
204 Assert.assertArrayEquals( l_map.values().toArray(), Stream.of(
"xxx",
"blub",
"yyy",
"xxx" ).toArray() );
214 final Multimap<Integer, String> l_map = HashMultimap.create();
215 final List<ITerm> l_return =
new ArrayList<>();
217 l_map.put( 1,
"yyy" );
218 l_map.put( 1,
"bar" );
219 l_map.put( 2,
"test string" );
220 l_map.put( 3,
"blub" );
224 Stream.of( l_map, 1, 2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
228 Assert.assertEquals( l_return.size(), 2 );
229 Assert.assertArrayEquals( l_return.get( 0 ).<List<?>>raw().toArray(), l_map.asMap().get( 1 ).toArray() );
230 Assert.assertArrayEquals( l_return.get( 1 ).<List<?>>raw().toArray(), l_map.asMap().get( 2 ).toArray() );
240 final Multimap<Integer, String> l_map1 = HashMultimap.create();
241 final Multimap<Integer, String> l_map2 = HashMultimap.create();
242 final List<ITerm> l_return =
new ArrayList<>();
244 l_map1.put( 1,
"foo" );
245 l_map1.put( 2,
"bar" );
246 l_map2.put( 1,
"foobar" );
250 Stream.of( 1, l_map1, l_map2 ).map(
CRawTerm::from ).collect( Collectors.toList() ),
254 Assert.assertEquals( l_return.size(), 2 );
255 Assert.assertArrayEquals( l_return.get( 0 ).<List<?>>raw().toArray(), Stream.of(
"foo" ).toArray() );
256 Assert.assertArrayEquals( l_return.get( 1 ).<List<?>>raw().toArray(), Stream.of(
"foobar" ).toArray() );
returns a multiple element of a single multimap.
final void asmap()
test as-map
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
adds an single element to multiple map arguments.
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
final void putmultiple()
test put-multiple
base test class with helpers
final void keysvalues()
test key and values
final void getmultiple()
test get-multiple
IContext EMPTYPLAN
empty context with plan
returns all key values of the multimap.
common structure for execution definition
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
returns all values of the multimap.
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
final void create()
test create
adds all elements to a single multimap argument.
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
execution context with local data
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
returns a single element of all multimap elements.
final void putsingle()
test put-single
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
returns the multimap as map.
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
< T > T raw()
cast to any raw value type
returns all key values of the map.
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
class for any helper calls
final void createsynchronized()
test synchronized create
returns a single element of all map elements.
returns all values of the map.
adds all elements to a single map argument.
returns a multiple element of a single map.
adds an single element to multiple multimap arguments.
term structure for simple datatypes
final void getsingle()
test get-single