sos.reports
Class ArrayBreakWeightRecorder

java.lang.Object
  |
  +--sos.reports.ArrayBreakWeightRecorder
All Implemented Interfaces:
BreakWeightRecorder

public class ArrayBreakWeightRecorder
extends java.lang.Object
implements BreakWeightRecorder

An implementation of BreakWeightRecorder that uses an array to record weights.

The final break position is determined as follows:

  1. Use the first index with a weight of FORCED_BREAK_WEIGHT, if one exists.
  2. Use the last index with a weight of EXCELLENT_BREAK_WEIGHT, if one exists.
  3. Use the last index for which the weight is GOOD_BREAK_WEIGHT and the ratio of EXCELLENT_BREAK_WEIGHT to the total number of tallies is maximum.

Since:
1.0

Field Summary
 
Fields inherited from interface sos.reports.BreakWeightRecorder
BAD_BREAK_WEIGHT, EXCELLENT_BREAK_WEIGHT, FORCED_BREAK_WEIGHT, GOOD_BREAK_WEIGHT, UNDEFINED_BREAK_WEIGHT
 
Constructor Summary
ArrayBreakWeightRecorder(int length)
          Creates an ArrayBreakWeightRecorder with the specified length.
 
Method Summary
 BreakWeightRecorder createView(int index, int length)
          Returns a view of this recorder.
 void fill(int weight)
          Fills the entire clip range with the specified weight.
 void fill(int index, int length, int weight)
          Fills the specified range with the specified weight.
 void fillEnd(int index, int weight)
          Fills the end portion with the specified weight.
 int getBestWeight()
          Returns the best, or highest, break weight in the clip range.
 int getBreakIndex()
          Returns the best place to break within the clip range, or -1 if such a place does not exist.
 int getFirstIndexOfWeight(int weight)
          Returns the index of the first bit in the clip range with the specified weight.
 int getFirstIndexOfWeightAtLeast(int weight)
          Returns the index of the first bit in the clip range with a weight greater than or equal to the specified weight.
 int getLastIndexOfWeight(int weight)
          Returns the index of the last bit in the clip range with the specified weight.
 int getLastIndexOfWeightAtLeast(int weight)
          Returns the index of the last bit in the clip range with a weight greater than or equal to the specified weight.
 int getRangeLength()
          Returns the length of the clip range.
 int getRangeStart()
          Returns the starting index of the clip range.
 int getWeight(int index)
          Returns the weight at the specified index.
 void setRange(int index, int length)
          Sets this recorder's clip range.
 void setWeight(int index, int weight)
          Sets the weight at the specified index.
 java.lang.String toString()
          Returns a string representation of this object.
 java.lang.String toString(int index, int length)
          Returns a string representation of this recorder over the specified range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayBreakWeightRecorder

public ArrayBreakWeightRecorder(int length)
Creates an ArrayBreakWeightRecorder with the specified length.

Parameters:
length - total number of bits
Method Detail

createView

public BreakWeightRecorder createView(int index,
                                      int length)
Description copied from interface: BreakWeightRecorder
Returns a view of this recorder. The view's indexing starts at 0 and ends at length - 1. Index 0 in the view corresponds to index in this recorder, and index length - 1 corresponds to index + length - 1. Operations on the view within its range propagate to this recorder.

The specified index and length are bound by this recorder's current range. That is, they are adjusted so that the view cannot operate outside this recorder's range.

Specified by:
createView in interface BreakWeightRecorder
Parameters:
index - index of this recorder to get mapped to index 0 of the returned view
length - number of indices to be in the view
Returns:
a sub-view restricted to length indices and translated by index

fill

public void fill(int weight)
Description copied from interface: BreakWeightRecorder
Fills the entire clip range with the specified weight. The resulting weight of a bit is the minimum of the current weight and the specified weight.

Specified by:
fill in interface BreakWeightRecorder
Parameters:
weight - maximum weight that each bit in the clip range should have

fill

public void fill(int index,
                 int length,
                 int weight)
Description copied from interface: BreakWeightRecorder
Fills the specified range with the specified weight. The resulting weight of a bit is the minimum of the current weight and the specified weight.

The range is bound by this recorder's current clip range. That is, bits outside the clip range are ignored.

Specified by:
fill in interface BreakWeightRecorder
Parameters:
index - start index at which to set the weight
length - number of bits for which to set the wieght
weight - maximum weight that each bit in the specified range should have
See Also:
BreakWeightRecorder.fill(int), BreakWeightRecorder.fillEnd(int, int)

fillEnd

public void fillEnd(int index,
                    int weight)
Description copied from interface: BreakWeightRecorder
Fills the end portion with the specified weight.

The range is bound by this recorder's current clip range. That is, bits outside the clip range are ignored.

Specified by:
fillEnd in interface BreakWeightRecorder
Parameters:
index - start index at which to set the weight
weight - maximum weight that each bit in the specified range should have

getBestWeight

public int getBestWeight()
Description copied from interface: BreakWeightRecorder
Returns the best, or highest, break weight in the clip range.

Specified by:
getBestWeight in interface BreakWeightRecorder
Returns:
the best weight

getBreakIndex

public int getBreakIndex()
Description copied from interface: BreakWeightRecorder
Returns the best place to break within the clip range, or -1 if such a place does not exist. The implementation is free to decide what constitutes best, as long as the weight at the returned index is not BAD_BREAK_WEIGHT.

Specified by:
getBreakIndex in interface BreakWeightRecorder
Returns:
the recommended break index, or -1 if one does not exist

getFirstIndexOfWeight

public int getFirstIndexOfWeight(int weight)
Description copied from interface: BreakWeightRecorder
Returns the index of the first bit in the clip range with the specified weight.

Specified by:
getFirstIndexOfWeight in interface BreakWeightRecorder
Parameters:
weight - weight to seek
Returns:
the index of the first bit in the clip range with the specified weight, or -1 if no such bit exists

getFirstIndexOfWeightAtLeast

public int getFirstIndexOfWeightAtLeast(int weight)
Description copied from interface: BreakWeightRecorder
Returns the index of the first bit in the clip range with a weight greater than or equal to the specified weight.

Specified by:
getFirstIndexOfWeightAtLeast in interface BreakWeightRecorder
Parameters:
weight - minimum weight to seek
Returns:
the index of the first bit in the clip range with a weight greater than or equal to the specified weight, or -1 if no such bit exists

getLastIndexOfWeight

public int getLastIndexOfWeight(int weight)
Description copied from interface: BreakWeightRecorder
Returns the index of the last bit in the clip range with the specified weight.

Specified by:
getLastIndexOfWeight in interface BreakWeightRecorder
Parameters:
weight - weight to seek
Returns:
the index of the last bit in the clip range with the specified weight, or -1 if no such bit exists

getLastIndexOfWeightAtLeast

public int getLastIndexOfWeightAtLeast(int weight)
Description copied from interface: BreakWeightRecorder
Returns the index of the last bit in the clip range with a weight greater than or equal to the specified weight.

Specified by:
getLastIndexOfWeightAtLeast in interface BreakWeightRecorder
Parameters:
weight - minimum weight to seek
Returns:
the index of the last bit in the clip range with a weight greater than or equal to the specified weight, or -1 if no such bit exists

getRangeLength

public int getRangeLength()
Description copied from interface: BreakWeightRecorder
Returns the length of the clip range.

Specified by:
getRangeLength in interface BreakWeightRecorder
Returns:
the length of the clip range
See Also:
BreakWeightRecorder.getRangeStart(), BreakWeightRecorder.setRange(int, int)

getRangeStart

public int getRangeStart()
Description copied from interface: BreakWeightRecorder
Returns the starting index of the clip range.

Specified by:
getRangeStart in interface BreakWeightRecorder
Returns:
the starting index of the clip range
See Also:
BreakWeightRecorder.getRangeLength(), BreakWeightRecorder.setRange(int, int)

getWeight

public int getWeight(int index)
Description copied from interface: BreakWeightRecorder
Returns the weight at the specified index.

Specified by:
getWeight in interface BreakWeightRecorder
Parameters:
index - index at which to fetch the weight
Returns:
the weight at index

setRange

public void setRange(int index,
                     int length)
Description copied from interface: BreakWeightRecorder
Sets this recorder's clip range. Future operations outside this range will be ignored.

The range is bound by this recorder's current clip range. That is, bits outside the clip range are ignored.

Specified by:
setRange in interface BreakWeightRecorder
Parameters:
index - start index of range to clip
length - length of range to clip

setWeight

public void setWeight(int index,
                      int weight)
Description copied from interface: BreakWeightRecorder
Sets the weight at the specified index. The method does nothing if the index is outside of the clip range. The resulting weight at index is the minimum of the current weight and the specified weight.

Specified by:
setWeight in interface BreakWeightRecorder
Parameters:
index - index at which to set the weight
weight - weight of a potential break at index

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this object

toString

public java.lang.String toString(int index,
                                 int length)
Returns a string representation of this recorder over the specified range.

Parameters:
index - index at which to start generating the string
length - number of bits to include in the string
Returns:
a string representation of this recorder over the specified range
Throws:
java.lang.IllegalArgumentException - if length < 0
java.lang.IndexOutOfBoundsException - if index < 0


Copyright 2003, 2004 Side of Software (SOS). All rights reserved.