com.yahoo.component.Version.compareTo()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(3.2k)|赞(0)|评价(0)|浏览(104)

本文整理了Java中com.yahoo.component.Version.compareTo()方法的一些代码示例,展示了Version.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Version.compareTo()方法的具体详情如下:
包路径:com.yahoo.component.Version
类名称:Version
方法名:compareTo

Version.compareTo介绍

[英]Compares this Version object to another version.

A version is considered to be less than another version if its major component is less than the other version's major component, or the major components are equal and its minor component is less than the other version's minor component, or the major and minor components are equal and its micro component is less than the other version's micro component, or the major, minor and micro components are equal and it's qualifier component is less than the other version's qualifier component (using String.compareTo).

A version is considered to be equal to another version if the major, minor and micro components are equal and the qualifier component is equal (using String.compareTo).

Unspecified numeric components are treated as 0, unspecified qualifier is treated as the empty string.
[中]将此Version对象与另一个版本进行比较。
如果一个版本的主要组件小于另一个版本的主要组件,或者主要组件相等且次要组件小于另一个版本的次要组件,则认为该版本小于另一个版本,或者主组件和次组件相等,其微组件小于另一版本的微组件,或者主组件、次组件和微组件相等,其限定组件小于另一版本的限定组件(使用String.compareTo)。
如果主要、次要和微观成分相等,且限定成分相等(使用[$2$]),则一个版本被视为等同于另一个版本。
未指定的数字组件被视为0,未指定的限定符被视为空字符串。

代码示例

代码示例来源:origin: com.yahoo.vespa/component

@Override
  public int compare(Version v1, Version v2) {
    return v1.compareTo(v2);
  }
}

代码示例来源:origin: com.yahoo.vespa/config-model

@Override
public int compareTo(ConfigModelId other) {
  if (other == this) return 0;
  int cmp = this.name.compareTo(other.name);
  if (cmp == 0) {
    cmp = this.version.compareTo(other.version);
  }
  return cmp;
}

代码示例来源:origin: com.yahoo.vespa/component

/**
 * Finds the best (highest) matching version among a set.
 *
 * @return the matching version, or null if there are no matches
 */
protected static Version findBestMatch(VersionSpecification versionSpec, Set<Version> versions) {
  Version bestMatch=null;
  for (Version version : versions) {
    //No version is set if getSpecifiedMajor() == null
    //In that case we allow all versions
    if (version == null || !versionSpec.matches(version)) continue;
    if (bestMatch==null || bestMatch.compareTo(version)<0)
      bestMatch=version;
  }
  return bestMatch;
}

代码示例来源:origin: com.yahoo.vespa/messagebus

@Override
  public void handleVersion(Version version) {
    boolean shouldSend = false;
    synchronized (this) {
      if (version == null) {
        hasError = true;
      } else if (version.compareTo(this.version) < 0) {
        this.version = version;
      }
      if (--pending == 0) {
        shouldSend = true;
      }
    }
    if (shouldSend) {
      net.send(this);
    }
  }
}

代码示例来源:origin: com.yahoo.vespa/container-core

/**
 * Returns the bundle of a given name having the highest matching version
 *
 * @param id the id of the component to return. May not include a version, or include
 *        an underspecified version, in which case the highest (mathcing) version which
 *        does not contain a qualifier is returned
 * @return the bundle match having the highest version, or null if there was no matches
 */
public Bundle getBundle(ComponentSpecification id) {
  Bundle highestMatch=null;
  for (Bundle bundle : getBundles()) {
    assert bundle.getSymbolicName() != null : "ensureHasBundleSymbolicName not called during installation";
    if ( ! bundle.getSymbolicName().equals(id.getName())) continue;
    if ( ! id.getVersionSpecification().matches(versionOf(bundle))) continue;
    if (highestMatch==null || versionOf(highestMatch).compareTo(versionOf(bundle))<0)
      highestMatch=bundle;
  }
  return highestMatch;
}

相关文章