Class SIDimensions

java.lang.Object
org.djunits.unit.si.SIDimensions
All Implemented Interfaces:
Serializable

public class SIDimensions extends Object implements Serializable
SIDimensions stores the dimensionality of a unit using the SI standards. Angle (rad) and solid angle (sr) have been added to be able to specify often used units regarding rotation.

Copyright (c) 2019-2024 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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final SIDimensions
    the dimensionless SIDimensions.
    static final int
    The (currently) 9 dimensions we take into account: rad, sr, kg, m, s, A, K, mol, cd.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    SIDimensions(byte[] dimensions)
    Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification.
    protected
    SIDimensions(byte[] numerator, byte[] denominator)
    Create an immutable fractional SIDimensions instance based on a safe copy of a given specification, separated in a numerator and a denominator.
     
    SIDimensions(int angle, int solidAngle, int mass, int length, int time, int current, int temperature, int amountOfSubstance, int luminousIntensity)
    Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification.
  • Method Summary

    Modifier and Type
    Method
    Description
    Add two SIDimensions and return the new SIDimensions.
    boolean
     
    int
     
    Invert a set of SI dimensions; instead of m/s we get s/m.
    boolean
    Indicate whether this SIDImensions contains one or more fractional dimensions.
    Subtract a set of SI dimensions from this SIDimensions.
    of(String siString)
    Parse a string representing SI dimensions to an SIDimensions object.
    Add a set of SI dimensions to this SIDimensions.
    Returns a safe copy of the SI abbreviations (a public static final String[] is mutable).
    Subtract an SIDimensions (dim2) from another SIDimensions (dim1) and return the new SIDimensions.
    toHTMLString(boolean divided, boolean separator)
    Return a string such as "kgm/s2" or or "kg.m.s-2" from this SIDimensions.
     
    toString(boolean divided, boolean separator)
    Return a string such as "kgm/s2" or "kg.m/s2" or "kg.m.s-2" from this SIDimensions.
    toString(boolean divided, boolean separator, boolean power)
    Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.
    toString(boolean divided, String separator, String powerPrefix, String powerPostfix)
    Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • NUMBER_DIMENSIONS

      public static final int NUMBER_DIMENSIONS
      The (currently) 9 dimensions we take into account: rad, sr, kg, m, s, A, K, mol, cd.
      See Also:
    • DIMLESS

      public static final SIDimensions DIMLESS
      the dimensionless SIDimensions.
  • Constructor Details

    • SIDimensions

      public SIDimensions(byte[] dimensions)
      Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification. As an example, speed is indicated as length = 1; time = -1 with the other dimensions equal to zero.
      Parameters:
      dimensions - byte[]; The (currently) 9 dimensions of the SI unit we distinguish: 0: angle (rad), 1: solid angle (sr), 2: mass (kg), 3: length (m), 4: time (s), 5: current (A), 6: temperature (K), 7: amount of substance (mol), 8: luminous intensity (cd).
    • SIDimensions

      protected SIDimensions(byte[] numerator, byte[] denominator)
      Create an immutable fractional SIDimensions instance based on a safe copy of a given specification, separated in a numerator and a denominator.
      Parameters:
      numerator - byte[]; The (currently) 9 dimensions of the SI unit we distinguish: 0: angle (rad), 1: solid angle (sr), 2: mass (kg), 3: length (m), 4: time (s), 5: current (A), 6: temperature (K), 7: amount of substance (mol), 8: luminous intensity (cd).
      denominator - byte[]; The (currently) 9 dimensions of the SI unit we distinguish: 0: angle (rad), 1: solid angle (sr), 2: mass (kg), 3: length (m), 4: time (s), 5: current (A), 6: temperature (K), 7: amount of substance (mol), 8: luminous intensity (cd).
    • SIDimensions

      public SIDimensions(int angle, int solidAngle, int mass, int length, int time, int current, int temperature, int amountOfSubstance, int luminousIntensity)
      Create an immutable SIDimensions instance based on a safe copy of a given dimensions specification.
      Parameters:
      angle - int; dimension of the angle (rad)
      solidAngle - int; dimension of the solidAngle (sr)
      mass - int; dimension of the mass (kg)
      length - int; dimension of the length (m)
      time - int; dimension of the time (s)
      current - int; dimension of the current (A)
      temperature - int; dimension of the temperature (K)
      amountOfSubstance - int; dimension of the amount of substance (mol)
      luminousIntensity - int; dimension of the luminous intensity (cd)
  • Method Details

    • of

      public static SIDimensions of(String siString) throws UnitException
      Parse a string representing SI dimensions to an SIDimensions object. Example: SIDimensions.of("kgm/s2") and SIDimensions.of("kgms-2") will both be translated to a dimensions object with vector {0,0,1,1,-2,0,0,0,0}. It is allowed to use 0 or 1 for the dimensions. Having the same unit in the numerator and the denominator is not seen as a problem: the values are subtracted from each other, so m/m will have a length dimensionality of 0. Dimensions between -9 and 9 are allowed. Spaces, periods and ^ are taken out, but other characters are not allowed and will lead to a UnitException. The order of allowed units is arbitrary, so "kg/ms2" is accepted as well as "kg/s^2.m".
      Parameters:
      siString - String; the string to parse
      Returns:
      SIDimension; the corresponding SI dimensions
      Throws:
      UnitException - when the string could not be parsed into dimensions
    • siAbbreviations

      public String[] siAbbreviations()
      Returns a safe copy of the SI abbreviations (a public static final String[] is mutable).
      Returns:
      String[]; a safe copy of the SI abbreviations
    • plus

      public SIDimensions plus(SIDimensions other)
      Add a set of SI dimensions to this SIDimensions. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.
      Parameters:
      other - SIDimensions; the dimensions to add (usually as a result of multiplication of scalars)
      Returns:
      SIDimensions; the new dimensions with the dimensions of this object plus the dimensions in the parameter
    • minus

      public SIDimensions minus(SIDimensions other)
      Subtract a set of SI dimensions from this SIDimensions. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.
      Parameters:
      other - SIDimensions; the dimensions to subtract (usually as a result of division of scalars)
      Returns:
      SIDimensions; the new dimensions with the dimensions of this object minus the dimensions in the parameter
    • invert

      public SIDimensions invert()
      Invert a set of SI dimensions; instead of m/s we get s/m. Note: as dimensions are considered to be immutable, a new dimension is returned. The original dimension (this) remains unaltered.
      Returns:
      SIDimensions; the new dimensions that are the inverse of the dimensions in this object
    • add

      public static SIDimensions add(SIDimensions dim1, SIDimensions dim2)
      Add two SIDimensions and return the new SIDimensions. Usually, dimensions are added as a result of multiplication of scalars.
      Parameters:
      dim1 - SIDimensions; the first set of dimensions
      dim2 - SIDimensions; the second set of dimensions
      Returns:
      the new dimensions with the sum of the dimensions in the parameters
    • subtract

      public static SIDimensions subtract(SIDimensions dim1, SIDimensions dim2)
      Subtract an SIDimensions (dim2) from another SIDimensions (dim1) and return the new SIDimensions. Usually, dimensions are added as a result of division of scalars.
      Parameters:
      dim1 - SIDimensions; the first set of dimensions
      dim2 - SIDimensions; the second set of dimensions that will be subtracted from dim1
      Returns:
      the new dimensions with the difference of the dimensions in the parameters
    • isFractional

      public boolean isFractional()
      Indicate whether this SIDImensions contains one or more fractional dimensions.
      Returns:
      boolean; whether this SIDImensions contains one or more fractional dimensions
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString(boolean divided, String separator, String powerPrefix, String powerPostfix)
      Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.
      Parameters:
      divided - boolean; if true, return m/s2 for acceleration; if false return ms-2
      separator - String; add this string between successive units, e.g. kg.m.s-2 instead of kgms-2
      powerPrefix - String; the prefix for the power, e.g., "^" or "<sup>"
      powerPostfix - String; the postfix for the power, e.g., "</sup>"
      Returns:
      String; a formatted string for this SIDimensions
    • toString

      public String toString(boolean divided, boolean separator)
      Return a string such as "kgm/s2" or "kg.m/s2" or "kg.m.s-2" from this SIDimensions.
      Parameters:
      divided - boolean; if true, return m/s2 for acceleration; if false return ms-2
      separator - boolean; if true, add a period between successive units, e.g. kg.m.s-2 instead of kgms-2
      Returns:
      String; a formatted string describing this SIDimensions
    • toString

      public String toString(boolean divided, boolean separator, boolean power)
      Return a string such as "kgm/s2" or "kg.m/s^2" or "kg.m.s^-2" from this SIDimensions.
      Parameters:
      divided - boolean; if true, return m/s2 for acceleration; if false return ms-2
      separator - boolean; if true, add a period between successive units, e.g. kg.m.s-2 instead of kgms-2
      power - boolean; if true, add a ^ sign before the power, e.g., "kg.m^2/s^3" instead of "kg.m2/s3"
      Returns:
      String; a formatted string describing this SIDimensions
    • toHTMLString

      public String toHTMLString(boolean divided, boolean separator)
      Return a string such as "kgm/s2" or or "kg.m.s-2" from this SIDimensions.
      Parameters:
      divided - boolean; if true, return "m/s2" for acceleration; if false return "ms-2"
      separator - boolean; if true, add a period between successive units, e.g. kg.m.s-2
      Returns:
      String; a formatted string describing this SIDimensions
    • toString

      public String toString()
      Overrides:
      toString in class Object