com.eliad.util
Interface LinearPointSet


public interface LinearPointSet
extends java.lang.Cloneable

An interface to describe a subset of N.

Invariants:
forall int i >= -1 | getWeight(i) >= 0
getWeight(0) == 0
forall int i > 0 | getWeight(i) <= getWeight(-1)
forall int i > 0 | getWeight(i+1) == getWeight(i) + (contains(i) ? 1 : 0)
isEmpty() == (getWeight(-1) == 0)
getStart() >= 0
isEmpty() implies getStart() == 0
!isEmpty() implies contains(getStart())
forall int i in [0,getStart()[ | !contains(i)
getEnd() > 0 implies contains(getEnd() - 1)
forall int i >= getEnd() | !contains(i)
Version:
1.0 00/04/10
Author:
Patrick Mérissert-Coffinières

Inner Class Summary
static class LinearPointSet.Factory
          A factory to clone LinearPoint objects, and create default ones
static interface LinearPointSet.Listener
           
 
Method Summary
 void addListener(LinearPointSet.Listener l)
          Adds Listener l to the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with start, count arguments coveribg all changes.
 void clearRegion(int start, int length)
          Ensures that all positions in the specified interval are excluded from the set
 java.lang.Object clone()
          Necessary to allow public access to the clone method.
 boolean contains(int x)
          Tests whether the x point is in the set.
 boolean contains(int start, int length)
          Tests whether the continuous subset of positions from start to length is contained in the set.
 int getEnd()
          Returns the first point not contained in the set.
 int getStart()
          Returns the first point.
 int getWeight(int max)
          Returns the number of included points up to some (optional) limit.
 void insertSlots(int start, int length)
          Inserts length positions before position start.
 boolean isEmpty()
          Returns whether the set contains at least one position.
 void removeListener(LinearPointSet.Listener l)
          Removes Listener l from the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with start, count arguments coveribg all changes.
 void removeSlots(int start, int length)
          Removes length positions at position start
 void setRegion(int start, int length)
          Ensures that all positions in the specified interval are included
 

Method Detail

getWeight

public int getWeight(int max)
Returns the number of included points up to some (optional) limit.
Parameters:
max - The excluded upper bound applied to this call must be strict positive or -1 -1 means no bound
Returns:
The number of points up to ubound,
Preconditions:
max > 0 || max == -1
Postconditions:
return >= 0

isEmpty

public boolean isEmpty()
Returns whether the set contains at least one position.
Returns:
true iff the set is not empty

getStart

public int getStart()
Returns the first point. Returns 0 for an empty set.
Returns:
the start of the set.
Postconditions:
return >=0
See Also:
getEnd()

getEnd

public int getEnd()
Returns the first point not contained in the set.
Returns:
the end of set, i.e. the first position not in it. will be 0 if empty.
Postconditions:
isEmpty() implies return == 0
!isEmpty() implies return > 0
See Also:
getStart()

contains

public boolean contains(int x)
Tests whether the x point is in the set.
Parameters:
x - the tested point.
Preconditions:
x>= 0

contains

public boolean contains(int start,
                        int length)
Tests whether the continuous subset of positions from start to length is contained in the set.
Parameters:
start - the start of the tested interval.
length - the length of the tested interval.
Preconditions:
start >= 0
length > 0

insertSlots

public void insertSlots(int start,
                        int length)
Inserts length positions before position start. The (length) new positions will be in the set only if start-1 is in the set.
Parameters:
start - The position of insertion. Must be non-negative.
length - The number of inserted positions. Must be strict positive.
Preconditions:
start >= 0
length > 0
Postconditions:
forall int i in [0, start[ | contains(i) == contains(i)@pre
forall int i in [start, start+length[ | contains(i) == (start > 0 && contains(start-1) && contains(start)@pre)
forall int i >= start+length | contains(i) == contains(i-length)@pre

removeSlots

public void removeSlots(int start,
                        int length)
Removes length positions at position start
Preconditions:
start >= 0
length > 0
Postconditions:
forall int i in [0, start[ | contains(i) == contains(i)@pre
forall int i >= start | contains(i) == contains(i+length)@pre

setRegion

public void setRegion(int start,
                      int length)
Ensures that all positions in the specified interval are included
Parameters:
start - The first position to include.
length - The number of positions whose inclusion must be insured
Preconditions:
start >= 0
length > 0
Postconditions:
forall int i in [0, start[ | contains(i) == contains(i)@pre
forall int i in [start, start+length[ | contains(i)
forall int i >= start+length | contains(i) == contains(i)@pre

clearRegion

public void clearRegion(int start,
                        int length)
Ensures that all positions in the specified interval are excluded from the set
Parameters:
start - The first position to exclude.
length - The number of positions whose exclusion must be insured
Preconditions:
start >= 0
length > 0
Postconditions:
forall int i in [0, start[ | contains(i) == contains(i)@pre
forall int i in [start, start+length[ | !contains(i)
forall int i >= start+length | contains(i) == contains(i)@pre

addListener

public void addListener(LinearPointSet.Listener l)
Adds Listener l to the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with start, count arguments coveribg all changes.

removeListener

public void removeListener(LinearPointSet.Listener l)
Removes Listener l from the list of Listeners that will be notified of any changes to the model by the invocation of their method markAsChanged with start, count arguments coveribg all changes.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Necessary to allow public access to the clone method.
Overrides:
clone in class java.lang.Object