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

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

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

Duration.toMinutes介绍

[英]Return the duration in minutes.
For instance, Duration.decode(1h, 24).toMinutes() will return 60.
[中]以分钟为单位返回持续时间。
例如,持续时间。解码(1h,24)。toMinutes()将返回60。

代码示例

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

/**
 * Return true if the given duration is greater than the current one.
 */
public boolean isGreaterThan(Duration other) {
 return toMinutes() > other.toMinutes();
}

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

@CheckForNull
public Long effortInMinutes() {
 return effort != null ? effort.toMinutes() : null;
}

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

/**
 * Return the formatted work duration using the english bundles.
 * <br>
 * Example : format(Duration.encode("9d 10h")) -&gt; 10d 2h
 *
 */
public String format(Duration duration) {
 Long durationInMinutes = duration.toMinutes();
 if (durationInMinutes == 0) {
  return "0";
 }
 boolean isNegative = durationInMinutes < 0;
 Long absDuration = Math.abs(durationInMinutes);
 int days = ((Double) ((double) absDuration / HOURS_IN_DAY / 60)).intValue();
 Long remainingDuration = absDuration - (days * HOURS_IN_DAY * 60);
 int hours = ((Double) (remainingDuration.doubleValue() / 60)).intValue();
 remainingDuration = remainingDuration - (hours * 60);
 int minutes = remainingDuration.intValue();
 return format(days, hours, minutes, isNegative);
}

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

public boolean setEffort(DefaultIssue issue, @Nullable Duration value, IssueChangeContext context) {
 Duration oldValue = issue.effort();
 if (!Objects.equals(value, oldValue)) {
  issue.setEffort(value);
  issue.setFieldChange(context, TECHNICAL_DEBT, oldValue != null ? oldValue.toMinutes() : null, value != null ? value.toMinutes() : null);
  issue.setUpdateDate(context.date());
  issue.setChanged(true);
  return true;
 }
 return false;
}

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

@Test
public void decode() {
 // 1 working day -> 8 hours
 assertThat(underTest.decode("1d").toMinutes()).isEqualTo(8L * ONE_HOUR);
 // 8 hours
 assertThat(underTest.decode("8h").toMinutes()).isEqualTo(8L * ONE_HOUR);
}

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

@Test
public void create_from_minutes() {
 assertThat(underTest.create(10L).toMinutes()).isEqualTo(10L);
}

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

@Test
public void create_from_duration_in_minutes() {
 Duration duration = Duration.create(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);
 assertThat(duration.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);
}

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

public void add(DefaultIssue issue) {
 boolean isOnLeak = onLeakPredicate.test(issue);
 distributions.get(RULE_TYPE).increment(issue.type().name(), isOnLeak);
 String componentUuid = issue.componentUuid();
 if (componentUuid != null) {
  distributions.get(COMPONENT).increment(componentUuid, isOnLeak);
 }
 RuleKey ruleKey = issue.ruleKey();
 if (ruleKey != null) {
  distributions.get(RULE).increment(ruleKey.toString(), isOnLeak);
 }
 String assigneeUuid = issue.assignee();
 if (assigneeUuid != null) {
  distributions.get(ASSIGNEE).increment(assigneeUuid, isOnLeak);
 }
 for (String tag : issue.tags()) {
  distributions.get(TAG).increment(tag, isOnLeak);
 }
 Duration effort = issue.effort();
 if (effort != null) {
  effortStats.add(effort.toMinutes(), isOnLeak);
 }
}

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

@Test
public void default_effort_to_fix_is_one_for_linear_function() {
 int coefficient = 2;
 rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, coefficient + "min", null));
 assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(coefficient * 1);
}

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

@Test
public void linear_function() {
 double effortToFix = 3.0;
 int coefficient = 2;
 issue.setGap(effortToFix);
 rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, coefficient + "min", null));
 assertThat(underTest.calculate(issue).toMinutes()).isEqualTo((int) (coefficient * effortToFix));
}

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

@Test
public void constant_function() {
 int constant = 2;
 issue.setGap(null);
 rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, constant + "min"));
 assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(2);
}

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

@Test
 public void linear_with_offset_function() {
  double effortToFix = 3.0;
  int coefficient = 2;
  int offset = 5;
  issue.setGap(effortToFix);
  rule.setFunction(new DefaultDebtRemediationFunction(
   DebtRemediationFunction.Type.LINEAR_OFFSET, coefficient + "min", offset + "min"));

  assertThat(underTest.calculate(issue).toMinutes()).isEqualTo((int) ((coefficient * effortToFix) + offset));
 }
}

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

@Test
public void iterator_over_one_issue() {
 dbTester.prepareDbUnit(getClass(), "one_issue.xml");
 Map<String, IssueDoc> issuesByKey = issuesByKey();
 assertThat(issuesByKey).hasSize(1);
 IssueDoc issue = issuesByKey.get("ABC");
 assertThat(issue.key()).isEqualTo("ABC");
 assertThat(issue.resolution()).isEqualTo("FIXED");
 assertThat(issue.status()).isEqualTo("RESOLVED");
 assertThat(issue.severity()).isEqualTo("BLOCKER");
 assertThat(issue.assigneeUuid()).isEqualTo("uuid-of-guy1");
 assertThat(issue.authorLogin()).isEqualTo("guy2");
 assertThat(issue.line()).isEqualTo(444);
 assertThat(issue.ruleId()).isEqualTo(200);
 assertThat(issue.componentUuid()).isEqualTo("FILE1");
 assertThat(issue.projectUuid()).isEqualTo("PROJECT1");
 assertThat(issue.moduleUuid()).isEqualTo("PROJECT1");
 assertThat(issue.modulePath()).isEqualTo(".PROJECT1.");
 assertThat(issue.directoryPath()).isEqualTo("src/main/java");
 assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
 assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
 assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
 assertThat(issue.type().getDbConstant()).isEqualTo(2);
}

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

@Test
public void copy_effort_for_external_issues() {
 issue.setGap(null);
 issue.setIsFromExternalRuleEngine(true);
 issue.setEffort(Duration.create(20l));
 rule.setFunction(null);
 assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(20l);
}

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

assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(1);
assertThat(issue.filePath()).isNull();
assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(2);
assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issue.getTags()).isEmpty();
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(1);
assertThat(issue.filePath()).isEqualTo("src/main/java");
assertThat(issue.getTags()).isEmpty();
assertThat(issue.effort().toMinutes()).isGreaterThan(0L);
assertThat(issue.type().getDbConstant()).isEqualTo(1);

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

/**
 * Return true if the given duration is greater than the current one.
 */
public boolean isGreaterThan(Duration other) {
 return toMinutes() > other.toMinutes();
}

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

/**
 * Return true if the given duration is greater than the current one.
 */
public boolean isGreaterThan(Duration other) {
 return toMinutes() > other.toMinutes();
}

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

@CheckForNull
public Long debtInMinutes() {
 return debt != null ? debt.toMinutes() : null;
}

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

@CheckForNull
public Long effortInMinutes() {
 return effort != null ? effort.toMinutes() : null;
}

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

public boolean setEffort(DefaultIssue issue, @Nullable Duration value, IssueChangeContext context) {
 Duration oldValue = issue.effort();
 if (!Objects.equals(value, oldValue)) {
  issue.setEffort(value);
  issue.setFieldChange(context, TECHNICAL_DEBT, oldValue != null ? oldValue.toMinutes() : null, value != null ? value.toMinutes() : null);
  issue.setUpdateDate(context.date());
  issue.setChanged(true);
  return true;
 }
 return false;
}

相关文章