org.ujoframework.extensions
Class Property<UJO extends Ujo,VALUE>

java.lang.Object
  extended by org.ujoframework.extensions.Property<UJO,VALUE>
All Implemented Interfaces:
java.lang.CharSequence, UjoProperty<UJO,VALUE>
Direct Known Subclasses:
BeanProperty, FactoryProperty, FieldProperty, ListProperty, RelationToMany, RelationToOne

public class Property<UJO extends Ujo,VALUE>
extends java.lang.Object
implements UjoProperty<UJO,VALUE>

The main implementation of the interface UjoProperty.

Author:
Pavel Ponec
See Also:
AbstractUjo

Constructor Summary
protected Property()
          Protected constructor
protected Property(java.lang.String name, java.lang.Class<VALUE> type, int index)
          Constructor with an property order
protected Property(java.lang.String name, VALUE value, int index)
          Constructor with an property order
 
Method Summary
protected static int _nextSequence()
          Returns a next property index by a synchronized method.
<VALUE_PAR>
UjoProperty<UJO,VALUE_PAR>
add(UjoProperty<? extends VALUE,VALUE_PAR> property)
          Create new composite (indirect) instance.
 int compareTo(UjoProperty p)
          Compare to another UjoProperty object by a index code.
 void copy(UJO from, UJO to)
          Copy a value from the first UJO object to second one.
 UjoProperty<UJO,VALUE> descending()
          Create a new instance of the indirect property with a descending direction of order.
 boolean equals(UJO ujo, VALUE value)
          Returns true, if the property value equals to a parameter value.
 VALUE getDefault()
          Returns a Default property value.
 int getIndex()
          Index of Property
 java.lang.String getName()
          Name of Property
 java.lang.Class<VALUE> getType()
          Type of Property
 VALUE getValue(UJO ujo)
          It is a basic method for getting an appropriate type safe value from an MapUjo object.
 char charAt(int index)
          A char from Name
protected  void checkAttribs()
          Check properties
protected  Property<UJO,VALUE> init(java.lang.String name, java.lang.Class<VALUE> type, VALUE defaultValue, int index, java.lang.Boolean lock)
          Property initialization.
 boolean isAscending()
          A flag for a direction of sorting.
 boolean isDefault(UJO ujo)
          Indicates whether a parameter value of the ujo "equal to" this default value.
 boolean isDirect()
          Returns a true value, if the property contains more properties.
 boolean isTypeOf(java.lang.Class type)
          Returns true if the property type is a type or subtype of the parameter class.
 int length()
          Length of the Name
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, java.lang.Class<VALUE> type)
          Returns a new instance of property where the default value is null.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, java.lang.Class<VALUE> type, int index)
          Returns a new instance of property where the default value is null.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, java.lang.Class<VALUE> type, VALUE value, int index, boolean lock)
          Returns a new instance of property where the default value is null.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, VALUE value)
          A Property Factory where a property type is related from from default value.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(java.lang.String name, VALUE value, int index)
          A Property Factory where a property type is related from from default value.
static
<UJO extends Ujo,VALUE>
UjoProperty<UJO,VALUE>
newInstance(UjoProperty p)
          A Property Factory where a property type is related from from default value.
static
<UJO extends Ujo,VALUE>
Property<UJO,VALUE>
newInstance(UjoProperty p, int index)
          A Property Factory where a property type is related from from default value.
 VALUE of(UJO ujo)
          A shortcut for the method getValue(Ujo).
 void setValue(UJO ujo, VALUE value)
          It is a basic method for setting an appropriate type safe value to an MapUjo object.
 void setValueFromDefault(UJO ujo)
          Assing a value from the default value.
 java.lang.CharSequence subSequence(int start, int end)
          Sub sequence from the Name
 java.lang.String toString()
          Returns a name of Property
<PROPERTY extends Property>
PROPERTY
writeDefault(VALUE value)
          Assign a Default value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Property

protected Property(java.lang.String name,
                   java.lang.Class<VALUE> type,
                   int index)
Constructor with an property order

Parameters:
name -
type -
index - On order of the property.

Property

protected Property(java.lang.String name,
                   VALUE value,
                   int index)
Constructor with an property order

Parameters:
name -
index - On order of the property.

Property

protected Property()
Protected constructor

Method Detail

_nextSequence

protected static final int _nextSequence()
Returns a next property index by a synchronized method. The UJO property indexed by this method may not be in continuous series however numbers have the upward direction always.


init

protected final Property<UJO,VALUE> init(java.lang.String name,
                                         java.lang.Class<VALUE> type,
                                         VALUE defaultValue,
                                         int index,
                                         java.lang.Boolean lock)
Property initialization.

Parameters:
name - Replace the Name of property if the one is NULL.
index - Replace index always, the value -1 invoke a next number from the internal sequencer.
type - Replace the Type of property if the one is NULL.
defaultValue - Replace the Optional default value if the one is NULL.
lock - Lock the property.

checkAttribs

protected void checkAttribs()
Check properties


getName

public final java.lang.String getName()
Name of Property

Specified by:
getName in interface UjoProperty<UJO extends Ujo,VALUE>

getType

public final java.lang.Class<VALUE> getType()
Type of Property

Specified by:
getType in interface UjoProperty<UJO extends Ujo,VALUE>

getIndex

public final int getIndex()
Index of Property

Specified by:
getIndex in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
ArrayUjo, UjoManager.readProperties(Class)

setValue

public final void setValue(UJO ujo,
                           VALUE value)
It is a basic method for setting an appropriate type safe value to an MapUjo object.
For the setting value is used internally a method Ujo.writeValue(org.ujoframework.UjoProperty, java.lang.Object)

Specified by:
setValue in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
Ujo.writeValue(org.ujoframework.UjoProperty, java.lang.Object)

getValue

public final VALUE getValue(UJO ujo)
It is a basic method for getting an appropriate type safe value from an MapUjo object.
For the getting value is used internally a method Ujo.readValue(org.ujoframework.UjoProperty) .
Note: this method replaces the value of null for default

Specified by:
getValue in interface UjoProperty<UJO extends Ujo,VALUE>
Parameters:
ujo - If a NULL parameter is used then an exception NullPointerException is throwed.
Returns:
Returns a type safe value from the ujo object.
See Also:
Ujo.readValue(UjoProperty)

of

public final VALUE of(UJO ujo)
A shortcut for the method getValue(Ujo).

Specified by:
of in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
getValue(Ujo)

getDefault

public VALUE getDefault()
Returns a Default property value. The value replace the null value in the method Ujo.readValue(...). If the default value is not modified, returns the null.

Specified by:
getDefault in interface UjoProperty<UJO extends Ujo,VALUE>
See Also:
Ujo.readValue(UjoProperty)

writeDefault

public <PROPERTY extends Property> PROPERTY writeDefault(VALUE value)
Assign a Default value. The default value may be modified after locking - at your own risk.
WARNING: the change of the default value modifies all values in all instances with the null value of the current property!


setValueFromDefault

public void setValueFromDefault(UJO ujo)
Assing a value from the default value.


isDefault

public boolean isDefault(UJO ujo)
Indicates whether a parameter value of the ujo "equal to" this default value.

Specified by:
isDefault in interface UjoProperty<UJO extends Ujo,VALUE>

isDirect

public final boolean isDirect()
Returns a true value, if the property contains more properties. The composite property is excluded from from function Ujo.readProperties() by default.

Specified by:
isDirect in interface UjoProperty<UJO extends Ujo,VALUE>

isAscending

public boolean isAscending()
A flag for a direction of sorting. This method returns true always.

Specified by:
isAscending in interface UjoProperty<UJO extends Ujo,VALUE>
Since:
0.85
See Also:
UjoComparator

descending

public UjoProperty<UJO,VALUE> descending()
Create a new instance of the indirect property with a descending direction of order.

Specified by:
descending in interface UjoProperty<UJO extends Ujo,VALUE>
Returns:
returns a new instance of the indirect UjoProperty
Since:
0.85
See Also:
isAscending(), UjoComparator

add

public <VALUE_PAR> UjoProperty<UJO,VALUE_PAR> add(UjoProperty<? extends VALUE,VALUE_PAR> property)
Create new composite (indirect) instance.

Specified by:
add in interface UjoProperty<UJO extends Ujo,VALUE>
Since:
0.92

copy

public void copy(UJO from,
                 UJO to)
Copy a value from the first UJO object to second one. A null value is not replaced by the default.

Specified by:
copy in interface UjoProperty<UJO extends Ujo,VALUE>

isTypeOf

public boolean isTypeOf(java.lang.Class type)
Returns true if the property type is a type or subtype of the parameter class.

Specified by:
isTypeOf in interface UjoProperty<UJO extends Ujo,VALUE>

equals

public boolean equals(UJO ujo,
                      VALUE value)
Returns true, if the property value equals to a parameter value. The property value can be null.

Specified by:
equals in interface UjoProperty<UJO extends Ujo,VALUE>
Parameters:
ujo - A basic Ujo.
value - Null value is supported.
Returns:
Accordance

compareTo

public int compareTo(UjoProperty p)
Compare to another UjoProperty object by a index code.


charAt

public char charAt(int index)
A char from Name

Specified by:
charAt in interface java.lang.CharSequence

length

public int length()
Length of the Name

Specified by:
length in interface java.lang.CharSequence

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Sub sequence from the Name

Specified by:
subSequence in interface java.lang.CharSequence

toString

public final java.lang.String toString()
Returns a name of Property

Specified by:
toString in interface java.lang.CharSequence
Specified by:
toString in interface UjoProperty<UJO extends Ujo,VALUE>
Overrides:
toString in class java.lang.Object

newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      java.lang.Class<VALUE> type,
                                                                      VALUE value,
                                                                      int index,
                                                                      boolean lock)
Returns a new instance of property where the default value is null. The method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      java.lang.Class<VALUE> type,
                                                                      int index)
Returns a new instance of property where the default value is null. The method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      java.lang.Class<VALUE> type)
Returns a new instance of property where the default value is null. The method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      VALUE value,
                                                                      int index)
A Property Factory where a property type is related from from default value. Method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(java.lang.String name,
                                                                      VALUE value)
A Property Factory where a property type is related from from default value. Method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> Property<UJO,VALUE> newInstance(UjoProperty p,
                                                                      int index)
A Property Factory where a property type is related from from default value. Method assigns a next property index.


newInstance

public static <UJO extends Ujo,VALUE> UjoProperty<UJO,VALUE> newInstance(UjoProperty p)
A Property Factory where a property type is related from from default value.
Warning: Method does not lock the property so you must call AbstractUjo.init(..) method after initialization!



Copyright © 2010. All Rights Reserved.