udunits/src/main/java/ucar/units/BaseUnit.java
public static synchronized BaseUnit getOrCreate(final UnitName id,
            final BaseQuantity baseQuantity) throws NameException,
            UnitExistsException {
        BaseUnit baseUnit;
        final BaseUnit nameUnit = nameMap.get(id);
        final BaseUnit quantityUnit = quantityMap.get(baseQuantity);
        if (nameUnit != null || quantityUnit != null) {
            baseUnit = nameUnit != null
                    ? nameUnit
                    : quantityUnit;
            if ((nameUnit != null && !baseQuantity.equals(nameUnit
                    .getBaseQuantity()))
                    || (quantityUnit != null && !id.equals(quantityUnit
                            .getUnitName()))) {
                throw new UnitExistsException(
                        "Attempt to incompatibly redefine base unit \""
                                + baseUnit + '"');
            }
        }
        else {
            baseUnit = new BaseUnit(id, baseQuantity);
            quantityMap.put(baseQuantity, baseUnit);
            nameMap.put(id, baseUnit);
        }
        return baseUnit;
    }
public static synchronized BaseUnit getOrCreate(final UnitName id,
            final BaseQuantity baseQuantity) throws NameException,
            UnitExistsException {
        BaseUnit baseUnit;
        final BaseUnit nameUnit = nameMap.get(id);
        final BaseUnit quantityUnit = quantityMap.get(baseQuantity);
        if (nameUnit != null || quantityUnit != null) {
            baseUnit = nameUnit != null
                    ? nameUnit
                    : quantityUnit;
            if ((nameUnit != null && !baseQuantity.equals(nameUnit
                    .getBaseQuantity()))
                    || (quantityUnit != null && !id.equals(quantityUnit
                            .getUnitName()))) {
                throw new UnitExistsException(
                        "Attempt to incompatibly redefine base unit \""
                                + baseUnit + '"');
            }
        }
        else {
            baseUnit = new BaseUnit(id, baseQuantity);
            quantityMap.put(baseQuantity, baseUnit);
            nameMap.put(id, baseUnit);
        }
        return baseUnit;
    }
Factory method for creating a new BaseUnit or obtaining a
previously-created one.

@param id
The identifier for the base unit. <code>
id.getSymbol()</code>
shall not return <code>
null</code>.
@param baseQuantity
The base quantity of the base unit.
@throws NameException
<code>id.getSymbol()</code> returned <code>
null</code>.
@throws UnitExistsException
Attempt to incompatibly redefine an existing base unit.