org.sonar.api.config.Settings.getDefinition()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(107)

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

Settings.getDefinition介绍

[英]The definition related to the specified property. It may be empty.
[中]与指定属性相关的定义。它可能是空的。

代码示例

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

@Override
public String[] getStringArray(String key) {
 boolean multiValue = settings.getDefinition(key)
  .map(PropertyDefinition::multiValues)
  .orElse(false);
 return get(key)
  .map(v -> parseAsCsv(key, v, multiValue ? REPLACE_ENCODED_COMMAS : identity()))
  .orElse(ArrayUtils.EMPTY_STRING_ARRAY);
}

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

public Settings setProperty(String key, @Nullable String[] values) {
 requireNonNull(key, "key can't be null");
 String effectiveKey = key.trim();
 Optional<PropertyDefinition> def = getDefinition(effectiveKey);
 if (!def.isPresent() || (!def.get().multiValues())) {
  throw new IllegalStateException("Fail to set multiple values on a single value property " + key);
 }
 String text = null;
 if (values != null) {
  List<String> escaped = new ArrayList<>();
  for (String value : values) {
   if (null != value) {
    escaped.add(value.replace(",", "%2C"));
   } else {
    escaped.add("");
   }
  }
  String escapedValue = escaped.stream().collect(Collectors.joining(","));
  text = trim(escapedValue);
 }
 return setProperty(key, text);
}

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

/**
 * Value is split by comma and trimmed. Never returns null.
 * <br>
 * Examples :
 * <ul>
 * <li>"one,two,three " -&gt; ["one", "two", "three"]</li>
 * <li>"  one, two, three " -&gt; ["one", "two", "three"]</li>
 * <li>"one, , three" -&gt; ["one", "", "three"]</li>
 * </ul>
 */
public String[] getStringArray(String key) {
 String effectiveKey = definitions.validKey(key);
 Optional<PropertyDefinition> def = getDefinition(effectiveKey);
 if ((def.isPresent()) && (def.get().multiValues())) {
  String value = getString(key);
  if (value == null) {
   return ArrayUtils.EMPTY_STRING_ARRAY;
  }
  List<String> values = new ArrayList<>();
  for (String v : Splitter.on(",").trimResults().split(value)) {
   values.add(v.replace("%2C", ","));
  }
  return values.toArray(new String[values.size()]);
 }
 return getStringArrayBySeparator(key, ",");
}

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

@Override
public String[] getStringArray(String key) {
 boolean multiValue = settings.getDefinition(key)
  .map(PropertyDefinition::multiValues)
  .orElse(false);
 return get(key)
  .map(v -> parseAsCsv(key, v, multiValue ? REPLACE_ENCODED_COMMAS : identity()))
  .orElse(ArrayUtils.EMPTY_STRING_ARRAY);
}

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

public Settings setProperty(String key, @Nullable String[] values) {
 requireNonNull(key, "key can't be null");
 String effectiveKey = key.trim();
 Optional<PropertyDefinition> def = getDefinition(effectiveKey);
 if (!def.isPresent() || (!def.get().multiValues())) {
  throw new IllegalStateException("Fail to set multiple values on a single value property " + key);
 }
 String text = null;
 if (values != null) {
  List<String> escaped = new ArrayList<>();
  for (String value : values) {
   if (null != value) {
    escaped.add(value.replace(",", "%2C"));
   } else {
    escaped.add("");
   }
  }
  String escapedValue = escaped.stream().collect(Collectors.joining(","));
  text = trim(escapedValue);
 }
 return setProperty(key, text);
}

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

/**
 * Value is split by comma and trimmed. Never returns null.
 * <br>
 * Examples :
 * <ul>
 * <li>"one,two,three " -&gt; ["one", "two", "three"]</li>
 * <li>"  one, two, three " -&gt; ["one", "two", "three"]</li>
 * <li>"one, , three" -&gt; ["one", "", "three"]</li>
 * </ul>
 */
public String[] getStringArray(String key) {
 String effectiveKey = definitions.validKey(key);
 Optional<PropertyDefinition> def = getDefinition(effectiveKey);
 if ((def.isPresent()) && (def.get().multiValues())) {
  String value = getString(key);
  if (value == null) {
   return ArrayUtils.EMPTY_STRING_ARRAY;
  }
  List<String> values = new ArrayList<>();
  for (String v : Splitter.on(",").trimResults().split(value)) {
   values.add(v.replace("%2C", ","));
  }
  return values.toArray(new String[values.size()]);
 }
 return getStringArrayBySeparator(key, ",");
}

相关文章