You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FakeMeasure.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.qualitygate;
  21. import java.util.Optional;
  22. import java.util.OptionalDouble;
  23. import javax.annotation.Nullable;
  24. import org.sonar.api.measures.Metric;
  25. public class FakeMeasure implements QualityGateEvaluator.Measure {
  26. private Double leakValue;
  27. private Double value;
  28. private Metric.ValueType valueType;
  29. private FakeMeasure() {
  30. // nothing to do
  31. }
  32. public FakeMeasure(Metric.ValueType valueType) {
  33. this.valueType = valueType;
  34. }
  35. public FakeMeasure(@Nullable Double value) {
  36. this.value = value;
  37. this.valueType = Metric.ValueType.FLOAT;
  38. }
  39. public FakeMeasure(@Nullable Integer value) {
  40. this.value = value == null ? null : value.doubleValue();
  41. this.valueType = Metric.ValueType.INT;
  42. }
  43. public static FakeMeasure newMeasureOnLeak(@Nullable Integer value) {
  44. FakeMeasure measure = new FakeMeasure();
  45. measure.leakValue = value == null ? null : value.doubleValue();
  46. measure.valueType = Metric.ValueType.INT;
  47. return measure;
  48. }
  49. @Override
  50. public Metric.ValueType getType() {
  51. return valueType;
  52. }
  53. @Override
  54. public OptionalDouble getValue() {
  55. return value == null ? OptionalDouble.empty() : OptionalDouble.of(value);
  56. }
  57. @Override
  58. public Optional<String> getStringValue() {
  59. return Optional.empty();
  60. }
  61. @Override
  62. public OptionalDouble getNewMetricValue() {
  63. return leakValue == null ? OptionalDouble.empty() : OptionalDouble.of(leakValue);
  64. }
  65. }