com.eliad.util
Class SizeSequenceIntervals

java.lang.Object
  |
  +--com.eliad.util.SizeSequenceIntervals

public class SizeSequenceIntervals
extends java.lang.Object
implements Intervals

An implementation of Intervals that mimic the JTable's use of the SizeSequence class

Version:
1.0 00/03/26
Author:
Patrick Mérissert-Coffinières
See Also:
Serialized Form

Constructor Summary
SizeSequenceIntervals(int numEntries, int size)
          Constructs a SizeSequenceIntervals object with a uniform size and a given number of entries.
SizeSequenceIntervals(javax.swing.SizeSequence seq, int def)
          Constructs a SizeSequenceIntervals object starting from a SizeSequence
 
Method Summary
 java.lang.Object clone()
          Necessary to allow public access to the clone method.
 int getCount()
          Returns the number of entries in this Intervals object
 int getDefaultSize()
          returns the default size for new entries
 int getIndex(int position)
          Returns the index of the entry that contains to the specified position.
 int getPosition(int index)
          Returns the start position for the specified entry.
 int getSize(int index)
          Returns the size of the specified entry.
 int[] getSizes()
          Returns the array of sizes for all entries.
 boolean hasFixedSize()
          Tests whether all the entries are the same size
 void insertEntries(int start, int length, int value)
          Adds a continuous group of entries to this Intervals.
 void removeEntries(int start, int length)
          Removes a continuous group of entries from this Intervals.
 void setFixedSize(int size)
          Sets a common size for all entries.
 void setSize(int index, int size)
          Sets the size of the specified entry.
 void setSizes(int[] sizes)
          Sets the sizes for all entries from an array
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SizeSequenceIntervals

public SizeSequenceIntervals(int numEntries,
                             int size)
Constructs a SizeSequenceIntervals object with a uniform size and a given number of entries.
Parameters:
numEmtries - initial number of entries
size - initial uniform size of entries

SizeSequenceIntervals

public SizeSequenceIntervals(javax.swing.SizeSequence seq,
                             int def)
Constructs a SizeSequenceIntervals object starting from a SizeSequence
Parameters:
seq - initial SizeSequence
Method Detail

getDefaultSize

public int getDefaultSize()
returns the default size for new entries
Specified by:
getDefaultSize in interface Intervals

getCount

public int getCount()
Returns the number of entries in this Intervals object
Specified by:
getCount in interface Intervals
Returns:
the number of entries
Postconditions:
return >= 0

getSize

public int getSize(int index)
Returns the size of the specified entry.
Specified by:
getSize in interface Intervals
Parameters:
index - the index corresponding to the entry
Returns:
the size of the entry
Preconditions:
index >= 0 && index < getCount()
Postconditions:
return >= 0
return == getPosition(index+1) - getPosition(x)

setSize

public void setSize(int index,
                    int size)
Sets the size of the specified entry.
Specified by:
setSize in interface Intervals
Parameters:
index - the index corresponding to the entry
size - the size of the entry
Preconditions:
index >= 0 && index < getCount()
size > 0
Postconditions:
getSize(index) == size

setFixedSize

public void setFixedSize(int size)
Sets a common size for all entries. This becomes the new default size.
Specified by:
setFixedSize in interface Intervals
Parameters:
size - the size of the entries
Preconditions:
size >= 0

hasFixedSize

public boolean hasFixedSize()
Tests whether all the entries are the same size
Specified by:
hasFixedSize in interface Intervals

getIndex

public int getIndex(int position)
Returns the index of the entry that contains to the specified position.
Specified by:
getIndex in interface Intervals
Parameters:
position - the position of the entry
Returns:
the index of the entry that occupies the specified position
Postconditions:
position >=0 && position < getPosition(getCount()) implies return >= 0 && return < getCount()
position <0 implies return == -1
position >= getPosition(getCount()) implies return == getCount()

getPosition

public int getPosition(int index)
Returns the start position for the specified entry.
Specified by:
getPosition in interface Intervals
Parameters:
index - the index of the entry whose position is desired.
Returns:
the starting position of the specified entry. Note that it may be one higher than the argument to getSize(int).
Preconditions:
index >= 0 && index <= getCount()
Postconditions:
return >= 0
index==0 implies return ==0
getIndex(return) == return

getSizes

public int[] getSizes()
Returns the array of sizes for all entries.
Specified by:
getSizes in interface Intervals
Postconditions:
return.length == getCount()
index >= 0 && index < getCount() implies return[index] >= 0

setSizes

public void setSizes(int[] sizes)
Sets the sizes for all entries from an array
Specified by:
setSizes in interface Intervals
Postconditions:
index >= 0 && index < sizes.length implies sizes[index] >= 0
getCount() == sizes.count

insertEntries

public void insertEntries(int start,
                          int length,
                          int value)
Adds a continuous group of entries to this Intervals.
Specified by:
insertEntries in interface Intervals
Parameters:
start - the index to be assigned to the first entry in the group
length - the number of entries in the group
value - the size to be assigned to each new entry
Preconditions:
start >= 0
length > 0
Postconditions:
getCount() == getCount()@pre + length

removeEntries

public void removeEntries(int start,
                          int length)
Removes a continuous group of entries from this Intervals.
Specified by:
removeEntries in interface Intervals
Parameters:
start - the index of the first entry to be removed
length - the number of entries to be removed
Preconditions:
start >= 0
length > 0
Postconditions:
start+length <= getCount()@pre implies getCount() == getCount()@pre - length

clone

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