2.17.2: 2011-06-17

net.sf.basedb.core
Class Quantity

java.lang.Object
  extended by net.sf.basedb.core.BasicItem<QuantityData>
      extended by net.sf.basedb.core.Quantity
All Implemented Interfaces:
AccessControlled, Identifiable, Nameable, Removable, SystemItem

public class Quantity
extends BasicItem<QuantityData>
implements Nameable, SystemItem, Removable

This class is used to represent a quantity for specifying units to annotations.

Version:
2.9
Author:
Nicklas
See Also:
Unit, Essentials of the SI: Base & derived units
Last modified
$Date: 2009-04-06 14:15:21 +0200 (Mon, 06 Apr 2009) $

Field Summary
static String ABSORBED_DOSE
          The id for the Quantity object representing absorbed dose.
static String ACCELERATION
          The id for the Quantity object representing acceleration.
static String ANGLE
          The id for the Quantity object representing angle.
static String AREA
          The id for the Quantity object representing area.
static String CAPACITANCE
          The id for the Quantity object representing capacitance.
static String CHARGE
          The id for the Quantity object representing electrical charge.
static String CURRENT
          The id for the Quantity object representing electric current.
static String DENSITY
          The id for the Quantity object representing density.
static String ENERGY
          The id for the Quantity object representing energy.
static String EQUIVALENT_DOSE
          The id for the Quantity object representing equivalent dose.
static String FLOW_RATE
          The id for the Quantity object representing flow rate.
static String FORCE
          The id for the Quantity object representing force.
static String FRACTION
          The id for the Quantity object representing fractions.
static String FREQUENCY
          The id for the Quantity object representing frequency.
static String LENGTH
          The id for the Quantity object representing length.
static String MAGNETIC_FIELD
          The id for the Quantity object representing magnetic field.
static String MAGNETIC_FLUX
          The id for the Quantity object representing magnetic flux.
static String MASS
          The id for the Quantity object representing mass.
static int MAX_REFERENCE_UNIT_LENGTH
          The maximum length of the reference unit that can be stored in the database.
static String MOMENTUM
          The id for the Quantity object representing momentum.
static String POTENTIAL
          The id for the Quantity object representing electrical potential.
static String POWER
          The id for the Quantity object representing power.
static String PRESSURE
          The id for the Quantity object representing pressure.
static String RADIOACTIVITY
          The id for the Quantity object representing radioactivity.
static String RESISTANCE
          The id for the Quantity object representing electrical resistance.
static String STORAGE_SIZE
          The id for the Quantity object representing storage sizes.
static String SUBSTANCE
          The id for the Quantity object representing "amount of substance".
static String TEMPERATURE
          The id for the Quantity object representing temperature.
static String THERMAL_CONDUCTIVITY
          The id for the Quantity object representing thermal conductivity.
static String TIME
          The id for the Quantity object representing time.
static String TORGUE
          The id for the Quantity object representing torque.
static Item TYPE
          The type of item represented by this class.
static String VELOCITY
          The id for the Quantity object representing velocity.
static String VOLUME
          The id for the Quantity object representing volume.
 
Fields inherited from interface net.sf.basedb.core.Nameable
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH
 
Fields inherited from interface net.sf.basedb.core.SystemItem
MAX_SYSTEM_ID_LENGTH
 
Constructor Summary
Quantity(QuantityData data)
          Creates a quantity item.
 
Method Summary
static Quantity getById(DbControl dc, int id)
          Get a Quantity object when you know the ID.
 String getDescription()
          Get the description for the item.
 String getName()
          Get the name of the item.
static Quantity getNew(DbControl dc, String referenceUnit)
          Create a new Quantity item.
static ItemQuery<Quantity> getQuery()
          Get a query configured to retrieve quantities.
 String getReferenceUnit()
          The reference unit describes the unit that all other units must relate to.
 String getSystemId()
          Get the system id for the item.
 Item getType()
          Get the type of item represented by the object.
(package private)  UnitData getUnit(org.hibernate.Session session, String symbol)
          Get the unit with a given symbol, or null if no unit is found.
 Unit getUnit(String symbol)
          Get a a unit by symbol, also checking among the aliases.
 ItemQuery<Unit> getUnits()
          Get a query that returns all units of this quantity.
 Set<ItemProxy> getUsingItems()
          Get all: Unit:s for this quantity AnnotationType:s using this quantity
(package private)  void initPermissions(int granted, int denied)
          If this is a system quantity, delete and create permissions are revoked.
 boolean isRemoved()
          Check if the removed flag is set for this item.
 boolean isSystemItem()
          Check if the item is a system item or not.
 boolean isUsed()
          Check if: Units for this quantity exists.
 void setDescription(String description)
          Set the description for the item.
 void setName(String name)
          Set the name of the item.
 void setReferenceUnit(String referenceUnit)
          Sets the reference unit.
 void setRemoved(boolean removed)
          Set the removed flag for this item.
 
Methods inherited from class net.sf.basedb.core.BasicItem
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getVersion, hashCode, hasPermission, isDetached, isInDatabase, onAfterCommit, onAfterInsert, onBeforeCommit, onRollback, setDbControl, setProjectDefaults, toString, toTransferable, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Identifiable
getId, getVersion
 
Methods inherited from interface net.sf.basedb.core.AccessControlled
checkPermission, getPermissions, hasPermission
 

Field Detail

TYPE

public static final Item TYPE
The type of item represented by this class.

See Also:
Item.QUANTITY, getType()

LENGTH

public static final String LENGTH
The id for the Quantity object representing length.

See Also:
"http://physics.nist.gov/cuu/Units/meter.html", Constant Field Values

MASS

public static final String MASS
The id for the Quantity object representing mass.

See Also:
"http://physics.nist.gov/cuu/Units/kilogram.html", Constant Field Values

TIME

public static final String TIME
The id for the Quantity object representing time.

See Also:
"http://physics.nist.gov/cuu/Units/second.html", Constant Field Values

TEMPERATURE

public static final String TEMPERATURE
The id for the Quantity object representing temperature.

See Also:
"http://physics.nist.gov/cuu/Units/kelvin.html", Constant Field Values

CURRENT

public static final String CURRENT
The id for the Quantity object representing electric current.

See Also:
"http://physics.nist.gov/cuu/Units/ampere.html", Constant Field Values

SUBSTANCE

public static final String SUBSTANCE
The id for the Quantity object representing "amount of substance".

See Also:
"http://physics.nist.gov/cuu/Units/mole.html", Constant Field Values

AREA

public static final String AREA
The id for the Quantity object representing area.

See Also:
"http://en.wikipedia.org/wiki/Area", Constant Field Values

VOLUME

public static final String VOLUME
The id for the Quantity object representing volume.

See Also:
"http://en.wikipedia.org/wiki/Volume", Constant Field Values

VELOCITY

public static final String VELOCITY
The id for the Quantity object representing velocity.

See Also:
"http://en.wikipedia.org/wiki/Speed", Constant Field Values

ANGLE

public static final String ANGLE
The id for the Quantity object representing angle.

See Also:
"http://en.wikipedia.org/wiki/Radian", Constant Field Values

FORCE

public static final String FORCE
The id for the Quantity object representing force.

See Also:
"http://en.wikipedia.org/wiki/Newton", Constant Field Values

FREQUENCY

public static final String FREQUENCY
The id for the Quantity object representing frequency.

See Also:
"http://en.wikipedia.org/wiki/Newton", Constant Field Values

DENSITY

public static final String DENSITY
The id for the Quantity object representing density.

See Also:
"http://en.wikipedia.org/wiki/Density", Constant Field Values

ENERGY

public static final String ENERGY
The id for the Quantity object representing energy.

See Also:
"http://en.wikipedia.org/wiki/Joule", Constant Field Values

POWER

public static final String POWER
The id for the Quantity object representing power.

See Also:
"http://en.wikipedia.org/wiki/Watt", Constant Field Values

PRESSURE

public static final String PRESSURE
The id for the Quantity object representing pressure.

See Also:
"http://en.wikipedia.org/wiki/Pascal_(unit)", Constant Field Values

POTENTIAL

public static final String POTENTIAL
The id for the Quantity object representing electrical potential.

See Also:
"http://en.wikipedia.org/wiki/Volt", Constant Field Values

RESISTANCE

public static final String RESISTANCE
The id for the Quantity object representing electrical resistance.

See Also:
"http://en.wikipedia.org/wiki/Ohm", Constant Field Values

CHARGE

public static final String CHARGE
The id for the Quantity object representing electrical charge.

See Also:
"http://en.wikipedia.org/wiki/Coulomb", Constant Field Values

CAPACITANCE

public static final String CAPACITANCE
The id for the Quantity object representing capacitance.

See Also:
"http://en.wikipedia.org/wiki/Farad", Constant Field Values

MAGNETIC_FIELD

public static final String MAGNETIC_FIELD
The id for the Quantity object representing magnetic field.

See Also:
"http://en.wikipedia.org/wiki/Tesla_(unit)", Constant Field Values

MAGNETIC_FLUX

public static final String MAGNETIC_FLUX
The id for the Quantity object representing magnetic flux.

See Also:
"http://en.wikipedia.org/wiki/Weber_(unit)", Constant Field Values

ABSORBED_DOSE

public static final String ABSORBED_DOSE
The id for the Quantity object representing absorbed dose.

See Also:
"http://en.wikipedia.org/wiki/Gray_(unit)", Constant Field Values

EQUIVALENT_DOSE

public static final String EQUIVALENT_DOSE
The id for the Quantity object representing equivalent dose.

See Also:
"http://en.wikipedia.org/wiki/Sievert", Constant Field Values

RADIOACTIVITY

public static final String RADIOACTIVITY
The id for the Quantity object representing radioactivity.

See Also:
"http://en.wikipedia.org/wiki/Becquerel", Constant Field Values

FRACTION

public static final String FRACTION
The id for the Quantity object representing fractions.

See Also:
"http://en.wikipedia.org/wiki/Parts-per_notation", Constant Field Values

ACCELERATION

public static final String ACCELERATION
The id for the Quantity object representing acceleration.

See Also:
"http://en.wikipedia.org/wiki/Acceleration", Constant Field Values

TORGUE

public static final String TORGUE
The id for the Quantity object representing torque.

See Also:
"http://en.wikipedia.org/wiki/Torque", Constant Field Values

MOMENTUM

public static final String MOMENTUM
The id for the Quantity object representing momentum.

See Also:
"http://en.wikipedia.org/wiki/Momentum", Constant Field Values

FLOW_RATE

public static final String FLOW_RATE
The id for the Quantity object representing flow rate.

See Also:
"http://en.wikipedia.org/wiki/Volumetric_flow_rate", Constant Field Values

THERMAL_CONDUCTIVITY

public static final String THERMAL_CONDUCTIVITY
The id for the Quantity object representing thermal conductivity.

See Also:
"http://en.wikipedia.org/wiki/Thermal_conductivity", Constant Field Values

STORAGE_SIZE

public static final String STORAGE_SIZE
The id for the Quantity object representing storage sizes.

See Also:
"http://en.wikipedia.org/wiki/Byte", Constant Field Values

MAX_REFERENCE_UNIT_LENGTH

public static final int MAX_REFERENCE_UNIT_LENGTH
The maximum length of the reference unit that can be stored in the database.

See Also:
setReferenceUnit(String), Constant Field Values
Constructor Detail

Quantity

Quantity(QuantityData data)
Creates a quantity item.

Parameters:
data - the data
Method Detail

getNew

public static Quantity getNew(DbControl dc,
                              String referenceUnit)
                       throws BaseException
Create a new Quantity item.

Parameters:
dc - The DbControl which will be used for permission checking and database access
referenceUnit - The reference unit which all units must relate to
Returns:
The new Quantity item
Throws:
BaseException - If there is an error

getById

public static Quantity getById(DbControl dc,
                               int id)
                        throws ItemNotFoundException,
                               PermissionDeniedException,
                               BaseException
Get a Quantity object when you know the ID.

Parameters:
dc - The DbControl which will be used for permission checking and database access.
id - The system ID of the item to load.
Returns:
The Quantity item
Throws:
ItemNotFoundException - This exception is thrown if an item with the specified ID is not found
PermissionDeniedException - This exception is thrown if the logged in user doesn't have read permission to the item
BaseException - This exception is thrown if there is another error

getQuery

public static ItemQuery<Quantity> getQuery()
Get a query configured to retrieve quantities.

Returns:
An ItemQuery object

isUsed

public boolean isUsed()
               throws BaseException
Check if:

Overrides:
isUsed in class BasicItem<QuantityData>
Returns:
TRUE if this item is used, FALSE otherwise
Throws:
BaseException - If not able to tell if item is used or not.
See Also:
BasicItem.getUsingItems()

getUsingItems

public Set<ItemProxy> getUsingItems()
Get all:

initPermissions

void initPermissions(int granted,
                     int denied)
               throws BaseException
If this is a system quantity, delete and create permissions are revoked.

Overrides:
initPermissions in class BasicItem<QuantityData>
Parameters:
granted - Permissions that have been granted by the subclass
denied - Permissions that have been denied by the subclass
Throws:
BaseException - If the permissions couldn't be initialised

getType

public Item getType()
Description copied from interface: Identifiable
Get the type of item represented by the object. The returned value is one of the values defined in the Item enumeration.

Specified by:
getType in interface Identifiable
Returns:
A value indicating the type of item

isRemoved

public boolean isRemoved()
Description copied from interface: Removable
Check if the removed flag is set for this item.

Specified by:
isRemoved in interface Removable
Returns:
TRUE if the item is flagged as removed, FALSE otherwise

setRemoved

public void setRemoved(boolean removed)
                throws PermissionDeniedException
Description copied from interface: Removable
Set the removed flag for this item.

Specified by:
setRemoved in interface Removable
Parameters:
removed - TRUE if the item should be flagged as removed, FALSE otherwise
Throws:
PermissionDeniedException - If the logged in user doesn't have Permission.DELETE permission for setting the flag to TRUE or Permission.WRITE permission for setting the flag to FALSE

getSystemId

public String getSystemId()
Description copied from interface: SystemItem
Get the system id for the item.

Specified by:
getSystemId in interface SystemItem
Returns:
The id of the item or null if it is not a system item

isSystemItem

public boolean isSystemItem()
Description copied from interface: SystemItem
Check if the item is a system item or not. A system item have a non-null value for the system id.

Specified by:
isSystemItem in interface SystemItem
Returns:
TRUE if this item is a system item, FALSE otherwise

getName

public String getName()
Description copied from interface: Nameable
Get the name of the item.

Specified by:
getName in interface Nameable
Returns:
A String with the name of the item

setName

public void setName(String name)
             throws PermissionDeniedException,
                    InvalidDataException
Description copied from interface: Nameable
Set the name of the item. The name cannot be null and mustn't be longer than the value specified by the Nameable.MAX_NAME_LENGTH constant.

Specified by:
setName in interface Nameable
Parameters:
name - The new name for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the name is null or longer than specified by the Nameable.MAX_NAME_LENGTH constant

getDescription

public String getDescription()
Description copied from interface: Nameable
Get the description for the item.

Specified by:
getDescription in interface Nameable
Returns:
A String with a description of the item

setDescription

public void setDescription(String description)
                    throws PermissionDeniedException,
                           InvalidDataException
Description copied from interface: Nameable
Set the description for the item. The description can be null but mustn't be longer than the value specified by the Nameable.MAX_DESCRIPTION_LENGTH constant.

Specified by:
setDescription in interface Nameable
Parameters:
description - The new description for the item
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the description longer than specified by the Nameable.MAX_DESCRIPTION_LENGTH constant

getReferenceUnit

public String getReferenceUnit()
The reference unit describes the unit that all other units must relate to. When setting Unit.getReferenceFactor() and Unit.getReferenceOffset() for a unit the following formula should be used:
1 reference unit * factor + offset = 1 of the unit
For example:
1 meter * 0.001 + 0 = 1 millimeter
1 kelvin * 1 + 273.15 = 1 °Celsius

See Also:
Unit.getReferenceFactor(), Unit.getReferenceOffset()

setReferenceUnit

public void setReferenceUnit(String referenceUnit)
                      throws PermissionDeniedException,
                             InvalidDataException
Sets the reference unit.

Parameters:
referenceUnit -
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission
InvalidDataException - If the value is null, or longer than MAX_REFERENCE_UNIT_LENGTH

getUnits

public ItemQuery<Unit> getUnits()
Get a query that returns all units of this quantity.

Returns:
An ItemQuery object

getUnit

public Unit getUnit(String symbol)
Get a a unit by symbol, also checking among the aliases. Note! This method always results in a database query. If you need to lookup lots of symbols, use a UnitCache instead which has better performance.

Parameters:
symbol - The symbol

getUnit

UnitData getUnit(org.hibernate.Session session,
                 String symbol)
Get the unit with a given symbol, or null if no unit is found.


2.17.2: 2011-06-17