JTemporal Home
Tutorial

net.sf.jtemporal
Class TemporalAttributeImpl<V>

java.lang.Object
  extended by net.sf.jtemporal.AbstractTemporalAttribute<V>
      extended by net.sf.jtemporal.TemporalAttributeImpl<V>
Type Parameters:
V - the type of the value
All Implemented Interfaces:
java.io.Serializable, ReadableTemporalAttribute<V>, TemporalAttribute<V>
Direct Known Subclasses:
TreeTemporalAttribute

public class TemporalAttributeImpl<V>
extends AbstractTemporalAttribute<V>
implements java.io.Serializable

Implements TemporalAttribute by using a TemporalAttributeStorage.
To achieve this goal, some temporal logic is added to the put and remove methods, and some collection-oriented behaviour is provided on top of the storage.

Version:
$Id: TemporalAttributeImpl.java,v 1.16 2007/09/23 20:07:52 tabeck Exp $
See Also:
Serialized Form

Constructor Summary
TemporalAttributeImpl(TemporalAttributeStorage storage)
           
 
Method Summary
 void clear()
          Removes all mappings from this map (optional operation).
 boolean containsInstant(Instant instant)
          Returns true if this map contains a mapping for the specified Instant.
 boolean containsValue(java.lang.Object value)
          Returns true if this map maps one or more Periods to the specified value.
 java.util.Set<TimedObject<V>> entrySet()
          Returns a set view of the entries (instances of TimedObject) contained in this map.
 Instant firstInstant()
          Returns the first (lowest) instant currently in this temporal map.
 Period firstPeriod()
          Returns the first (lowest) period currently in this temporal map.
 V get(Instant instant)
          Returns the value to which this map maps the specified Instant.
 TimedObject<V> getEntry(Instant instant)
          Returns the entry active at the given instant.
 Period getPeriod(Instant instant)
          Returns the period that has a value associated at specified instant.
 TemporalAttributeStorage getStorage()
          Returns the storage that has been passed to the constructor to build this TemporalAttribute.
 boolean isEmpty()
          Returns true if this map contains no Period-value mappings.
 Instant lastInstant()
          Returns the last (highest) instant currently in this temporal map.
 Period lastPeriod()
          Returns the last (highest) period currently in this temporal map.
 java.util.Set<Period> periodSet()
          Returns a set view of the periods contained in this map.
 boolean put(Period _p, V _value)
          Associates the specified value with the specified Period in this map (optional operation).
 boolean remove(Period p)
          Removes the mapping(s) for this period from this map if present (optional operation).
 int size()
          Returns the number of Period-value mappings in this map.
 TemporalAttribute<V> subMap(Period p)
           
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jtemporal.AbstractTemporalAttribute
equals, extent, putAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TemporalAttributeImpl

public TemporalAttributeImpl(TemporalAttributeStorage storage)
Method Detail

getStorage

public TemporalAttributeStorage getStorage()
Returns the storage that has been passed to the constructor to build this TemporalAttribute.

Returns:
the storage

clear

public void clear()
Description copied from interface: TemporalAttribute
Removes all mappings from this map (optional operation).

Specified by:
clear in interface TemporalAttribute<V>

size

public int size()
Description copied from interface: TemporalAttribute
Returns the number of Period-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface TemporalAttribute<V>
Returns:
the number of Instant-value mappings in this map.

isEmpty

public boolean isEmpty()
Description copied from interface: TemporalAttribute
Returns true if this map contains no Period-value mappings.

Specified by:
isEmpty in interface TemporalAttribute<V>
Returns:
true if this map contains no Period-value mappings.

get

public V get(Instant instant)
Description copied from interface: TemporalAttribute
Returns the value to which this map maps the specified Instant. Returns null if the map contains no mapping at this Instant.
WARNING: for defragmentation purposes, this method may eventually return a different instance of value that equals the value stored by put(Period).

Specified by:
get in interface ReadableTemporalAttribute<V>
Specified by:
get in interface TemporalAttribute<V>
Parameters:
instant - instant whose associated value is to be returned
Returns:
the value to which this map maps the specified instant.

getPeriod

public Period getPeriod(Instant instant)
Description copied from interface: TemporalAttribute
Returns the period that has a value associated at specified instant.

Specified by:
getPeriod in interface TemporalAttribute<V>
Parameters:
instant - instant whose associated enclosing period is to be returned
Returns:
the period of the entry that overlaps the specified instant. returns null if this map does not contain a mapping for the specified instant.

getEntry

public TimedObject<V> getEntry(Instant instant)
Description copied from interface: TemporalAttribute
Returns the entry active at the given instant.
This method is like a get(Instant) and getPeriod(Instant) in a single shot.
WARNING: for defragmentation purposes, this method may eventually return a different instance of value that equals the value stored by put(Period).

Specified by:
getEntry in interface TemporalAttribute<V>
Overrides:
getEntry in class AbstractTemporalAttribute<V>
Parameters:
instant - instant whose associated entry is to be returned
Returns:
the entry active at the given instant. returns null if this map does not contain a mapping for the specified instant.

containsInstant

public boolean containsInstant(Instant instant)
Description copied from interface: TemporalAttribute
Returns true if this map contains a mapping for the specified Instant.

Specified by:
containsInstant in interface TemporalAttribute<V>
Parameters:
instant - instant whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified instant.

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: TemporalAttribute
Returns true if this map maps one or more Periods to the specified value.

Specified by:
containsValue in interface TemporalAttribute<V>
Parameters:
value - value whose presence in this map is to be tested.
Returns:
true if this map maps one or more keys to the specified value.

put

public boolean put(Period _p,
                   V _value)
Description copied from interface: TemporalAttribute
Associates the specified value with the specified Period in this map (optional operation). If the map previously contained a mapping to a period overlapping this period, the old value is replaced for the given period.
WARNING: for defragmentation purposes, get(Instant) and getEntry(Instant) may eventually return a a different instance of value that equals(value).

Specified by:
put in interface TemporalAttribute<V>
Parameters:
_p - period with which the specified value is to be associated.
_value - value to be associated with the specified key. Be careful at the equals implementation of the value object: the result of the equals method is supposed to be immutable while it is stored in this collection.
Returns:
true if one or more previous values are overwritten partially or completely. false if there is no conflicting mapping.

remove

public boolean remove(Period p)
Description copied from interface: TemporalAttribute
Removes the mapping(s) for this period from this map if present (optional operation).

Specified by:
remove in interface TemporalAttribute<V>
Parameters:
p - period whose mappings are to be removed from the map.
Returns:
true if one or more previous values are removed partially or completely. false if there is any mapping changed.

periodSet

public java.util.Set<Period> periodSet()
Description copied from interface: TemporalAttribute
Returns a set view of the periods contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
periodSet in interface TemporalAttribute<V>
Returns:
a set view of the keys contained in this map.

entrySet

public java.util.Set<TimedObject<V>> entrySet()
Description copied from interface: TemporalAttribute
Returns a set view of the entries (instances of TimedObject) contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
entrySet in interface TemporalAttribute<V>
Returns:
a set view of the keys contained in this map.
See Also:
TimedObject

firstInstant

public Instant firstInstant()
Description copied from interface: TemporalAttribute
Returns the first (lowest) instant currently in this temporal map.

Specified by:
firstInstant in interface TemporalAttribute<V>
Returns:
the first (lowest) instant currently in this temporal map.

lastInstant

public Instant lastInstant()
Description copied from interface: TemporalAttribute
Returns the last (highest) instant currently in this temporal map.

Specified by:
lastInstant in interface TemporalAttribute<V>
Returns:
the last (highest) instant currently in this temporal map.

firstPeriod

public Period firstPeriod()
Description copied from interface: TemporalAttribute
Returns the first (lowest) period currently in this temporal map.

Specified by:
firstPeriod in interface TemporalAttribute<V>
Returns:
the first (lowest) period currently in this temporal map.

lastPeriod

public Period lastPeriod()
Description copied from interface: TemporalAttribute
Returns the last (highest) period currently in this temporal map.

Specified by:
lastPeriod in interface TemporalAttribute<V>
Returns:
the last (highest) period currently in this temporal map.

subMap

public TemporalAttribute<V> subMap(Period p)
Specified by:
subMap in interface TemporalAttribute<V>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

JTemporal Home
Tutorial