Package org.djunits.unit
Class Unit.Builder<U extends Unit<U>>
java.lang.Object
org.djunits.unit.Unit.Builder<U>
- Type Parameters:
U
- the unit for which the builder contains the information.
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbsoluteLinearUnit.Builder
public static class Unit.Builder<U extends Unit<U>> extends Object implements Serializable
The class that contains the information to build a unit.
Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUNITS License.
- Author:
- Alexander Verbraeck
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description Builder()
Empty constructor. -
Method Summary
Modifier and Type Method Description Set<String>
getAdditionalAbbreviations()
Retrieve the additional abbreviations.String
getDefaultDisplayAbbreviation()
Retrieve the default display abbreviation.String
getDefaultTextualAbbreviation()
Retrieve the default textual abbreviation.String
getId()
Retrieve the id of the unit that this builder builds.String
getName()
Return the name.Quantity<U>
getQuantity()
Retrieve the unit base.Scale
getScale()
Retrieve the scale.SIPrefixes
getSiPrefixes()
Return whether SI prefixes, ranging from yotta (y) to yocto (Y), will be generated.double
getSiPrefixPowerFactor()
Return the power factor of the SI prefixes, e.g.UnitSystem
getUnitSystem()
Retrieve the unit system.boolean
isGenerated()
Retrieve the generated flag.Unit.Builder<U>
setAdditionalAbbreviations(String... newAdditionalAbbreviations)
Set the additional abbreviations.Unit.Builder<U>
setDefaultDisplayAbbreviation(String newDefaultDisplayAbbreviation)
Set the default display abbreviation.Unit.Builder<U>
setDefaultTextualAbbreviation(String newDefaultTextualAbbreviation)
Set the default textual abbreviation.Unit.Builder<U>
setGenerated(boolean newGenerated)
Set the generated flag.Unit.Builder<U>
setId(String newId)
Set the id of the unit that this builder builds.Unit.Builder<U>
setName(String newName)
Set the name.Unit.Builder<U>
setQuantity(Quantity<U> newQuantity)
Set the unit base.Unit.Builder<U>
setScale(Scale newScale)
Set the scale.Unit.Builder<U>
setSiPrefixes(SIPrefixes newSiPrefixes, double power)
Set whether SI prefixes, ranging from yotta (y) to yocto (Y), are allowed.Unit.Builder<U>
setUnitSystem(UnitSystem newUnitSystem)
Set the unit system.String
toString()
-
Constructor Details
-
Builder
public Builder()Empty constructor. Content is generated through chaining: new Unit.Builder<TypeUnit>().setId("id").setName("name");
-
-
Method Details
-
getSiPrefixes
Return whether SI prefixes, ranging from yotta (y) to yocto (Y), will be generated.- Returns:
- siPrefixes, NONE (e.g., for inch), ALL (e.g., for meter) or KILO (e.g., for kilometer)
-
getSiPrefixPowerFactor
public double getSiPrefixPowerFactor()Return the power factor of the SI prefixes, e.g. 2.0 for square meters and 3.0 for cubic meters.- Returns:
- siPrefixPower double; power factor of the SI prefixes, e.g. 2.0 for square meters and 3.0 for cubic meters
-
setSiPrefixes
Set whether SI prefixes, ranging from yotta (y) to yocto (Y), are allowed. If not set; this property defaults tofalse
.- Parameters:
newSiPrefixes
- SIPrefixes; SIPrefixes set siPrefixes, NONE (e.g., for inch), ALL (e.g., for meter) or KILO (e.g., for kilometer)power
- double; power factor of the SI prefixes, e.g. 2.0 for square meters and 3.0 for cubic meters- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getId
Retrieve the id of the unit that this builder builds.- Returns:
- String; the id of the unit that this builder builds
-
setId
Set the id of the unit that this builder builds.- Parameters:
newId
- String; set the id of the unit that this builder builds (must be set; the default isnull
which is invalid)- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getAdditionalAbbreviations
Retrieve the additional abbreviations.- Returns:
- Set<String>; the additional abbreviations
-
setAdditionalAbbreviations
Set the additional abbreviations.- Parameters:
newAdditionalAbbreviations
- String...; the additional abbreviations- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getDefaultDisplayAbbreviation
Retrieve the default display abbreviation.- Returns:
- String; the default display abbreviation
-
setDefaultDisplayAbbreviation
Set the default display abbreviation.- Parameters:
newDefaultDisplayAbbreviation
- String; the default display abbreviation- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getDefaultTextualAbbreviation
Retrieve the default textual abbreviation.- Returns:
- String; the default textual abbreviation
-
setDefaultTextualAbbreviation
Set the default textual abbreviation.- Parameters:
newDefaultTextualAbbreviation
- String; the default textual abbreviation- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getName
Return the name.- Returns:
- String; the name
-
setName
Set the name.- Parameters:
newName
- String; the name- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getScale
Retrieve the scale.- Returns:
- Scale; the scale
-
setScale
Set the scale.- Parameters:
newScale
- Scale; set the scale- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getUnitSystem
Retrieve the unit system.- Returns:
- unitSystem UnitSystem; the unit system
-
setUnitSystem
Set the unit system.- Parameters:
newUnitSystem
- UnitSystem; the unit system- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
isGenerated
public boolean isGenerated()Retrieve the generated flag.- Returns:
- generated Boolean; the generated flag
-
setGenerated
Set the generated flag. Defaults to false. Should be set for units that are automatically generated.- Parameters:
newGenerated
- boolean; the value for the generated flag- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
getQuantity
Retrieve the unit base.- Returns:
- baseUnit BaseUnit<U>; the unit base
-
setQuantity
Set the unit base. Can never be null and has to be filled.- Parameters:
newQuantity
- Quantity<U>; the unit base- Returns:
- Builder; this builder instance that is being constructed (for method call chaining)
-
toString
-