ILIAS  release_8 Revision v8.24
ILIAS\Data\Range Class Reference

A simple class to express a range of whole positive numbers. More...

+ Collaboration diagram for ILIAS\Data\Range:

Public Member Functions

 __construct (int $start, int $length)
 
 unpack ()
 
 getStart ()
 
 getLength ()
 
 getEnd ()
 getEnd will return the (excluded) endpoint. More...
 
 withStart (int $start)
 
 withLength (int $length)
 
 croppedTo (int $max)
 This will create a range that is guaranteed to not exceed $max. More...
 

Protected Member Functions

 checkStart (int $start)
 
 checkLength (int $length)
 

Protected Attributes

int $start
 
int $length
 

Detailed Description

A simple class to express a range of whole positive numbers.

Range is a half-open interval (right-open): [a,b) = {x ∈ ℕ: a ≤ x < b}. Since the endpoint is excluded, a Range of 0,3 means: records 0,1,2, but not 3.

Author
Nils Haagen nils..nosp@m.haag.nosp@m.en@co.nosp@m.ncep.nosp@m.ts-an.nosp@m.d-tr.nosp@m.ainin.nosp@m.g.de

Definition at line 30 of file Range.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Data\Range::__construct ( int  $start,
int  $length 
)

Definition at line 35 of file Range.php.

36 {
37 $this->checkStart($start);
38 $this->checkLength($length);
39 $this->start = $start;
40 $this->length = $length;
41 }
checkStart(int $start)
Definition: Range.php:43
checkLength(int $length)
Definition: Range.php:50

References ILIAS\Data\Range\$length, ILIAS\Data\Range\$start, ILIAS\Data\Range\checkLength(), and ILIAS\Data\Range\checkStart().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkLength()

ILIAS\Data\Range::checkLength ( int  $length)
protected

Definition at line 50 of file Range.php.

50 : void
51 {
52 if ($length < 0) {
53 throw new \InvalidArgumentException("Length must be larger or equal then 0", 1);
54 }
55 }

References ILIAS\Data\Range\$length.

Referenced by ILIAS\Data\Range\__construct(), and ILIAS\Data\Range\withLength().

+ Here is the caller graph for this function:

◆ checkStart()

ILIAS\Data\Range::checkStart ( int  $start)
protected

Definition at line 43 of file Range.php.

43 : void
44 {
45 if ($start < 0) {
46 throw new \InvalidArgumentException("Start must be a positive number (or 0)", 1);
47 }
48 }

References ILIAS\Data\Range\$start.

Referenced by ILIAS\Data\Range\__construct(), and ILIAS\Data\Range\withStart().

+ Here is the caller graph for this function:

◆ croppedTo()

ILIAS\Data\Range::croppedTo ( int  $max)

This will create a range that is guaranteed to not exceed $max.

Definition at line 104 of file Range.php.

104 : Range
105 {
106 if ($max > $this->getEnd()) {
107 return $this;
108 }
109
110 if ($this->getStart() > $max) {
111 return new self($max, 0);
112 }
113
114 return $this->withLength($max - $this->getStart());
115 }
withLength(int $length)
Definition: Range.php:93
getEnd()
getEnd will return the (excluded) endpoint.
Definition: Range.php:76

References ILIAS\Data\Range\getEnd(), ILIAS\Data\Range\getStart(), and ILIAS\Data\Range\withLength().

+ Here is the call graph for this function:

◆ getEnd()

ILIAS\Data\Range::getEnd ( )

getEnd will return the (excluded) endpoint.

For a Range of (4,2), e.g.: getEnd is 4 + 2 = 6, so valid records are 4 and 5, but not 6.

Definition at line 76 of file Range.php.

76 : int
77 {
78 if ($this->length === PHP_INT_MAX) {
79 return PHP_INT_MAX;
80 }
81
82 return $this->start + $this->length;
83 }

References ILIAS\Data\Range\$length.

Referenced by ILIAS\Data\Range\croppedTo(), RangeTest\testEndCalculation(), RangeTest\testWithLength(), and RangeTest\testWithStart().

+ Here is the caller graph for this function:

◆ getLength()

ILIAS\Data\Range::getLength ( )

◆ getStart()

ILIAS\Data\Range::getStart ( )

◆ unpack()

ILIAS\Data\Range::unpack ( )

◆ withLength()

ILIAS\Data\Range::withLength ( int  $length)

Definition at line 93 of file Range.php.

93 : Range
94 {
95 $this->checkLength($length);
96 $clone = clone $this;
97 $clone->length = $length;
98 return $clone;
99 }

References ILIAS\Data\Range\$length, and ILIAS\Data\Range\checkLength().

Referenced by ILIAS\Data\Range\croppedTo(), RangeTest\testNegativeLength(), and RangeTest\testWithLength().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withStart()

ILIAS\Data\Range::withStart ( int  $start)

Definition at line 85 of file Range.php.

85 : Range
86 {
87 $this->checkStart($start);
88 $clone = clone $this;
89 $clone->start = $start;
90 return $clone;
91 }

References ILIAS\Data\Range\$start, and ILIAS\Data\Range\checkStart().

Referenced by RangeTest\testNegativeStart(), and RangeTest\testWithStart().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $length

◆ $start


The documentation for this class was generated from the following file: