aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/pagetemplates/model/Layout.java
blob: b4d0bfa44f08a8af37f7f4dbfc8ffe779087cdf5 (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
45
46
47
48
49
50
51
52
53
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.pagetemplates.model;

/**
 * The layout of a section
 *
 * @author bratseth
 */
// This is not made an enum, to allow the value set to be extendible.
// It is not explicitly made immutable
// to enable adding of internal state later (esp. parameters).
// If this becomes mutable, the creation scheme must be changed
// such that each fromString returns a unique instance, and
// the name must become a (immutable) type.
public class Layout {

    /** The built in "column" layout */
    public static final Layout column=new Layout("column");
    /** The built in "row" layout */
    public static final Layout row=new Layout("row");

    private String name;

    public Layout(String name) {
        this.name=name;
    }

    public String getName() { return name; }

    @Override
    public int hashCode() { return name.hashCode(); }

    @Override
    public boolean equals(Object o) {
        if (o==this) return true;
        if (! (o instanceof Layout)) return false;
        Layout other=(Layout)o;
        return this.name.equals(other.name);
    }

    /** Returns a layout having this string as name, or null if the given string is null or empty */
    public static Layout fromString(String layout) {
        //if (layout==null) return null;
        //if (layout)
        if (layout.equals("column")) return column;
        if (layout.equals("row")) return row;
        return new Layout(layout);
    }

    @Override
    public String toString() { return "layout '" + name + "'"; }

}