com.tomgibara.pronto.config.source
Class LastModifiedCalculator

java.lang.Object
  extended by com.tomgibara.pronto.config.source.LastModifiedCalculator

public final class LastModifiedCalculator
extends java.lang.Object

Instances of this class can compute accurate values for lastModified from property maps alone. The property maps supplied to these objects are not modified and are copied if their values need to be recorded by this object. The copies made in this way are available via the getProperties() method.

Author:
Tom Gibara

Constructor Summary
LastModifiedCalculator()
          Initializes the object without a known last modified date or known properties.
LastModifiedCalculator(java.util.Map<java.lang.String,java.lang.String> properties, long lastModified)
          After calling this constructor, the lastModified field will equal the supplied lastModified date and the properties field will contain a copy of the supplied properties.
 
Method Summary
 long getLastModified()
          Returns the lastModified date maintained by this object.
 java.util.Map<java.lang.String,java.lang.String> getProperties()
          Returns a copy of the last supplied properties which had changed.
 void update(java.util.Map<java.lang.String,java.lang.String> properties)
          Computes the lastModified field of this object based on the supplied map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LastModifiedCalculator

public LastModifiedCalculator()
Initializes the object without a known last modified date or known properties. The update method must be called before these fields are accessed.


LastModifiedCalculator

public LastModifiedCalculator(java.util.Map<java.lang.String,java.lang.String> properties,
                              long lastModified)
After calling this constructor, the lastModified field will equal the supplied lastModified date and the properties field will contain a copy of the supplied properties.

Parameters:
properties - the initial properties for this object, not null
lastModified - the known last modification date for the supplied properties, not negative
Method Detail

update

public void update(java.util.Map<java.lang.String,java.lang.String> properties)
Computes the lastModified field of this object based on the supplied map. This method will persist a copy of the supplied properties if the properties differ from the last call to this method (or if this is the first call to the method).

Parameters:
properties - a new collection of properties

getProperties

public java.util.Map<java.lang.String,java.lang.String> getProperties()
                                                               throws java.lang.IllegalStateException
Returns a copy of the last supplied properties which had changed.

Returns:
the properties recorded by this object, never null
Throws:
java.lang.IllegalStateException - if the update method has not yet been called

getLastModified

public long getLastModified()
                     throws java.lang.IllegalStateException
Returns the lastModified date maintained by this object.

Returns:
the time at which the properties stored by this object were last modified
Throws:
java.lang.IllegalStateException - if the update method has not yet been called


Copyright © 2006-2007 Tom Gibara. All Rights Reserved.