JTemporal Home
Tutorial

net.sf.jtemporal
Class TemporalSetImpl<V>

java.lang.Object
  extended by net.sf.jtemporal.AbstractTemporalSet<V>
      extended by net.sf.jtemporal.TemporalSetImpl<V>
Type Parameters:
V - the type of the value
All Implemented Interfaces:
TemporalSet<V>

public class TemporalSetImpl<V>
extends AbstractTemporalSet<V>

The standard implementation of TemporalSet.
Takes care about temporal logic, and delegates all the data storage and retrieval to a TemporalSetStorage.

Version:
$Id: TemporalSetImpl.java,v 1.7 2007/09/15 08:27:24 tabeck Exp $

Constructor Summary
TemporalSetImpl(TemporalSetStorage storage)
          Creates a new TemporalSet using the give storage.
 
Method Summary
 void clear()
          Removes all the mappings from this map.
 boolean contains(Instant instant, java.lang.Object value)
          Returns true if there is a mapping for this value at the given instant.
 boolean containsValue(java.lang.Object value)
          Returns true if there is a mapping for 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(java.lang.Object value)
          Returns the first (lowest) instant currently defined for the given value.
 Period firstPeriod(java.lang.Object value)
          Returns the first (lowest) period currently defined for the given value.
 Period getPeriod(Instant instant, java.lang.Object value)
          Returns the period of the mapping valid at the specified instant for the given value.
 boolean isEmpty()
          Returns true if this map contains no Period-value mappings.
 boolean isEmpty(Instant i)
          Returns true if this map does not contain mappings valid at the given intant.
 Instant lastInstant(java.lang.Object value)
          Returns the last (highest) instant currently defined for the given value.
 Period lastPeriod(java.lang.Object value)
          Returns the last (highest) period currently defined for the given value.
 java.util.Set<Period> periodSet(java.lang.Object value)
          Returns a set view of the periods contained in this map for the give value.
 boolean put(Period _p, V _value)
          Associates the specified value with the specified Period in this map.
 boolean remove(Period p, java.lang.Object value)
          Removes the mapping(s) for this period and value from this map if present.
 boolean removePeriod(Period p)
          Removes all the mapping(s) for this period from this map if present.
 boolean removeValue(java.lang.Object value)
          Removes all the mapping(s) for this value from this map if present.
 int size()
          Returns the number of Period-value mappings in this map.
 int sizeAt(Instant instant)
          Returns the number values in this map valid at the given instant.
 int sizeFor(java.lang.Object value)
          Returns the number of Period-value mappings in this map for the given value.
 int sizeValues()
          Returns the number of distinct values in this map.
 java.util.Set<V> valueSet()
          Returns a read-only Set containing the distinct values defined somewhen in this map.
 java.util.Set<V> valueSet(Instant instant)
          Returns a read-only Set containing the values defined in this map at the specified instant.
 
Methods inherited from class net.sf.jtemporal.AbstractTemporalSet
equals, extent, putAll
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemporalSetImpl

public TemporalSetImpl(TemporalSetStorage storage)
Creates a new TemporalSet using the give storage.

Parameters:
storage - the storage containing all the data.
Method Detail

clear

public void clear()
Description copied from interface: TemporalSet
Removes all the mappings from this map.


size

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

Returns:
the number of Period-value mappings in this map.

sizeFor

public int sizeFor(java.lang.Object value)
Description copied from interface: TemporalSet
Returns the number of Period-value mappings in this map for the given value. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Parameters:
value - the number of entries for the given value
Returns:
the number of Instant-value mappings in this map.

sizeAt

public int sizeAt(Instant instant)
Description copied from interface: TemporalSet
Returns the number values in this map valid at the given instant. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Parameters:
instant - the instant at which the counted entries are valid
Returns:
the number of entries valid at the given instant.

sizeValues

public int sizeValues()
Description copied from interface: TemporalSet
Returns the number of distinct values in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:
the number of distinct values in this map.

isEmpty

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

Returns:
true if this map contains no Period-value mappings.

isEmpty

public boolean isEmpty(Instant i)
Description copied from interface: TemporalSet
Returns true if this map does not contain mappings valid at the given intant.

Parameters:
i - when this temporal set is empty
Returns:
true if this map does not contain mappings valid at the given intant.

valueSet

public java.util.Set<V> valueSet(Instant instant)
Description copied from interface: TemporalSet
Returns a read-only Set containing the values defined in this map at the specified instant. Returns an empty set if the map contains no mapping at this Instant.

Parameters:
instant - instant whose associated value is to be returned
Returns:
a read-only Set containing the values defined in this map at the specified instant.

valueSet

public java.util.Set<V> valueSet()
Description copied from interface: TemporalSet
Returns a read-only Set containing the distinct values defined somewhen in this map. Returns an empty set if the map contains no mapping at all.

Returns:
a read-only Set containing the distinct values defined somewhen in this map.

entrySet

public java.util.Set<TimedObject<V>> entrySet()
Description copied from interface: TemporalSet
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.

Returns:
a set view of the keys contained in this map.
See Also:
TimedObject

getPeriod

public Period getPeriod(Instant instant,
                        java.lang.Object value)
Description copied from interface: TemporalSet
Returns the period of the mapping valid at the specified instant for the given value.

Parameters:
instant - when the given value is valid
value - the value of the entry valid during the returned period
Returns:
the period of the mapping valid at the specified instant for the given value. Returns null if this map does not contain a mapping for the given value at the specified instant.

contains

public boolean contains(Instant instant,
                        java.lang.Object value)
Description copied from interface: TemporalSet
Returns true if there is a mapping for this value at the given instant. Same as containsValue(Instant instant, Object value)

Parameters:
instant - instant whose presence in this map is to be tested.
value - value whose presence in this map is to be tested.
Returns:
true if there is a mapping for this value at the given instant.

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: TemporalSet
Returns true if there is a mapping for the specified value.

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: TemporalSet
Associates the specified value with the specified Period in this map. If the map previously contained a mapping to an equal value, during a period overlapping this period, the periods are merged.

Parameters:
_p - period with which the specified value is to be associated.
_value - value to be associated with the specified period. 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,
                      java.lang.Object value)
Description copied from interface: TemporalSet
Removes the mapping(s) for this period and value from this map if present.

Parameters:
p - period whose mappings are to be removed from the map.
value - value whose mapping are to be removed from the map.
Returns:
true if one or more previous values are removed partially or completely. false if there is no mapping changed.

removeValue

public boolean removeValue(java.lang.Object value)
Description copied from interface: TemporalSet
Removes all the mapping(s) for this value from this map if present.

Parameters:
value - value whose mapping are to be removed from the map.
Returns:
trueif the TemporalSet contained the specified element.

removePeriod

public boolean removePeriod(Period p)
Description copied from interface: TemporalSet
Removes all the mapping(s) for this period from this map if present.

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(java.lang.Object value)
Description copied from interface: TemporalSet
Returns a set view of the periods contained in this map for the give value. 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.

Returns:
a set view of the periods contained in this map for the give value.

firstInstant

public Instant firstInstant(java.lang.Object value)
Description copied from interface: TemporalSet
Returns the first (lowest) instant currently defined for the given value.

Returns:
the first (lowest) instant currently defined for the given value.

lastInstant

public Instant lastInstant(java.lang.Object value)
Description copied from interface: TemporalSet
Returns the last (highest) instant currently defined for the given value.

Returns:
the last (highest) instant currently defined for the given value.

firstPeriod

public Period firstPeriod(java.lang.Object value)
Description copied from interface: TemporalSet
Returns the first (lowest) period currently defined for the given value.

Returns:
the first (lowest) period currently defined for the given value.

lastPeriod

public Period lastPeriod(java.lang.Object value)
Description copied from interface: TemporalSet
Returns the last (highest) period currently defined for the given value.

Returns:
the last (highest) period currently defined for the given value.

JTemporal Home
Tutorial