diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2019-06-04 08:24:54 -0500 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-07-12 20:21:13 +0200 |
commit | 0f63c1e2bdf0c9fad3ca66ea64ef197bb16e6258 (patch) | |
tree | d173e5f6c3eb6d058e6bce023d74f28c6f7fe0fe /sonar-plugin-api/src/main/java/org/sonar/api/measures | |
parent | 6eb6107eaaf06d756bf517f0f06cf75021591fa0 (diff) | |
download | sonarqube-0f63c1e2bdf0c9fad3ca66ea64ef197bb16e6258.tar.gz sonarqube-0f63c1e2bdf0c9fad3ca66ea64ef197bb16e6258.zip |
Remove use of Guava in main sources of sonar-plugin-api
Diffstat (limited to 'sonar-plugin-api/src/main/java/org/sonar/api/measures')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java | 14 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/measures/MultisetDistributionFormat.java | 50 |
2 files changed, 9 insertions, 55 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java index f7e199ff592..ca5f062d66e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java @@ -31,9 +31,8 @@ import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.scanner.ScannerSide; import org.sonar.api.server.ServerSide; -import static com.google.common.base.MoreObjects.firstNonNull; -import static com.google.common.base.Preconditions.checkArgument; import static org.apache.commons.lang.StringUtils.isNotBlank; +import static org.sonar.api.utils.Preconditions.checkArgument; /** * Used to define a metric in a plugin. Should be used with {@link Metrics} extension point. @@ -219,7 +218,7 @@ public class Metric<G extends Serializable> implements Serializable, org.sonar.a * @param userManaged whether the metric is user managed */ private Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, @Nullable String domain, - boolean userManaged) { + boolean userManaged) { this.key = key; this.description = description; this.type = type; @@ -739,15 +738,20 @@ public class Metric<G extends Serializable> implements Serializable, org.sonar.a if (ValueType.PERCENT == this.type) { this.bestValue = (direction == DIRECTION_BETTER) ? 100.0 : 0.0; this.worstValue = (direction == DIRECTION_BETTER) ? 0.0 : 100.0; - this.decimalScale = firstNonNull(decimalScale, DEFAULT_DECIMAL_SCALE); + this.decimalScale = coalesce(decimalScale, DEFAULT_DECIMAL_SCALE); } else if (ValueType.FLOAT == this.type) { - this.decimalScale = firstNonNull(decimalScale, DEFAULT_DECIMAL_SCALE); + this.decimalScale = coalesce(decimalScale, DEFAULT_DECIMAL_SCALE); } return new Metric<>(this); } } + @CheckForNull + private static <T> T coalesce(@Nullable T a, @Nullable T b) { + return a == null ? b : a; + } + @Override public String key() { return getKey(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MultisetDistributionFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MultisetDistributionFormat.java deleted file mode 100644 index a65140eb491..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MultisetDistributionFormat.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.measures; - -import com.google.common.collect.Multiset; -import org.sonar.api.utils.KeyValueFormat; - -/** - * Format internal {@link com.google.common.collect.Multiset} of {@link CountDistributionBuilder} - * and {@link RangeDistributionBuilder} - */ -class MultisetDistributionFormat { - - private MultisetDistributionFormat() { - // only statics - } - - static String format(Multiset countBag) { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (Object obj : countBag.elementSet()) { - if (!first) { - sb.append(KeyValueFormat.PAIR_SEPARATOR); - } - sb.append(obj.toString()); - sb.append(KeyValueFormat.FIELD_SEPARATOR); - // -1 allows to include zero values - sb.append(countBag.count(obj) - 1); - first = false; - } - return sb.toString(); - } -} |