Skip to content

Commit 86b0f09

Browse files
author
Philipp Kraus
committed
add range action
1 parent 5ba47c6 commit 86b0f09

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

TestCAsl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.lightjason.agentspeak.testing.action.CTestEqual;
4747
import org.lightjason.agentspeak.testing.action.CTestIs;
4848
import org.lightjason.agentspeak.testing.action.CTestListGet;
49+
import org.lightjason.agentspeak.testing.action.CTestListRange;
4950
import org.lightjason.agentspeak.testing.action.CTestPrint;
5051
import org.lightjason.agentspeak.testing.action.CTestToString;
5152

@@ -185,7 +186,8 @@ public void testASLDefault( @Nonnull final String p_file ) throws Exception
185186
new CTestEqual(),
186187
new CTestToString(),
187188
new CTestIs(),
188-
new CTestListGet()
189+
new CTestListGet(),
190+
new CTestListRange()
189191
),
190192
CCommon.actionsFromPackage()
191193
)

action/CTestListRange.java

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* @cond LICENSE
3+
* ######################################################################################
4+
* # LGPL License #
5+
* # #
6+
* # This file is part of the LightJason #
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.testing.action;
25+
26+
import org.lightjason.agentspeak.action.IBaseAction;
27+
import org.lightjason.agentspeak.common.CPath;
28+
import org.lightjason.agentspeak.common.IPath;
29+
import org.lightjason.agentspeak.language.CRawTerm;
30+
import org.lightjason.agentspeak.language.ITerm;
31+
import org.lightjason.agentspeak.language.execution.IContext;
32+
import org.lightjason.agentspeak.language.fuzzy.IFuzzyValue;
33+
34+
import javax.annotation.Nonnull;
35+
import java.util.Collections;
36+
import java.util.List;
37+
import java.util.stream.Collectors;
38+
import java.util.stream.IntStream;
39+
import java.util.stream.Stream;
40+
41+
42+
/**
43+
* test action for range list generation
44+
*/
45+
public final class CTestListRange extends IBaseAction
46+
{
47+
/**
48+
* serial id
49+
*/
50+
private static final long serialVersionUID = 7182954486280160148L;
51+
/**
52+
* action name
53+
*/
54+
private static final IPath NAME = CPath.of( "test/list/range" );
55+
56+
57+
@Nonnull
58+
@Override
59+
public IPath name()
60+
{
61+
return NAME;
62+
}
63+
64+
@Override
65+
public int minimalArgumentNumber()
66+
{
67+
return 2;
68+
}
69+
70+
@Nonnull
71+
@Override
72+
public Stream<IFuzzyValue<?>> execute( final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List<ITerm> p_argument,
73+
@Nonnull final List<ITerm> p_return )
74+
{
75+
final List<?> l_range = IntStream.range( p_argument.get( 0 ).<Number>raw().intValue(), p_argument.get( 1 ).<Number>raw().intValue() )
76+
.boxed()
77+
.collect( Collectors.toList() );
78+
79+
p_return.add(
80+
CRawTerm.of(
81+
p_parallel ? Collections.synchronizedList( l_range ) : l_range
82+
)
83+
);
84+
85+
return Stream.of();
86+
}
87+
}

0 commit comments

Comments
 (0)