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

de.tsl2.nano.util.operation.OperableUnit Maven / Gradle / Ivy

/*
 * File: $HeadURL$
 * Id  : $Id$
 * 
 * created by: Thomas Schneider
 * created on: Jul 20, 2012
 * 
 * Copyright: (c) Thomas Schneider 2012, all rights reserved
 */
package de.tsl2.nano.util.operation;

/**
 * usable to compare values with defined units. f.e., a bigdecimal working as currency.
 * 
 * @author Thomas Schneider
 * @version $Revision$
 */
public class OperableUnit, U> extends Operable implements IUnit {

    /**
     * constructor
     * 
     * @param value
     * @param converter
     */
    public OperableUnit(T value, IConvertableUnit converter) {
        super(value, converter);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public U getUnit() {
        return ((IConvertableUnit)converter).getUnit();
    }

    /**
     * converts the own value to the given operableunit.
     * 
     * @param convertableUnit new unit, to convert the own value to
     * @return converted value
     */
    public , U1> OperableUnit convert(IConvertableUnit convertableUnit) {
        return new OperableUnit(convertableUnit.from(converter.to(value)), convertableUnit);
    }
    
    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return getConversion() + " " + getUnit();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy