CoreFiles by mySites.guru
Match.php62 lines, 1,148 bytes, from Joomla_4.0.0-alpha7-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha6
md5
0674d05fe29195dc1671bc388d67ff3b
sha1
579e0cb102502f7592875f83b45ff6d0651caee4
sha256
8e93ea7a79c2ba21e0133de576de86e91f809542ffbb554c5a5b4d18a04f04c8
<?php

namespace Negotiation;

final class Match
{
    /**
     * @var float
     */
    public $quality;

    /**
     * @var int
     */
    public $score;

    /**
     * @var int
     */
    public $index;

    public function __construct($quality, $score, $index)
    {
        $this->quality = $quality;
        $this->score   = $score;
        $this->index   = $index;
    }

    /**
     * @param Match $a
     * @param Match $b
     *
     * @return int
     */
    public static function compare(Match $a, Match $b)
    {
        if ($a->quality !== $b->quality) {
            return $a->quality > $b->quality ? -1 : 1;
        }

        if ($a->index !== $b->index) {
            return $a->index > $b->index ? 1 : -1;
        }

        return 0;
    }

    /**
     * @param array $carry reduced array
     * @param Match $match match to be reduced
     *
     * @return Match[]
     */
    public static function reduce(array $carry, Match $match)
    {
        if (!isset($carry[$match->index]) || $carry[$match->index]->score < $match->score) {
            $carry[$match->index] = $match;
        }

        return $carry;
    }
}

The same content is in 13 releases, Joomla 4.0.0-alpha7 to 4.0.0-beta7. See them all, or every version of this file.