commit 8b15778d67d00a1df570d403235aab637195b04d Author: richie Date: Fri Nov 16 16:57:52 2018 +0800 示例函数 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..55cc8e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.iml +.idea/ +lib/report/*.jar +target/ +.classpath +.DS_Store \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..2e671e0 --- /dev/null +++ b/build.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..3ac8a68 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,17 @@ + + com.fr.plugin.function.fib + + yes + 1.0 + 10.0 + 2018-07-31 + author + + + ]]> + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..4dded45 --- /dev/null +++ b/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + + com.fr.plugin + starter + 10.0 + + jar + demo-function-fibonacci + + + ${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.function.fib-1.0/classes + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/function/fib/Fibonacci.java b/src/main/java/com/fr/plugin/function/fib/Fibonacci.java new file mode 100644 index 0000000..3291059 --- /dev/null +++ b/src/main/java/com/fr/plugin/function/fib/Fibonacci.java @@ -0,0 +1,44 @@ +package com.fr.plugin.function.fib; + +import com.fr.general.GeneralUtils; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.record.analyzer.EnableMetrics; +import com.fr.script.AbstractFunction; +import com.fr.stable.ArrayUtils; +import com.fr.stable.Primitive; + +@EnableMetrics +public class Fibonacci extends AbstractFunction { + + @Override + @Focus(id = "com.fr.plugin.function.fib", text = "", source = Original.PLUGIN) + public Object run(Object[] args) { + if (ArrayUtils.isEmpty(args)) { + return Primitive.ERROR_VALUE; + } + int n = GeneralUtils.objectToNumber(args[0]).intValue(); + if (n < 0) { + return Primitive.ERROR_VALUE; + } + return getFib(n); + } + + private int getFib(int n) { + if (n < 0) { + return -1; + } else if (n == 0) { + return 0; + } else if (n == 1 || n == 2) { + return 1; + } else { + int[] fibAry = new int[n + 1]; + fibAry[0] = 0; + fibAry[1] = fibAry[2] = 1; + for (int i = 3; i <= n; i++) { + fibAry[i] = fibAry[i - 1] + fibAry[i - 2]; + } + return fibAry[n]; + } + } +} diff --git a/src/main/resources/.gitkeep b/src/main/resources/.gitkeep new file mode 100644 index 0000000..e69de29