All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.openxc.units.State Maven / Gradle / Ivy

The newest version!
package com.openxc.units;

import java.util.Locale;

import com.google.common.base.Objects;

/**
 * A State is a type of Unit with a limited number of acceptable values.
 */
public class State> extends Unit {
    private T mValue;

    /**
     * Construct an instance of State from the Enum T value.
     *
     * @param value an instance of the Enum T.
     */
    public State(T value) {
        mValue = value;
    }

    @Override
    public boolean equals(Object obj) {
        if(!super.equals(obj)) {
            return false;
        }

        @SuppressWarnings("unchecked")
        final State other = (State) obj;
        return mValue.equals(other.mValue);
    }

    /**
     * Return the value of this State as an Enum.
     *
     * This is primarily useful for comparison.
     *
     * @return this State's base Enum value.
     */
    public T enumValue() {
        return mValue;
    }

    public String getSerializedValue() {
        return mValue.toString().toLowerCase(Locale.US);
    }

    @Override
    public String toString() {
        return mValue.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy