org.sonar.api.utils.Duration.add()方法的使用及代码示例

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

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

Duration.add介绍

[英]Add the given duration to the current one.
[中]将给定的持续时间添加到当前持续时间。

代码示例

代码示例来源:origin: SonarSource/sonarqube

@Test
public void add() {
 assertThat(Duration.decode("1h", HOURS_IN_DAY).add(Duration.decode("1min", HOURS_IN_DAY))).isEqualTo(Duration.decode("1h1min", HOURS_IN_DAY));
}

代码示例来源:origin: SonarSource/sonarqube

@CheckForNull
public Duration calculate(DefaultIssue issue) {
 if (issue.isFromExternalRuleEngine()) {
  return issue.effort();
 }
 Rule rule = ruleRepository.getByKey(issue.ruleKey());
 DebtRemediationFunction fn = rule.getRemediationFunction();
 if (fn != null) {
  verifyEffortToFix(issue, fn);
  Duration debt = Duration.create(0);
  String gapMultiplier = fn.gapMultiplier();
  if (fn.type().usesGapMultiplier() && !Strings.isNullOrEmpty(gapMultiplier)) {
   int effortToFixValue = MoreObjects.firstNonNull(issue.gap(), 1).intValue();
   // TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
   debt = durations.decode(gapMultiplier).multiply(effortToFixValue);
  }
  String baseEffort = fn.baseEffort();
  if (fn.type().usesBaseEffort() && !Strings.isNullOrEmpty(baseEffort)) {
   // TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
   debt = debt.add(durations.decode(baseEffort));
  }
  return debt;
 }
 return null;
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

private Duration calculateDebt(DebtRemediationFunction function, @Nullable Double effortToFix, RuleKey ruleKey) {
 if (DebtRemediationFunction.Type.CONSTANT_ISSUE.equals(function.type()) && effortToFix != null) {
  throw new IllegalArgumentException("Rule '" + ruleKey + "' can not use 'Constant/issue' remediation function " +
   "because this rule does not have a fixed remediation cost.");
 }
 Duration result = Duration.create(0);
 Duration factor = function.coefficient();
 Duration offset = function.offset();
 if (factor != null) {
  int effortToFixValue = Objects.firstNonNull(effortToFix, 1).intValue();
  result = factor.multiply(effortToFixValue);
 }
 if (offset != null) {
  result = result.add(offset);
 }
 return result;
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-server

@CheckForNull
public Duration calculate(DefaultIssue issue) {
 if (issue.isFromExternalRuleEngine()) {
  return issue.effort();
 }
 Rule rule = ruleRepository.getByKey(issue.ruleKey());
 DebtRemediationFunction fn = rule.getRemediationFunction();
 if (fn != null) {
  verifyEffortToFix(issue, fn);
  Duration debt = Duration.create(0);
  String gapMultiplier = fn.gapMultiplier();
  if (fn.type().usesGapMultiplier() && !Strings.isNullOrEmpty(gapMultiplier)) {
   int effortToFixValue = MoreObjects.firstNonNull(issue.gap(), 1).intValue();
   // TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
   debt = durations.decode(gapMultiplier).multiply(effortToFixValue);
  }
  String baseEffort = fn.baseEffort();
  if (fn.type().usesBaseEffort() && !Strings.isNullOrEmpty(baseEffort)) {
   // TODO convert to Duration directly in Rule#remediationFunction -> better performance + error handling
   debt = debt.add(durations.decode(baseEffort));
  }
  return debt;
 }
 return null;
}

相关文章