Documentation ¶
Index ¶
- type PageInterval
- func (pi *PageInterval) AddPage(page int) error
- func (pi *PageInterval) AddPagesBetween(first, last int)
- func (pi *PageInterval) GetFirstPage() (int, error)
- func (pi *PageInterval) GetLastPage() (int, error)
- func (pi *PageInterval) HasPage(page int) bool
- func (pi *PageInterval) HasPages() bool
- func (pi *PageInterval) Intervals() []PageRange
- func (pi *PageInterval) Iterator() itf.Iterater[int]
- func (pi *PageInterval) PageCount() int
- func (pi *PageInterval) RemovePage(page int)
- func (pi *PageInterval) RemovePagesBetween(first, last int)
- func (pi *PageInterval) ReverseIterator() itf.Iterater[int]
- func (pi *PageInterval) String() string
- type PageRange
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PageInterval ¶
type PageInterval struct {
// contains filtered or unexported fields
}
PageInterval represents a collection of page intervals, where each interval is represented by a pair of integers. The PageInterval ensures non-overlapping, non-duplicate intervals and reduces the amount of intervals by merging two consecutive intervals into one.
Example:
pi := NewPageInterval() pi.AddPagesBetween(1, 5) pi.AddPagesBetween(10, 15)
fmt.Println(pi.Intervals()) // Output: [[1 5] [10 15]] fmt.Println(pi.PageCount()) // Output: 11
func NewPageInterval ¶
func NewPageInterval() *PageInterval
NewPageInterval creates a new instance of PageInterval with empty intervals and a page count of 0.
Returns:
- *PageInterval: A pointer to the newly created PageInterval.
func (*PageInterval) AddPage ¶
func (pi *PageInterval) AddPage(page int) error
AddPage is a method of the PageInterval type that adds a page to the PageInterval, maintaining the non-overlapping, non-duplicate intervals. It panics with *ers.ErrInvalidParameter if the page number is less than 1.
Parameters:
- page: The page number to add to the PageInterval.
Example:
pi := PageInterval{ intervals: []PageRange{{1, 5}, {10, 15}}, pageCount: 11, } pi.AddPage(6) fmt.Println(pi.intervals) // Output: [[1 6] [10 15]] fmt.Println(pi.pageCount) // Output: 12
func (*PageInterval) AddPagesBetween ¶
func (pi *PageInterval) AddPagesBetween(first, last int)
AddPagesBetween is a method of the PageInterval type that adds pages between the first and last page numbers to the PageInterval.
However, if the first page number is less than 1, it is set to 1 to remove invalid pages, same goes for the last page number. Finally, if the last page number is less than the first page number, the values are swapped.
Parameters:
- first: The first page number to add to the PageInterval.
- last: The last page number to add to the PageInterval.
Example:
pi := PageInterval{ intervals: []PageRange{{1, 5}, {10, 15}}, pageCount: 11, } pi.AddPagesBetween(6, 9) fmt.Println(pi.intervals) // Output: [[1 15]] fmt.Println(pi.pageCount) // Output: 15
func (*PageInterval) GetFirstPage ¶
func (pi *PageInterval) GetFirstPage() (int, error)
GetFirstPage is a method of the PageInterval type that returns the first page number in the PageInterval. It panics with *ers.ErrCallFailed if no pages have been set.
Returns:
- int: The first page number in the PageInterval.
func (*PageInterval) GetLastPage ¶
func (pi *PageInterval) GetLastPage() (int, error)
GetLastPage is a method of the PageInterval type that returns the last page number in the PageInterval. It panics with *ers.ErrCallFailed if no pages have been set.
Returns:
- int: The last page number in the PageInterval.
func (*PageInterval) HasPage ¶
func (pi *PageInterval) HasPage(page int) bool
HasPage is a method of the PageInterval type that checks if the given page exists in the PageInterval.
Parameters:
- page: The page number to check for in the PageInterval.
Returns:
- bool: A boolean value that is true if the page exists in the PageInterval, and false otherwise.
func (*PageInterval) HasPages ¶
func (pi *PageInterval) HasPages() bool
HasPages is a method of the PageInterval type that checks if the PageInterval has any pages.
Returns:
- bool: A boolean value that is true if the PageInterval has pages, and false otherwise.
func (*PageInterval) Intervals ¶
func (pi *PageInterval) Intervals() []PageRange
Intervals is a method of the PageInterval type that returns the intervals stored in the PageInterval. Each interval is represented as a pair of integers, where the first integer is the start page number and the second integer is the end page number.
Returns:
- intervals: A slice of integer pairs representing the intervals in the PageInterval.
func (*PageInterval) Iterator ¶
func (pi *PageInterval) Iterator() itf.Iterater[int]
Iterator is a method of the PageInterval type that returns an iterator for iterating over the pages in the PageInterval.
Returns:
- itf.Iterater[int]: An iterator for iterating over the pages in the PageInterval.
func (*PageInterval) PageCount ¶
func (pi *PageInterval) PageCount() int
PageCount is a method of the PageInterval type that returns the total number of pages across all intervals in the PageInterval.
Returns:
- pageCount: The total number of pages across all intervals in the PageInterval.
func (*PageInterval) RemovePage ¶
func (pi *PageInterval) RemovePage(page int)
RemovePage is a method of the PageInterval type that removes the specified page from the PageInterval. No changes are made if the page number is less than 1 or not found in the PageInterval.
Parameters:
- page: The page number to remove from the PageInterval.
Example:
pi := PageInterval{ intervals: []PageRange{{1, 5}, {10, 15}}, pageCount: 11, } pi.RemovePage(5) fmt.Println(pi.intervals) // Output: [[1 4] [10 15]] fmt.Println(pi.pageCount) // Output: 10
func (*PageInterval) RemovePagesBetween ¶
func (pi *PageInterval) RemovePagesBetween(first, last int)
RemovePagesBetween is a method of the PageInterval type that removes pages between the specified first and last page numbers from the PageInterval.
However, if the first page number is less than 1, it is set to 1 to remove invalid pages, same goes for the last page number. Finally, if the last page number is less than the first page number, the values are swapped.
Parameters:
- first, last: The first and last page numbers to remove from the PageInterval, respectively.
func (*PageInterval) ReverseIterator ¶
func (pi *PageInterval) ReverseIterator() itf.Iterater[int]
ReverseIterator is a method of the PageInterval type that returns a PageIntervalReverseIterator for iterating over the intervals in the PageInterval in reverse order.
Returns:
- itf.Iterater[int]: An iterator for iterating over the intervals in the PageInterval in reverse order.
func (*PageInterval) String ¶
func (pi *PageInterval) String() string
String is a method of the PageInterval type that returns a string representation of the PageInterval. Each interval is represented as "start : end" separated by a comma.
Returns:
- string: A formatted string representation of the PageInterval.
type PageRange ¶ added in v0.2.9
type PageRange [2]int
PageRange represents a pair of integers that represent the start and end page numbers of an interval. The first integer is the start page number and the second integer is the end page number of the interval. (both inclusive)
For instance, the PageRange [1, 5] represents the interval from page 1 to page 5.