aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/grouping/request/AvgFunction.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /container-search/src/main/java/com/yahoo/search/grouping/request/AvgFunction.java
Publish
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/grouping/request/AvgFunction.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/grouping/request/AvgFunction.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/AvgFunction.java b/container-search/src/main/java/com/yahoo/search/grouping/request/AvgFunction.java
new file mode 100644
index 00000000000..c0474064741
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/grouping/request/AvgFunction.java
@@ -0,0 +1,42 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.search.grouping.request;
+
+import java.util.List;
+
+/**
+ * This class represents a min-function in a {@link GroupingExpression}. It evaluates to a number that equals the
+ * average of the results of all arguments.
+ *
+ * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
+ */
+public class AvgFunction extends FunctionNode {
+
+ /**
+ * Constructs a new instance of this class.
+ *
+ * @param arg1 The first compulsory argument, must evaluate to a number.
+ * @param arg2 The second compulsory argument, must evaluate to a number.
+ * @param argN The optional arguments, must evaluate to a number.
+ */
+ public AvgFunction(GroupingExpression arg1, GroupingExpression arg2, GroupingExpression... argN) {
+ this(asList(arg1, arg2, argN));
+ }
+
+ private AvgFunction(List<GroupingExpression> args) {
+ super("avg", args);
+ }
+
+ /**
+ * Constructs a new instance of this class from a list of arguments.
+ *
+ * @param args The arguments to pass to the constructor.
+ * @return The created instance.
+ * @throws IllegalArgumentException Thrown if the number of arguments is less than 2.
+ */
+ public static AvgFunction newInstance(List<GroupingExpression> args) {
+ if (args.size() < 2) {
+ throw new IllegalArgumentException("Expected 2 or more arguments, got " + args.size() + ".");
+ }
+ return new AvgFunction(args);
+ }
+}