diff options
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/grouping/request/RawPredefined.java')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/grouping/request/RawPredefined.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/grouping/request/RawPredefined.java b/container-search/src/main/java/com/yahoo/search/grouping/request/RawPredefined.java new file mode 100644 index 00000000000..c2650346231 --- /dev/null +++ b/container-search/src/main/java/com/yahoo/search/grouping/request/RawPredefined.java @@ -0,0 +1,48 @@ +// 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 predefined bucket-function in a {@link GroupingExpression} for expressions that evaluate to a + * raw. + * + * @author <a href="mailto:lulf@yahoo-inc.com">Ulf Lilleengen</a> + */ +public class RawPredefined extends PredefinedFunction { + + /** + * Constructs a new instance of this class. + * + * @param exp The expression to evaluate, must evaluate to a string. + * @param arg1 The compulsory bucket. + * @param argN The optional buckets. + */ + public RawPredefined(GroupingExpression exp, RawBucket arg1, RawBucket... argN) { + this(exp, asList(arg1, argN)); + } + + private RawPredefined(GroupingExpression exp, List<RawBucket> args) { + super(exp, args); + } + + @Override + public RawBucket getBucket(int i) { + return (RawBucket)getArg(i + 1); + } + + /** + * Constructs a new instance of this class from a list of arguments. + * + * @param exp The expression to evaluate, must evaluate to a string. + * @param args The buckets to pass to the constructor. + * @return The created instance. + * @throws IllegalArgumentException Thrown if the list of buckets is empty. + */ + public static RawPredefined newInstance(GroupingExpression exp, List<RawBucket> args) { + if (args.isEmpty()) { + throw new IllegalArgumentException("Expected at least one bucket, got none."); + } + return new RawPredefined(exp, args); + } +} |