Convert Fuse to kotlin

This commit is contained in:
Mike Cifelli 2018-10-21 10:10:04 -04:00
parent bff9981458
commit 84467388bb
4 changed files with 41 additions and 37 deletions

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="function.FunctionNames" />
</list>
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>

View File

@ -1,35 +0,0 @@
package function.builtin;
import function.ArgumentValidator;
import function.FunctionNames;
import function.LispFunction;
import sexpression.Atom;
import sexpression.Cons;
import sexpression.LispString;
import sexpression.SExpression;
import sexpression.Symbol;
@FunctionNames({ "FUSE" })
public class FUSE extends LispFunction {
private static final String SEPARATOR = "-";
private ArgumentValidator argumentValidator;
public FUSE(String name) {
this.argumentValidator = new ArgumentValidator(name);
this.argumentValidator.setExactNumberOfArguments(2);
this.argumentValidator.setFirstArgumentExpectedType(Symbol.class);
this.argumentValidator.setTrailingArgumentExpectedType(Atom.class);
this.argumentValidator.setTrailingArgumentExcludedType(LispString.class);
}
@Override
public SExpression call(Cons argumentList) {
argumentValidator.validate(argumentList);
Symbol left = (Symbol) argumentList.getFirst();
Atom right = (Atom) ((Cons) argumentList.getRest()).getFirst();
return new Symbol(left.toString() + SEPARATOR + right.toString());
}
}

View File

@ -0,0 +1,34 @@
package function.builtin
import function.ArgumentValidator
import function.FunctionNames
import function.LispFunction
import sexpression.Atom
import sexpression.Cons
import sexpression.LispString
import sexpression.SExpression
import sexpression.Symbol
@FunctionNames("FUSE")
class Fuse(name: String) : LispFunction() {
private val argumentValidator: ArgumentValidator = ArgumentValidator(name).apply {
setExactNumberOfArguments(2)
setFirstArgumentExpectedType(Symbol::class.java)
setTrailingArgumentExpectedType(Atom::class.java)
setTrailingArgumentExcludedType(LispString::class.java)
}
override fun call(argumentList: Cons): SExpression {
argumentValidator.validate(argumentList)
val left = argumentList.first as Symbol
val right = (argumentList.rest as Cons).first as Atom
return Symbol("$left$SEPARATOR$right")
}
companion object {
private const val SEPARATOR = "-"
}
}

View File

@ -1,4 +1,4 @@
package function.builtin.special;
package function.builtin;
import function.ArgumentValidator.BadArgumentTypeException;
import function.ArgumentValidator.TooFewArgumentsException;
@ -10,7 +10,7 @@ import testutil.SymbolAndFunctionCleaner;
import static testutil.TestUtilities.assertSExpressionsMatch;
import static testutil.TestUtilities.evaluateString;
public class FUSETest extends SymbolAndFunctionCleaner {
public class FuseTest extends SymbolAndFunctionCleaner {
@Test
public void fuseSymbolAndNumber() {