Holger's Java API

## com.antelmann.db
Class PropertyEntryImpl

    java.lang.Object
      com.antelmann.db.AbstractDBEntry
          com.antelmann.db.PropertyEntryImpl

All Implemented Interfaces:
  DBEntry, PropertyEntry, DetailedString, Serializable

Direct Known Subclasses:
  BaseDocument, ContactImpl, EntryHeader, ImageURLEntry, PropertyEntryWithAddress, RowItem, UserImpl

    public class PropertyEntryImpl

extends AbstractDBEntry
implements PropertyEntry, DetailedString

This class represents a default PropertyEntry implementation that can serve as a base class for PropertyEntry implementations. In addition this implementation optionally monitors changes on its properties. Finally, this class also provides support for undo/redo.

Author:
  Holger Antelmann
See Also:
  Serialized Form

Field Summary
`protected PropertyChangeSupport` `propertyChangeSupport` access to the embedded property change support; this variable is initially null (until initialized by `setChangeListenerSupport(boolean)`)
`protected HashMap<String,Object>` `props` provides unmonitored and unchecked access to the properties for the inheriting class; altering the properties directly would circumvent the property change support.
`protected UndoManager` `um` access to the embedded undo/redo support; this variable is initially null (until initialized by `setUndoSupported(boolean)`)
`protected VetoableChangeSupport` `vcs` access to the embedded vetoable change support; this variable is initially null (until initialized by `setVetoableChangeSupport(boolean)`)

Fields inherited from interface com.antelmann.db.DBEntry
`ENTRY_FLAVOR, ENTRY_LIST_FLAVOR`

Constructor Summary
`PropertyEntryImpl()` convenience constructor: creates an instance with a serializable random UUID
`PropertyEntryImpl(Object id)`
`PropertyEntryImpl(Object id, Map<String,?> properties)` the given properties do NOT run through the property change check; they ought to be checked once the extending class is fully initialized
`PropertyEntryImpl(Object id, PropertyEntry entity)` all properties from the given entity are copied into this entity; the given properties do NOT run through the property change check.

Method Summary
`void` `addPropertyChangeListener(PropertyChangeListener listener)`
`void` `addPropertyChangeListener(String propertyKey, PropertyChangeListener listener)`
`void` `addVetoableChangeListener(String propertyKey, VetoableChangeListener listener)`
`void` `addVetoableChangeListener(VetoableChangeListener listener)`
`Properties` `asProperties()`
`boolean` `canRedo()`
`boolean` `canUndo()`
`protected void` `checkPropertyChange(String key, Object value)` determines whether a property can be changed as given.
`void` `clearProperties()` clears all properties by removing every key separately (as a removal may not be allowed by checkPropertyChange())
`protected boolean` `containsPropertyText(String text)` searches within the property values (based on toString()) for the given text case-insensivitely
`boolean` `containsValuePattern(CharSequence pattern)` searches through all properties and returns true only if the given pattern is found within the String values of the properties
`boolean` `equalWithProperties(PropertyEntry entry)` checks (next to equals) whether all properties are the same
`static boolean` `equalWithProperties(PropertyEntry entry1, PropertyEntry entry2)`
`boolean` `getBoolean(String key)`
`Number` `getNumber(String key)` convenience method; returns either the property value of the given key or 0 if the property value is null
`Map<String,Object>` `getProperties()` generates a new view on each call; altering properties can be done via the `setProperty(String, Object)` method
`Object` `getProperty(String key)` allows access to some property; may return null if not set
`Object` `getProperty(String key, Object defaultValue)` if the given key maps to a null value, the defaultValue is returned instead
`PropertyChangeListener[]` `getPropertyChangeListeners()`
`static Comparator<PropertyEntry>` `getPropertyComparator(String propertyKey)`
`static PatternExtractor<PropertyEntry,Object>` `getPropertyExtractor(String propertyKey)`

`static

`<T> PatternExtractor<PropertyEntry,T>`

`

`getPropertyExtractor(String propertyKey, Class<T> type)`
returns a PatternExtractor based on the value of the given property

`String[]` `getPropertyKeys()` note that an existing key may still map to a null value
`static PatternExtractor<PropertyEntry,String>` `getStringExtractor(String propertyKey)` returns a PatternExtractor based on the String value of the given property
`VetoableChangeListener[]` `getVetoableChangeListeners()`
`boolean` `isCaseInsensitive()` determines whether this instance behaves case-insensitive in regards to the property keys.
`boolean` `isChangeListenerSupportEnabled()` determines whether listener support is enabled on this object (false by default)
`static boolean` `isKeyIn(String key, String... keyCandidates)` convenience method to more easily check keys in inheriting classes
`boolean` `isUndoSupport()`
`boolean` `isVetoableChangeSupportEnabled()`
`void` `putAll(Map<?,?> map)` all imported properties are checked by `checkPropertyChange()`
`boolean` `redo()`
`Object` `removeProperty(String key)` removes the given key from the properties
`void` `removePropertyChangeListener(PropertyChangeListener listener)`
`void` `removeVetoableChangeListener(VetoableChangeListener listener)`
`void` `setAllFrom(Map<?,?> map)`
`void` `setCaseInsensitive(boolean caseInsensitive)`
`void` `setChangeListenerSupport(boolean flag)` allows to enable/disable listener support on this object (disabled by default).
`Object` `setProperty(String key, Object value)` edit/set a given property value based on the given key.
`void` `setUndoSupported(boolean flag)` if one wanted to customize the UndoManager upon creation, this would be the method to override
`protected void` `setVetoableChangeSupport(boolean flag)` allows to enable/disable vetoable change support on this object (disabled by default).
`String` `toDetailedString()` provides full details of this instance in a String.
`boolean` `undo()`
`void` `verifyProperties()` This default implementation simply runs all existing properties through `checkPropertyChange(String, Object)`.

Methods inherited from class com.antelmann.db.AbstractDBEntry
`equals, getID, hashCode, hashEntry, sameEntry, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.antelmann.db.DBEntry
`getID`

Field Detail

### props

    protected final HashMap<String,Object> props

  provides unmonitored and unchecked access to the properties for the inheriting class; altering the properties directly would circumvent the property change support. Also, this instance is a subclass of HashMap for that it overrides put, get and remove to support `isCaseInsensitive()`.

### propertyChangeSupport

    protected PropertyChangeSupport propertyChangeSupport

  access to the embedded property change support; this variable is initially null (until initialized by `setChangeListenerSupport(boolean)`)

  See Also:
    `setChangeListenerSupport(boolean)`

### vcs

    protected VetoableChangeSupport vcs

  access to the embedded vetoable change support; this variable is initially null (until initialized by `setVetoableChangeSupport(boolean)`)

  See Also:
    `setVetoableChangeSupport(boolean)`

### um

    protected UndoManager um

  access to the embedded undo/redo support; this variable is initially null (until initialized by `setUndoSupported(boolean)`)

Constructor Detail

### PropertyEntryImpl

    public PropertyEntryImpl()

  convenience constructor: creates an instance with a serializable random UUID

### PropertyEntryImpl

    public PropertyEntryImpl(Object id)

### PropertyEntryImpl

    public PropertyEntryImpl(Object id,
                             PropertyEntry entity)

  all properties from the given entity are copied into this entity; the given properties do NOT run through the property change check. If needed, they ought to be checked once the extending class is fully initialized.

  See Also:
    `checkPropertyChange(String, Object)`, `verifyProperties()`

### PropertyEntryImpl

    public PropertyEntryImpl(Object id,
                             Map<String,?> properties)

  the given properties do NOT run through the property change check; they ought to be checked once the extending class is fully initialized

  See Also:
    `checkPropertyChange(String, Object)`, `verifyProperties()`

Method Detail

### isCaseInsensitive

    public boolean isCaseInsensitive()

  determines whether this instance behaves case-insensitive in regards to the property keys. If true, all keys are stored and given out in lower-keys and all requests to a key are also transformed to lower-case before the properties are queried.

  See Also:
    `setCaseInsensitive(boolean)`

### setCaseInsensitive

    public void setCaseInsensitive(boolean caseInsensitive)

  See Also:
    `isCaseInsensitive()`

### equalWithProperties

    public boolean equalWithProperties(PropertyEntry entry)

  checks (next to equals) whether all properties are the same

### equalWithProperties

    public static boolean equalWithProperties(PropertyEntry entry1,
                                              PropertyEntry entry2)

### getNumber

    public Number getNumber(String key)

  convenience method; returns either the property value of the given key or 0 if the property value is null

### getBoolean

    public boolean getBoolean(String key)

### getProperty

    public Object getProperty(String key)

  Description copied from interface: `PropertyEntry`
  allows access to some property; may return null if not set

  Specified by:
    `getProperty` in interface `PropertyEntry`

### getProperty

    public Object getProperty(String key,
                              Object defaultValue)

  if the given key maps to a null value, the defaultValue is returned instead

### getPropertyKeys

    public String[] getPropertyKeys()

  note that an existing key may still map to a null value

### verifyProperties

    public void verifyProperties()
                          throws IllegalArgumentException

  This default implementation simply runs all existing properties through `checkPropertyChange(String, Object)`. If any implementation requires to check for more (e.g. for missing properties), this method is to be overridden to provide this functionality. Within the implementation of PropertyEntryImpl, this method is never called.

  Throws:
    `IllegalArgumentException`

### checkPropertyChange

    protected void checkPropertyChange(String key,
                                       Object value)
                                throws IllegalArgumentException,
                                       NullPointerException

  determines whether a property can be changed as given. This method is checked on the attempt to change any property; If this method throws an IllegalArgumentException, it is propagated to the caller of setProperty() or removeProperty(). If this is called on the attempt to remove a property, the value is null. This method may be overridden to guarantee a specific consistency of all properties. The message within the IllegalArgumentException allows for specific information on why a property change would not be allowed. This implementation is plain empty, i.e. any change is allowed.

  Throws:
    `IllegalArgumentException` - if the change of the value is not to be allowed
    `NullPointerException` - if a key or value must not be null but still is
  See Also:
    `setProperty(String, Object)`, `removeProperty(String)`

### isKeyIn

    public static boolean isKeyIn(String key,
                                  String... keyCandidates)

  convenience method to more easily check keys in inheriting classes

### setProperty

    public Object setProperty(String key,
                              Object value)
                       throws IllegalArgumentException

  Description copied from interface: `PropertyEntry`
  edit/set a given property value based on the given key. Note that null values are allowed as value, but not as key!

  Specified by:
    `setProperty` in interface `PropertyEntry`
  Returns:
    the previous value of the given key or null if not previously set (or previously set to null)
  Throws:
    `IllegalArgumentException` - if `checkPropertyChange(key, value)`throws one or if the VetoableChangeSupport is enabled and throws a PropertyVetoException``
  See Also:
    `checkPropertyChange(String, Object)`

### removeProperty

    public Object removeProperty(String key)
                          throws IllegalArgumentException

  Description copied from interface: `PropertyEntry`
  removes the given key from the properties

  Specified by:
    `removeProperty` in interface `PropertyEntry`
  Returns:
    the previous value of the given key or null if previously unset
  Throws:
    `IllegalArgumentException` - if `checkPropertyChange(key, value)`throws one or if the VetoableChangeSupport is enabled and throws a PropertyVetoException``
  See Also:
    `checkPropertyChange(String, Object)`

### setAllFrom

    public void setAllFrom(Map<?,?> map)

### putAll

    public void putAll(Map<?,?> map)

  all imported properties are checked by `checkPropertyChange()`

### clearProperties

    public void clearProperties()
                         throws IllegalArgumentException

  clears all properties by removing every key separately (as a removal may not be allowed by checkPropertyChange())

  Throws:
    `IllegalArgumentException`

### getProperties

    public Map<String,Object> getProperties()

  generates a new view on each call; altering properties can be done via the `setProperty(String, Object)` method

  Specified by:
    `getProperties` in interface `PropertyEntry`

### asProperties

    public Properties asProperties()

### toDetailedString

    public String toDetailedString()

  Description copied from interface: `DetailedString`
  provides full details of this instance in a String. In case the String contains multiple lines, it is recommended to use '\n' rather than the platform specific line-break for better compatibility.

  Specified by:
    `toDetailedString` in interface `DetailedString`
  Returns:
    a (potentially multi-line) String providing full details on this object instance

### containsPropertyText

    protected boolean containsPropertyText(String text)

  searches within the property values (based on toString()) for the given text case-insensivitely

### isVetoableChangeSupportEnabled

    public boolean isVetoableChangeSupportEnabled()

### setVetoableChangeSupport

    protected void setVetoableChangeSupport(boolean flag)

  allows to enable/disable vetoable change support on this object (disabled by default). Calling this method with false will also set the protected member propertyChangeSupport to null.

  See Also:
    `isVetoableChangeSupportEnabled()`

### addVetoableChangeListener

    public void addVetoableChangeListener(VetoableChangeListener listener)
                                   throws IllegalStateException

  Throws:
    `IllegalStateException` - if the vetoable change support is not enabled on this object
  See Also:
    `isVetoableChangeSupportEnabled()`

### addVetoableChangeListener

    public void addVetoableChangeListener(String propertyKey,
                                          VetoableChangeListener listener)
                                   throws IllegalStateException

  Throws:
    `IllegalStateException` - if the vetoable change support is not enabled on this object
  See Also:
    `isVetoableChangeSupportEnabled()`

### removeVetoableChangeListener

    public void removeVetoableChangeListener(VetoableChangeListener listener)
                                      throws IllegalStateException

  Throws:
    `IllegalStateException` - if the vetoable change support is not enabled on this object
  See Also:
    `isVetoableChangeSupportEnabled()`

### getVetoableChangeListeners

    public VetoableChangeListener[] getVetoableChangeListeners()

  Returns:
    null if the vetoable change support is not enabled on this object or the actual listener array
  See Also:
    `isVetoableChangeSupportEnabled()`

### setChangeListenerSupport

    public void setChangeListenerSupport(boolean flag)

  allows to enable/disable listener support on this object (disabled by default). Calling this method with false will also set the protected member propertyChangeSupport to null.

  See Also:
    `isChangeListenerSupportEnabled()`

### isChangeListenerSupportEnabled

    public boolean isChangeListenerSupportEnabled()

  determines whether listener support is enabled on this object (false by default)

  See Also:
    `setChangeListenerSupport(boolean)`

### addPropertyChangeListener

    public void addPropertyChangeListener(PropertyChangeListener listener)
                                   throws IllegalStateException

  Throws:
    `IllegalStateException` - if the listener support is not enabled on this object
  See Also:
    `isChangeListenerSupportEnabled()`

### addPropertyChangeListener

    public void addPropertyChangeListener(String propertyKey,
                                          PropertyChangeListener listener)
                                   throws IllegalStateException

  Throws:
    `IllegalStateException` - if the listener support is not enabled on this object
  See Also:
    `isChangeListenerSupportEnabled()`

### removePropertyChangeListener

    public void removePropertyChangeListener(PropertyChangeListener listener)
                                      throws IllegalStateException

  Throws:
    `IllegalStateException` - if the listener support is not enabled on this object
  See Also:
    `isChangeListenerSupportEnabled()`

### getPropertyChangeListeners

    public PropertyChangeListener[] getPropertyChangeListeners()

  Returns:
    null if the listener support is not enabled on this object or the actual listener array
  See Also:
    `isChangeListenerSupportEnabled()`

### setUndoSupported

    public void setUndoSupported(boolean flag)

  if one wanted to customize the UndoManager upon creation, this would be the method to override

### isUndoSupport

    public boolean isUndoSupport()

### undo

    public boolean undo()

### redo

    public boolean redo()

### canUndo

    public boolean canUndo()

### canRedo

    public boolean canRedo()

### containsValuePattern

    public boolean containsValuePattern(CharSequence pattern)

  searches through all properties and returns true only if the given pattern is found within the String values of the properties

### getStringExtractor

    public static PatternExtractor<PropertyEntry,String> getStringExtractor(String propertyKey)

  returns a PatternExtractor based on the String value of the given property

### getPropertyExtractor

    public static PatternExtractor<PropertyEntry,Object> getPropertyExtractor(String propertyKey)

### getPropertyExtractor

    public static <T> PatternExtractor<PropertyEntry,T> getPropertyExtractor(String propertyKey,
                                                                             Class<T> type)

  returns a PatternExtractor based on the value of the given property

### getPropertyComparator

    public static Comparator<PropertyEntry> getPropertyComparator(String propertyKey)
                                                           throws IllegalArgumentException

  Throws:
    `IllegalArgumentException`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads