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

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

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

Duration.encode介绍

[英]Return the duration in text, by using the given hours in day parameter to process hours.
Duration.decode("1d 1h", 8).encode(8) will return "1d 1h" Duration.decode("2d", 8).encode(16) will return "1d"
[中]通过使用给定的小时数参数来处理小时数,以文本形式返回持续时间。
期间解码(“1d 1h”,8)。编码(8)将返回“1d 1h”持续时间。解码(“2d”,8)。编码(16)将返回“1d”

代码示例

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

/**
 * Return the string value of the Duration.
 * <br>
 * Example : encode(Duration.encode("9d 10h")) -&gt; "10d2h"
 */
public String encode(Duration duration) {
 return duration.encode(HOURS_IN_DAY);
}

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

@CheckForNull
private static String sanitizeValue(String label, @Nullable String s) {
 if (StringUtils.isNotBlank(s)) {
  try {
   Duration duration = Duration.decode(s, HOURS_IN_DAY);
   return duration.encode(HOURS_IN_DAY);
  } catch (Exception e) {
   throw new IllegalArgumentException(String.format("Invalid %s: %s (%s)", label, s, e.getMessage()), e);
  }
 }
 return null;
}

代码示例来源: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: org.sonarsource.sonarqube/sonar-plugin-api

/**
 * Return the string value of the Duration.
 * <br>
 * Example : encode(Duration.encode("9d 10h")) -&gt; "10d2h"
 */
public String encode(Duration duration) {
 return duration.encode(HOURS_IN_DAY);
}

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

/**
 * Return the string value of the Duration.
 * <br>
 * Example : encode(Duration.encode("9d 10h")) -> "10d2h" (if sonar.technicalDebt.hoursInDay property is set to 8)
 */
public String encode(Duration duration) {
 return duration.encode(hoursInDay());
}

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

@CheckForNull
private String sanitizeValue(String label, @Nullable String s) {
 if (StringUtils.isNotBlank(s)) {
  try {
   Duration duration = Duration.decode(s, HOURS_IN_DAY);
   return duration.encode(HOURS_IN_DAY);
  } catch (Exception e) {
   throw new IllegalArgumentException(String.format("Invalid %s: %s (%s)", label, s, e.getMessage()), e);
  }
 }
 return null;
}

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

@CheckForNull
private static String sanitizeValue(String label, @Nullable String s) {
 if (StringUtils.isNotBlank(s)) {
  try {
   Duration duration = Duration.decode(s, HOURS_IN_DAY);
   return duration.encode(HOURS_IN_DAY);
  } catch (Exception e) {
   throw new IllegalArgumentException(String.format("Invalid %s: %s (%s)", label, s, e.getMessage()), e);
  }
 }
 return null;
}

相关文章