Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4792924
WeightedValue.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
WeightedValue.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Collections
;
use
TypeError
;
class
WeightedValue
implements
Comparable
{
///
/// Constants
///
const
DEFAULT_WEIGHT
=
1.0
;
///
/// Private members
///
/**
* @var float
*/
private
$weight
=
self
::
DEFAULT_WEIGHT
;
/**
* @var mixed
*/
private
$value
;
///
/// Constructors
///
public
function
__construct
(
$value
,
float
$weight
=
self
::
DEFAULT_WEIGHT
)
{
$this
->
value
=
$value
;
$this
->
weight
=
$weight
;
}
public
static
function
parse
(
string
$expression
)
:
WeightedValue
{
$pair
=
explode
(
';q='
,
$expression
);
if
(
count
(
$pair
)
==
1
)
{
return
new
WeightedValue
(
$pair
[
0
]);
}
return
new
WeightedValue
(
$pair
[
0
],
(
float
)
$pair
[
1
]);
}
///
/// Getters and setters
///
public
function
getWeight
()
:
float
{
return
$this
->
weight
;
}
public
function
setWeight
(
float
$weight
)
:
self
{
$this
->
weight
=
$weight
;
return
$this
;
}
public
function
getValue
()
{
return
$this
->
value
;
}
public
function
setValue
(
$value
)
:
self
{
$this
->
value
=
$value
;
return
$this
;
}
///
/// Helper methods
///
public
function
compareTo
(
object
$other
)
:
int
{
if
(!
$other
instanceof
WeightedValue
)
{
throw
new
TypeError
;
}
return
$this
->
getWeight
()
<=>
$other
->
getWeight
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 21:39 (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2435893
Default Alt Text
WeightedValue.php (1 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment