com.bazaarvoice.lassie.screenboard.widgets.Color.java Source code

Java tutorial

Introduction

Here is the source code for com.bazaarvoice.lassie.screenboard.widgets.Color.java

Source

/*
 * Copyright 2013 Bazaarvoice, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bazaarvoice.lassie.screenboard.widgets;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import static com.google.common.base.Preconditions.checkNotNull;

public enum Color {
    RED_ON_WHITE("red_on_white"), YELLOW_ON_WHITE("yellow_on_white"), GREEN_ON_WHITE(
            "green_on_white"), WHITE_ON_RED(
                    "white_on_red"), WHITE_ON_YELLOW("white_on_yellow"), WHITE_ON_GREEN("white_on_green");

    private final String _name;

    /**
     * Constructor that sets the name of the Color as it is documented in the datadog API.
     *
     * @param name name of the Color.
     */
    private Color(String name) {
        _name = name;
    }

    /**
     * Gets the name of the Color as it is documented in the datadog API.
     *
     * @return The name of the Color.
     */
    @JsonValue
    public String getName() {
        return _name;
    }

    /**
     * Parse Color name into the corresponding {@link Color} value.
     *
     * @param name The name of the expected enum.
     * @return The Color enum.
     */
    @JsonCreator
    public static Color fromName(String name) {
        checkNotNull(name);
        return Color.valueOf(name.toUpperCase());
    }
}