io.github.carlomicieli.footballdb.starter.domain.StatValue.java Source code

Java tutorial

Introduction

Here is the source code for io.github.carlomicieli.footballdb.starter.domain.StatValue.java

Source

/*
 * Copyright 2014 the original author or authors.
 *
 *  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 io.github.carlomicieli.footballdb.starter.domain;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * @author Carlo Micieli
 */
public final class StatValue {
    private final String groupName;
    private final String name;
    private final String value;

    private StatValue(String groupName, String name, String value) {
        this.groupName = groupName;
        this.name = name;
        this.value = value;
    }

    /**
     * The kind of statistic value.
     * @return
     */
    public String groupName() {
        return groupName;
    }

    /**
     * The name.
     * @return
     */
    public String name() {
        return name;
    }

    /**
     * The statistic value.
     * @return
     */
    public String value() {
        return value;
    }

    @Override
    public String toString() {
        return String.format("Stat(%s, %s, %s)", groupName, name, value);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this)
            return true;
        if (!(obj instanceof StatValue))
            return false;

        StatValue that = (StatValue) obj;
        return new EqualsBuilder().append(this.groupName, that.groupName).append(this.name, that.name)
                .append(this.value, that.value).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(31, 7).append(this.groupName).append(this.name).append(this.value).hashCode();
    }

    public static StatValue parse(String name, String val) {
        String[] tokens = name.split("\\.");
        return new StatValue(tokens[0], tokens[1], val);
    }
}