summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/grouping/result/GroupId.java
blob: 81ce8b7573b37d3205c8fd4efb0c196f00e33a77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.grouping.result;

/**
 * This abstract class represents the id of a single group in the grouping result model. A subclass corresponding to the
 * evaluation result of generating {@link com.yahoo.search.grouping.request.GroupingExpression} is contained in all
 * {@link Group} objects. It is used by {@link com.yahoo.search.grouping.GroupingRequest} to identify its root result
 * group, and by all client code for identifying groups.
 * <p>
 * The {@link #toString()} method of this class generates a URI-compatible string on the form
 * "group:&lt;typeName&gt;:&lt;subclassSpecific&gt;".
 *
 * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
 */
public abstract class GroupId {

    private final String type;
    private final String image;

    protected GroupId(String type, Object... args) {
        this.type = type;

        StringBuilder image = new StringBuilder("group:");
        image.append(type);
        for (Object arg : args) {
            image.append(":").append(arg);
        }
        this.image = image.toString();
    }

    /**
     * Returns the type name of this group id. This is the second part of the {@link #toString()} value of this.
     *
     * @return The type name.
     */
    public String getTypeName() {
        return type;
    }

    @Override
    public String toString() {
        return image;
    }
}