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 .