Compare two Versionable objects

Returns true if they are equal

@param  Versionable $v1
@param  Versionable $v2
@return bool
769225
private static function versionableEquals(Versionable $v1, Versionable $v2)
    {
        if ($v1->getMajor() !== $v2->getMajor()) {
            return false;
        }
        if ($v1->getMinor() !== $v2->getMinor()) {
            return false;
        }
        if ($v1->getPatch() !== $v2->getPatch()) {
            return false;
        }

        return true;
    }
719715
function compareVersions(v1, v2) {
    if (semver.gt(v1.tag, v2.tag)) {
        return -1;
    }
    if (semver.lt(v1.tag, v2.tag)) {
        return 1;
    }
    return 0;
}
172179
public function compare(SchemaVersion $version)
    {
        return version_compare(
            str_replace('-', '.', $this->toString()),
            str_replace('-', '.', $version->toString())
        );
    }
529359
public static int compareVersions(String version_1, String version_2)
	{
		for (int j = 0; j < Math.min(version_2.length(), version_1.length()); j++)
		{

			char v1_c = version_1.charAt(j);
			char v2_c = version_2.charAt(j);

			if (v1_c == v2_c)
			{

				continue;
			}

			if (v2_c == '.')
			{

				// version1 higher (e.g. 10.2 -vs- 1.2)

				return (+1);

			} else if (v1_c == '.')
			{

				// version2 higher ( e.g. 1.2 -vs- 10.2 )

				return (-1);

			} else
			{

				return (v1_c - v2_c);
			}
		}

		// longest one wins. e.g. 1.2.1 -vs- 1.2

		return (version_1.length() - version_2.length());
	}
131310
final static boolean valEquals(final Object o1, final Object o2) {
    return (o1 == null ? o2 == null : o1.equals(o2));
  }
1354714
private static function preReleaseGreaterThan(PreRelease $v1, PreRelease $v2)
    {
        // Pre-releases can be denoted as versionable (X.Y.Z) or greek (alpha.5)
        // We let versionable take precedence
        if (!self::versionableEquals($v1, $v2)) {
            // If v1 is bigger on the versionable level, it's bigger.
            return self::versionableGreaterThan($v1, $v2);
        }

        // "Greek" part is "bigger" for v1
        if ($v1->getGreek() !== $v2->getGreek()) {
            return self::greekLargerThan($v1->getGreek(), $v2->getGreek());
        }

        // Release number for v1 is bigger than v2's
        if ($v1->getReleaseNumber() > $v2->getReleaseNumber()) {
            return true;
        }

        return false;
    }
861566
public function hasVersionMigrated(Version $version)
    {
        $this->createMigrationCollection();

        $record = $this->getCollection()->findOne(['v' => $version->getVersion()]);

        return null !== $record;
    }
1011541
public static function isNewestVersionAvailable()
    {
        $latestVersion = self::getLatestVersion();
        if (!empty($latestVersion)
            && version_compare(Version::VERSION, $latestVersion) == -1
        ) {
            return $latestVersion;
        }
        return false;
    }
1275826
protected static function isFileVersionMatch(string $version): bool
    {
        try {
            $fileVersion = null;
            if (class_exists(self::CONNECTOR_CLASS)) {
                $ref = new \ReflectionClass(self::CONNECTOR_CLASS);
                if (preg_match(FW::VERSION_WITHOUT_BUG_FIX, $ref->getDocComment(), $result)) {
                    $fileVersion = Arr::first($result);
                }
            }

            return version_compare($fileVersion, $version, '>=');
        } catch (\Exception $e) {
            return false;
        }
    }
1055421
function compareVersion(version1, version2) {
  version1 = cleanupVersion(version1).split('.');
  version2 = cleanupVersion(version2).split('.');
  for (let i = 0; i < 3; i++) {
    let compared = compare(+version1[i], +version2[i]);
    if (compared !== 0) {
      return compared;
    }
  }
  return 0;
}
142375
public static function compareVersions($a, $b)
    {
        $versionPos = max(count($a), count($b));
        while (count($a) < $versionPos) {
            $a[] = 0;
        }
        while (count($b) < $versionPos) {
            $b[] = 0;
        }

        for ($v = 0; $v < count($a); $v++) {
            if ((int)$a[$v] < (int)$b[$v]) {
                return '<';
            }
            if ((int)$a[$v] > (int)$b[$v]) {
                return '>';
            }
        }
        return '=';
    }
242586
public static function compare(Version $first, Version $second) : int
    {
        $obj = new self($first, $second);

        return $obj->doCompare();
    }
831182
public static function compareVersion($v1, $v2)
    {
        if(empty($v1)){
            return 0;
        }

        $l1  = explode('.',$v1);
        $l2  = explode('.',$v2);
        $len = count($l1) > count($l2) ? count($l1): count($l2);

        for ($i = 0; $i < $len; $i++){
            $n1 = isset($l1[$i])?$l1[$i]:0;
            $n2 = isset($l2[$i])?$l2[$i]:0;
            if ($n1 > $n2){
                return true;//需要更新
            }else if ($n1 < $n2){
                return false;//不需要更新
            }
        }
        return false;
    }
826568
private function isIdentifierEquals($entity1, $entity2)
    {
        if ($entity1 === $entity2) {
            return true;
        }

        $class     = $this->em->getClassMetadata(get_class($entity1));
        $persister = $this->getEntityPersister($class->getClassName());

        if ($class !== $this->em->getClassMetadata(get_class($entity2))) {
            return false;
        }

        $identifierFlattener = $this->em->getIdentifierFlattener();

        $oid1 = spl_object_id($entity1);
        $oid2 = spl_object_id($entity2);

        $id1 = $this->entityIdentifiers[$oid1]
            ?? $identifierFlattener->flattenIdentifier($class, $persister->getIdentifier($entity1));
        $id2 = $this->entityIdentifiers[$oid2]
            ?? $identifierFlattener->flattenIdentifier($class, $persister->getIdentifier($entity2));

        return $id1 === $id2 || implode(' ', $id1) === implode(' ', $id2);
    }
1216750
def all_versions_equal(self, versions):  # type: (Dict[str,str]) -> bool
        
        if len(versions) <= 1:
            return True

        semver = None
        for key, version in versions.items():
            if semver is None:
                try:
                    semver, _, __ = version_object_and_next(version)
                except ValueError:
                    logger.error("Invalid version at:" + unicode((key, version)))
                    return False
                continue
            try:
                version_as_version, _, __ = version_object_and_next(version)
            except:
                return False
            if version_as_version != semver:
                return False
        return True
414023
public static function smallerThan(Version $v1, Version $v2)
    {
        // If it's equal it can not be smaller
        if (self::equals($v1, $v2)) {
            return false;
        }

        // If it's not equal, and not greater, it must be smaller
        return !self::greaterThan($v1, $v2);
    }
1347633
public static int compareOsgiVersions(String v1, String v2) {
		return Version.parseVersion(v1).compareTo(Version.parseVersion(v2));
	}