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

ucar.units.UnitID Maven / Gradle / Ivy

Go to download

The ucar.units Java package is for decoding and encoding formatted unit specifications (e.g. "m/s"), converting numeric values between compatible units (e.g. between "m/s" and "knot"), and for performing arithmetic operations on units (e.g. dividing one unit by another, or raising a unit to a power).

The newest version!
/*
 * Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata
 * See LICENSE for license information.
 */
package ucar.units;

import java.io.Serializable;

/**
 * Provides support for unit identifiers.
 * 
 * @author Steven R. Emmerson
 */
public abstract class UnitID implements Serializable {
	private static final long	serialVersionUID	= 1L;

	/**
	 * Factory method for constructing an identifier from a name, plural, and
	 * symbol.
	 * 
	 * @param name
	 *            The name for the unit. May be null
     *				.
	 * @param plural
	 *            The plural form of the name. If null
     *				 and
	 *            name is non-
     *				null, then regular
	 *            plural-forming rules are used on the name.
	 * @param symbol
	 *            The symbol for the unit. May be null
     *				.
	 */
	public static UnitID newUnitID(final String name, final String plural,
			final String symbol) {
		UnitID id;
		try {
			id = name == null
					? new UnitSymbol(symbol)
					: UnitName.newUnitName(name, plural, symbol);
		}
		catch (final NameException e) {
			id = null; // can't happen
		}
		return id;
	}

	/**
	 * Returns the name of the unit.
	 * 
	 * @return The name of the unit. May be null.
	 */
	public abstract String getName();

	/**
	 * Returns the plural form of the name of the unit.
	 * 
	 * @return The plural form of the name of the unit. May be null
	 *         .
	 */
	public abstract String getPlural();

	/**
	 * Returns the symbol for the unit.
	 * 
	 * @return The symbol for the unit. May be null.
	 */
	public abstract String getSymbol();

	/**
	 * Returns the string representation of this identifier.
	 * 
	 * @return The string representation of this identifier.
	 */
	@Override
	public abstract String toString();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy