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

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

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

Duration.create介绍

[英]Create a Duration from a number of minutes.
[中]根据分钟数创建持续时间。

代码示例

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

/**
 * Add the given duration to the current one.
 */
public Duration add(Duration with) {
 return Duration.create(durationInMinutes + with.durationInMinutes);
}

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

/**
 * Create a Duration object from a number of minutes
 */
public Duration create(long minutes) {
 return Duration.create(minutes);
}

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

/**
 * Subtract the given duration to the current one.
 */
public Duration subtract(Duration with) {
 return Duration.create(durationInMinutes - with.durationInMinutes);
}

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

/**
 * Multiply the duration with the given factor.
 */
public Duration multiply(int factor) {
 return Duration.create(durationInMinutes * factor);
}

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

@CheckForNull
public Duration effort() {
 Number effort = getNullableField(IssueIndexDefinition.FIELD_ISSUE_EFFORT);
 return (effort != null) ? Duration.create(effort.longValue()) : null;
}

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

@Test
public void decode() {
 assertThat(Duration.decode("    15 d  23  h     42min  ", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES + 23 * ONE_HOUR_IN_MINUTES + 42 * ONE_MINUTE));
 assertThat(Duration.decode("15d23h42min", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES + 23 * ONE_HOUR_IN_MINUTES + 42 * ONE_MINUTE));
 assertThat(Duration.decode("23h", HOURS_IN_DAY)).isEqualTo(Duration.create(23 * ONE_HOUR_IN_MINUTES));
 assertThat(Duration.decode("15d", HOURS_IN_DAY)).isEqualTo(Duration.create(15 * ONE_DAY_IN_MINUTES));
 assertThat(Duration.decode("42min", HOURS_IN_DAY)).isEqualTo(Duration.create(42 * ONE_MINUTE));
 assertThat(Duration.decode("0min", HOURS_IN_DAY)).isEqualTo(Duration.create(0));
 assertThat(Duration.decode("25h61min", HOURS_IN_DAY)).isEqualTo(Duration.create(25 * ONE_HOUR_IN_MINUTES + 61));
}

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

@Test
public void encode() {
 assertThat(Duration.create(2 * ONE_DAY_IN_MINUTES + 5 * ONE_HOUR_IN_MINUTES + 46 * ONE_MINUTE).encode(HOURS_IN_DAY)).isEqualTo("2d5h46min");
 assertThat(Duration.create(ONE_DAY_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1d");
 assertThat(Duration.create(ONE_HOUR_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1h");
 assertThat(Duration.create(HOURS_IN_DAY * ONE_HOUR_IN_MINUTES).encode(HOURS_IN_DAY)).isEqualTo("1d");
 assertThat(Duration.create(ONE_MINUTE).encode(HOURS_IN_DAY)).isEqualTo("1min");
 assertThat(Duration.create(0).encode(HOURS_IN_DAY)).isEqualTo("0min");
}

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

@Test
public void format() {
 assertThat(underTest.format(Duration.create(5 * ONE_DAY))).isEqualTo("5d");
 assertThat(underTest.format(Duration.create(2 * ONE_HOUR))).isEqualTo("2h");
 assertThat(underTest.format(Duration.create(ONE_MINUTE))).isEqualTo("1min");
 assertThat(underTest.format(Duration.create(5 * ONE_DAY + 2 * ONE_HOUR))).isEqualTo("5d 2h");
 assertThat(underTest.format(Duration.create(2 * ONE_HOUR + ONE_MINUTE))).isEqualTo("2h 1min");
 assertThat(underTest.format(Duration.create(5 * ONE_DAY + 2 * ONE_HOUR + ONE_MINUTE))).isEqualTo("5d 2h");
}

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

@Test
public void display_negative_duration() {
 assertThat(underTest.format(Duration.create(-5 * ONE_DAY))).isEqualTo("-5d");
 assertThat(underTest.format(Duration.create(-2 * ONE_HOUR))).isEqualTo("-2h");
 assertThat(underTest.format(Duration.create(-1 * ONE_MINUTE))).isEqualTo("-1min");
}

代码示例来源: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

@Test
public void display_zero_without_unit() {
 assertThat(underTest.format(Duration.create(0))).isEqualTo("0");
}

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

@Test
public void test_equals_and_hashcode() throws Exception {
 Duration duration = Duration.create(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);
 Duration durationWithSameValue = Duration.create(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE);
 Duration durationWithDifferentValue = Duration.create(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES);
 assertThat(duration).isEqualTo(duration);
 assertThat(durationWithSameValue).isEqualTo(duration);
 assertThat(durationWithDifferentValue).isNotEqualTo(duration);
 assertThat(duration).isNotEqualTo(null);
 assertThat(duration.hashCode()).isEqualTo(duration.hashCode());
 assertThat(durationWithSameValue.hashCode()).isEqualTo(duration.hashCode());
 assertThat(durationWithDifferentValue.hashCode()).isNotEqualTo(duration.hashCode());
}

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

@Test
public void set_debt() {
 underTest.setDebt(Duration.create(55));
 assertThat(underTest.getFieldValue(EFFORT + ".count")).isEqualTo("55min");
}

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

private DefaultIssue oldBugIssue(long effort) {
 return newCodeSmellIssueWithoutEffort()
  .setEffort(Duration.create(effort))
  .setType(RuleType.BUG)
  .setCreationDate(new Date(OLD_ISSUES_DATES[random.nextInt(OLD_ISSUES_DATES.length)]));
}

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

private DefaultIssue oldCodeSmellIssue(long effort) {
 return newCodeSmellIssueWithoutEffort()
  .setEffort(Duration.create(effort))
  .setType(RuleType.CODE_SMELL)
  .setCreationDate(new Date(OLD_ISSUES_DATES[random.nextInt(OLD_ISSUES_DATES.length)]));
}

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

private DefaultIssue oldVulnerabilityIssue(long effort) {
 return newCodeSmellIssueWithoutEffort()
  .setEffort(Duration.create(effort))
  .setType(RuleType.VULNERABILITY)
  .setCreationDate(new Date(OLD_ISSUES_DATES[random.nextInt(OLD_ISSUES_DATES.length)]));
}

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

@Test
public void set_past_technical_debt_without_previous_value() {
 Duration newDebt = Duration.create(15 * 8 * 60);
 issue.setEffort(newDebt);
 boolean updated = underTest.setPastEffort(issue, null, context);
 assertThat(updated).isTrue();
 assertThat(issue.effort()).isEqualTo(newDebt);
 assertThat(issue.mustSendNotifications()).isFalse();
 FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT);
 assertThat(diff.oldValue()).isNull();
 assertThat(diff.newValue()).isEqualTo(15L * 8 * 60);
}

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

@Test
public void set_past_technical_debt_with_null_new_value() {
 issue.setEffort(null);
 Duration previousDebt = Duration.create(10 * 8 * 60);
 boolean updated = underTest.setPastEffort(issue, previousDebt, context);
 assertThat(updated).isTrue();
 assertThat(issue.effort()).isNull();
 assertThat(issue.mustSendNotifications()).isFalse();
 FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT);
 assertThat(diff.oldValue()).isEqualTo(10L * 8 * 60);
 assertThat(diff.newValue()).isNull();
}

代码示例来源: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

private void sendNewIssuesNotification(NewIssuesStatistics statistics, Component project, long analysisDate, NotificationStatistics notificationStatistics) {
 NewIssuesStatistics.Stats globalStatistics = statistics.globalStatistics();
 NewIssuesNotification notification = newIssuesNotificationFactory
  .newNewIssuesNotification()
  .setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest())
  .setProjectVersion(project.getProjectAttributes().getVersion())
  .setAnalysisDate(new Date(analysisDate))
  .setStatistics(project.getName(), globalStatistics)
  .setDebt(Duration.create(globalStatistics.effort().getOnLeak()));
 notificationStatistics.newIssuesDeliveries += service.deliver(notification);
 notificationStatistics.newIssues++;
}

相关文章