Package org.daisy.dotify.common.splitter
Class SplitPointHandler<T extends SplitPointUnit,U extends SplitPointDataSource<T,U>>
- java.lang.Object
-
- org.daisy.dotify.common.splitter.SplitPointHandler<T,U>
-
- Type Parameters:
T
- the type of split point unitsU
- the type of data source
public class SplitPointHandler<T extends SplitPointUnit,U extends SplitPointDataSource<T,U>> extends Object
Breaks units into results. All allowed break points are supplied with the input.
-
-
Constructor Summary
Constructors Constructor Description SplitPointHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SplitPointSpecification
find(float breakPoint, U data, SplitOption... options)
Finds a split point at, or before, the supplied breakPoint according to the rules in the data.SplitPointSpecification
find(float breakPoint, U data, SplitPointCost<T> cost, SplitOption... options)
Finds a split point at, or before, the supplied breakPoint according to the rules in the data.static <T extends SplitPointUnit,U extends SplitPointDataSource<T,U>>
intfindLeading(U in)
Finds leading skippable units in the supplied data source.static <T extends SplitPointUnit,U extends SplitPointDataSource<T,U>>
SplitPoint<T,U>skipLeading(U in, int index)
Skips leading units in the supplied list.static <T extends SplitPointUnit>
SplitPoint<T,SplitPointDataList<T>>split(float breakPoint, List<T> units, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data.static <T extends SplitPointUnit>
SplitPoint<T,SplitPointDataList<T>>split(float breakPoint, List<T> units, SplitPointCost<T> cost, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data.static <T extends SplitPointUnit>
SplitPoint<T,SplitPointDataList<T>>split(float breakPoint, T... units)
Splits the data at, or before, the supplied breakPoint according to the rules in the data.SplitPoint<T,U>
split(float breakPoint, U data, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data.SplitPoint<T,U>
split(float breakPoint, U data, SplitPointCost<T> cost, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data.SplitPoint<T,U>
split(SplitPointSpecification spec, U data)
Splits the data according to the supplied specification.static <T extends SplitPointUnit>
SplitList<T>trimLeading(List<T> in)
Trims leading skippable units in the supplied list.static <T extends SplitPointUnit,U extends SplitPointDataSource<T,U>>
SplitPoint<T,U>trimLeading(U in)
Trims leading skippable units in the supplied data source.
-
-
-
Method Detail
-
split
@SafeVarargs public static <T extends SplitPointUnit> SplitPoint<T,SplitPointDataList<T>> split(float breakPoint, T... units)
Splits the data at, or before, the supplied breakPoint according to the rules in the data. If force is used, rules may be broken to achieve a result.- Type Parameters:
T
- the type of split point units- Parameters:
breakPoint
- the split pointunits
- the data- Returns:
- returns a split point result
-
split
public static <T extends SplitPointUnit> SplitPoint<T,SplitPointDataList<T>> split(float breakPoint, List<T> units, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data. If force is used, rules may be broken to achieve a result.- Type Parameters:
T
- the type of split point units- Parameters:
breakPoint
- the split pointunits
- the dataoptions
- the split options- Returns:
- returns a split point result
-
split
public static <T extends SplitPointUnit> SplitPoint<T,SplitPointDataList<T>> split(float breakPoint, List<T> units, SplitPointCost<T> cost, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data. If force is used, rules may be broken to achieve a result.- Type Parameters:
T
- the type of split point units- Parameters:
breakPoint
- the split pointunits
- the datacost
- the cost function used when determining the optimal forced split point. In other words, the cost function is only used if there are no breakable units available.options
- the split options- Returns:
- returns a split point result
-
split
public SplitPoint<T,U> split(float breakPoint, U data, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data. If force is used, rules may be broken to achieve a result.- Parameters:
breakPoint
- the split pointdata
- the data to splitoptions
- the split options- Returns:
- returns a split point result
-
split
public SplitPoint<T,U> split(float breakPoint, U data, SplitPointCost<T> cost, SplitOption... options)
Splits the data at, or before, the supplied breakPoint according to the rules in the data. If force is used, rules may be broken to achieve a result.- Parameters:
breakPoint
- the split pointdata
- the data to splitcost
- the cost function used when determining the optimal forced split point. In other words, the cost function is only used if there are no breakable units available.options
- the split options- Returns:
- returns a split point result
- Throws:
IllegalArgumentException
- if cost is null
-
split
public SplitPoint<T,U> split(SplitPointSpecification spec, U data)
Splits the data according to the supplied specification. A specification can be created by using
find(float, SplitPointDataSource, SplitPointCost, SplitOption...)
on the data source.No data is beyond the specified split point is produced using this method. Also, only one of the data producing operations is called, either
SplitPointDataSource.getRemaining()
orSplitPointDataSource.split(int)
.- Parameters:
spec
- the specificationdata
- the data- Returns:
- returns a split point result
-
find
public SplitPointSpecification find(float breakPoint, U data, SplitOption... options)
Finds a split point at, or before, the supplied breakPoint according to the rules in the data. If force is used, rules may be broken to achieve a result.- Parameters:
breakPoint
- the split pointdata
- the data to splitoptions
- the split options- Returns:
- returns a split point specification
-
find
public SplitPointSpecification find(float breakPoint, U data, SplitPointCost<T> cost, SplitOption... options)
Finds a split point at, or before, the supplied breakPoint according to the rules in the data. If force is used, rules may be broken to achieve a result.- Parameters:
breakPoint
- the split pointdata
- the data to splitcost
- the cost function used when determining the optimal forced split point. In other words, the cost function is only used if there are no breakable units available.options
- the split options- Returns:
- returns a split point specification
-
trimLeading
public static <T extends SplitPointUnit> SplitList<T> trimLeading(List<T> in)
Trims leading skippable units in the supplied list. The result is backed by the original list.- Type Parameters:
T
- the type of split list- Parameters:
in
- the list to trim- Returns:
- the list split in two parts, one with the leading skippable units, one with the remainder
-
trimLeading
public static <T extends SplitPointUnit,U extends SplitPointDataSource<T,U>> SplitPoint<T,U> trimLeading(U in)
Trims leading skippable units in the supplied data source. The result is backed by the original data source.- Type Parameters:
T
- the type of split listU
- the type of data source- Parameters:
in
- the list to trim- Returns:
- a split point, the leading skippable units are placed in
SplitPoint.getDiscarded()
, the remainder are placed inSplitPoint.getTail()
-
skipLeading
public static <T extends SplitPointUnit,U extends SplitPointDataSource<T,U>> SplitPoint<T,U> skipLeading(U in, int index)
Skips leading units in the supplied list. The result is backed by the original data source. No data is beyond index is produced using this method.- Type Parameters:
T
- the type of objectU
- the type of data source- Parameters:
in
- the list to trimindex
- the index of the split point- Returns:
- a split point, the leading units are placed in
SplitPoint.getDiscarded()
, the remainder are placed inSplitPoint.getTail()
-
findLeading
public static <T extends SplitPointUnit,U extends SplitPointDataSource<T,U>> int findLeading(U in)
Finds leading skippable units in the supplied data source.- Type Parameters:
T
- the type of objectU
- the type of data source- Parameters:
in
- the data source to search- Returns:
- returns the index of the first non-skippable unit
-
-