You are here

public function Measurement::compareTo in Physical Fields 8

Compares the current measurement with the given one.

Parameters

\Drupal\physical\Measurement $measurement: The measurement.

Return value

int 0 if both measurements are equal, 1 if the first one is greater, -1 otherwise.

3 calls to Measurement::compareTo()
Measurement::equals in src/Measurement.php
Gets whether the current measurement is equivalent to the given one.
Measurement::greaterThan in src/Measurement.php
Gets whether the current measurement is greater than the given one.
Measurement::lessThan in src/Measurement.php
Gets whether the current measurement is lesser than the given measurement.

File

src/Measurement.php, line 199

Class

Measurement
Provides a base class for measurement value objects.

Namespace

Drupal\physical

Code

public function compareTo(Measurement $measurement) {
  if ($this->unit != $measurement
    ->getUnit()) {
    $measurement = $measurement
      ->convert($this->unit);
  }
  return Calculator::compare($this->number, $measurement
    ->getNumber());
}