|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.BasicItem<UnitData> net.sf.basedb.core.Unit
public class Unit
This class is used to represent a specific unit that can be
used with annotations. A unit must be related to the
reference unit of the quantity. See Quantity.getReferenceUnit()
for examples.
Quantity
,
Essentials of
the SI: Base & derived unitsField Summary | |
---|---|
static int |
MAX_SYMBOL_LENGTH
The maximum length of the display symbol that can be stored in the database. |
static Item |
TYPE
The type of item represented by this class. |
Fields inherited from interface net.sf.basedb.core.Nameable |
---|
MAX_DESCRIPTION_LENGTH, MAX_NAME_LENGTH |
Constructor Summary | |
---|---|
Unit(UnitData data)
Creates a unit item. |
Method Summary | ||
---|---|---|
void |
addSymbol(String symbol)
Add a symbol to this unit. |
|
void |
changeReferenceFactorAndOffset(double factor,
double offset)
Changes the factor and offset used for converting values in this unit into the reference unit. |
|
(package private) UnitData |
findOtherUnit(org.hibernate.Session session,
String symbol)
Find the unit with a given symbol that has the same quantity as this unit. |
|
double |
fromOther(double value,
Unit other)
Convert a value from another unit to this unit. |
|
double |
fromReferenceUnit(double value)
Convert a value from the reference unit to this unit. |
|
static Unit |
getById(DbControl dc,
int id)
Get a Unit object when you know the ID. |
|
String |
getDescription()
Get the description for the item. |
|
String |
getDisplaySymbol()
Get the display symbol to use when displaying values with this unit. |
|
|
getFormatter(Formatter<T> parent)
Create a formatter for formatting values with this unit. |
|
String |
getName()
Get the name of the item. |
|
static Unit |
getNew(DbControl dc,
Quantity quantity,
String displaySymbol)
Create a new Unit item. |
|
Quantity |
getQuantity()
Get the quantity this unit belongs to. |
|
static ItemQuery<Unit> |
getQuery()
Get a query configured to retrieve units. |
|
double |
getReferenceFactor()
Get the factor that is used for converting values in this unit into the reference unit of the quantity. |
|
double |
getReferenceOffset()
Get the offset that is used for converting values in this unit into the reference unit of the quantity. |
|
Set<String> |
getSymbols()
Get all symbols that are registered for this unit. |
|
Item |
getType()
Get the type of item represented by the object. |
|
Set<ItemProxy> |
getUsingItems()
Get all: AnnotationType :s using this unit as default unit
Annotation :s using this unit
|
|
boolean |
isRemoved()
Check if the removed flag is set for this item. |
|
boolean |
isUsed()
Check if: Annotation types are using this unit as default unit Annotations are using this unit |
|
(package private) void |
onBeforeCommit(Transactional.Action action)
Set property filters that use this unit to null when the unit is deleted. |
|
void |
removeSymbol(String symbol)
Remove a symbol from this unit. |
|
void |
setDescription(String description)
Set the description for the item. |
|
void |
setDisplaySymbol(String symbol)
Set the display symbol for this unit. |
|
void |
setName(String name)
Set the name of the item. |
|
private void |
setQuantity(Quantity quantity)
|
|
void |
setRemoved(boolean removed)
Set the removed flag for this item. |
|
void |
setSymbols(Set<String> symbols)
Set the symbols that should be registered for this unit. |
|
double |
toReferenceUnit(double value)
Convert a value from this unit to the reference unit. |
|
double |
toUnit(double value,
Unit other)
Convert a value from this unit to another unit. |
Methods inherited from class net.sf.basedb.core.BasicItem |
---|
addUsingItems, addUsingItems, checkPermission, equals, getData, getDbControl, getId, getPermissions, getPluginPermissions, getSessionControl, getVersion, hashCode, hasPermission, initPermissions, isDetached, isInDatabase, onAfterCommit, onAfterInsert, 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 |
---|
public static final Item TYPE
Item.UNIT
,
getType()
public static final int MAX_SYMBOL_LENGTH
setDisplaySymbol(String)
,
Constant Field ValuesConstructor Detail |
---|
Unit(UnitData data)
data
- the dataMethod Detail |
---|
public static Unit getNew(DbControl dc, Quantity quantity, String displaySymbol) throws BaseException
Unit
item. The unit will have
default values for the reference factor (1.0) and offset (0.0).
Use changeReferenceFactorAndOffset(double, double)
to change those.
dc
- The DbControl
which will be used for
permission checking and database accessquantity
- The quantity the unit belongs todisplaySymbol
- The symbol used when displaying values with
this unit
Unit
item
BaseException
- If there is an errorpublic static Unit getById(DbControl dc, int id) throws ItemNotFoundException, PermissionDeniedException, BaseException
Unit
object when you know the ID.
dc
- The DbControl
which will be used for
permission checking and database access.id
- The system ID of the item to load.
Unit
item
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
errorpublic static ItemQuery<Unit> getQuery()
ItemQuery
objectpublic boolean isUsed() throws BaseException
isUsed
in class BasicItem<UnitData>
BaseException
- If not able to tell if item is used or not.BasicItem.getUsingItems()
public Set<ItemProxy> getUsingItems()
AnnotationType
:s using this unit as default unit
Annotation
:s using this unit
getUsingItems
in class BasicItem<UnitData>
BasicItem.addUsingItems(Set, Item, org.hibernate.Query)
void onBeforeCommit(Transactional.Action action) throws BaseException
onBeforeCommit
in class BasicItem<UnitData>
BaseException
- If there is an errorTransactional
,
Core API overview - Transaction handling,
Coding rules and guidelines for item classespublic Item getType()
Identifiable
Item
enumeration.
getType
in interface Identifiable
public boolean isRemoved()
Removable
isRemoved
in interface Removable
public void setRemoved(boolean removed) throws PermissionDeniedException
Removable
setRemoved
in interface Removable
removed
- TRUE if the item should be flagged as removed,
FALSE otherwise
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 FALSEpublic String getName()
Nameable
getName
in interface Nameable
String
with the name of the itempublic void setName(String name) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_NAME_LENGTH
constant.
setName
in interface Nameable
name
- The new name for the item
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
constantpublic String getDescription()
Nameable
getDescription
in interface Nameable
String
with a description of the itempublic void setDescription(String description) throws PermissionDeniedException, InvalidDataException
Nameable
Nameable.MAX_DESCRIPTION_LENGTH
constant.
setDescription
in interface Nameable
description
- The new description for the item
PermissionDeniedException
- If the logged in user doesn't
have write permission
InvalidDataException
- If the description longer
than specified by the Nameable.MAX_DESCRIPTION_LENGTH
constantpublic Quantity getQuantity()
private void setQuantity(Quantity quantity)
public String getDisplaySymbol()
public void setDisplaySymbol(String symbol) throws PermissionDeniedException, InvalidDataException
removeSymbol(String)
to do that.
symbol
- The symbol
PermissionDeniedException
- If the logged in user doesn't have
write permission
InvalidDataException
- If the new value null or longer than
MAX_SYMBOL_LENGTH
public Set<String> getSymbols()
public void setSymbols(Set<String> symbols)
Quantity
. Symbols that
are not in the given set will be unregistered except for the display
symbol.
symbols
- A set with the symbolspublic void addSymbol(String symbol)
symbol
- The symbol to addpublic void removeSymbol(String symbol)
symbol
- The symbol to removepublic double getReferenceOffset()
Quantity.getReferenceUnit()
for a description of how the
values are converted.
changeReferenceFactorAndOffset(double, double)
public double getReferenceFactor()
Quantity.getReferenceUnit()
for a description of how the
values are converted.
changeReferenceFactorAndOffset(double, double)
public void changeReferenceFactorAndOffset(double factor, double offset)
factor
- The new factoroffset
- The new offsetpublic double toReferenceUnit(double value)
value
- The value in this unit
public double fromReferenceUnit(double value)
value
- The reference value
public double toUnit(double value, Unit other)
other.fromReferenceUnit(this.toReferenceUnit(value))
.
value
- The value in this unitother
- The other unit
public double fromOther(double value, Unit other)
this.fromReferenceUnit(other.toReferenceUnit(value))
value
- The value in the other unitother
- The other unit
public <T> Formatter<T> getFormatter(Formatter<T> parent)
PrefixSuffixFormatter
to append the unit symbol.
parent
- The parent formatter for formatting the actual values
UnitData findOtherUnit(org.hibernate.Session session, String symbol)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |