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

org.jcamp.units.DimensionlessUnit Maven / Gradle / Ivy

Go to download

The JCAMP-DX project is the reference implemention of the IUPAC JCAMP-DX spectroscopy data standard.

There is a newer version: 0.9.2
Show newest version
package org.jcamp.units;

/**
 * unit without dimensions.
 * @author Thomas Weber 
 */
public final class DimensionlessUnit extends Unit {
    String quantity;
    String name;
    String symbol;
    /**
     * ScaledUnit constructor comment.
     * @param identifier java.lang.String
     */
    public DimensionlessUnit(String quantity, String name, String symbol) {
        super(quantity, name);
        this.quantity = quantity;
        this.name = name;
        this.symbol = symbol;
    }
    /**
     * convert value from unit thatUnit to this unit.
     * @param value double
     * @param thatUnit Unit
     * @return double
     */
    public double convertFrom(double value, Unit thatUnit) throws UnitException {
        if (isConvertibleTo(thatUnit)) {
            if (thatUnit instanceof DimensionlessUnit || thatUnit.equals(BaseUnit.generic))
                return value;
            else
                return thatUnit.convertTo(value, this);
        } else
            throw new UnitException("units not convertible");
    }
    /**
     * convert value to unit thatUnit from this unit.
     * @param value double
     * @param thatUnit Unit
     * @return double
     */
    public double convertTo(double value, Unit thatUnit) throws UnitException {
        if (isConvertibleTo(thatUnit)) {
            if (thatUnit instanceof DimensionlessUnit || thatUnit.equals(BaseUnit.generic))
                return value;
            else
                return thatUnit.convertFrom(value, this);
        } else
            throw new UnitException("units not convertible");
    }
    /**
     * gets unit name.
     * @return String
     */
    public String getName() {
        return name;
    }
    /**
     * gets quantity.
     * @return String
     */
    public java.lang.String getQuantity() {
        return quantity;
    }
    /**
     * getScaleFactor method comment.
     */
    final double getScaleFactor() {
        return 1.0;
    }
    /**
     * getDefinition method comment.
     */
    public String getSymbol() {
        return symbol;
    }
    /**
     * checks if unit is convertible to unit thatUnit.
     * @param thatUnit Unit
     * @return boolean
     */
    public boolean isConvertibleTo(Unit thatUnit) {
        return BaseUnit.generic.isConvertibleTo(thatUnit);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy