001/* 002 * SonarQube 003 * Copyright (C) 2009-2017 SonarSource SA 004 * mailto:info AT sonarsource DOT com 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with this program; if not, write to the Free Software Foundation, 018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 */ 020package org.sonar.api.ce.measure.test; 021 022import javax.annotation.concurrent.Immutable; 023import org.sonar.api.ce.measure.Measure; 024 025import static com.google.common.base.Preconditions.checkState; 026import static java.util.Objects.requireNonNull; 027 028@Immutable 029public class TestMeasure implements Measure { 030 031 private Integer intValue; 032 private Long longValue; 033 private Double doubleValue; 034 private String stringValue; 035 private Boolean booleanValue; 036 037 public static TestMeasure createMeasure(double doubleValue){ 038 TestMeasure measure = new TestMeasure(); 039 measure.doubleValue = doubleValue; 040 return measure; 041 } 042 043 public static TestMeasure createMeasure(int intValue) { 044 TestMeasure measure = new TestMeasure(); 045 measure.intValue = intValue; 046 return measure; 047 } 048 049 public static TestMeasure createMeasure(long longValue) { 050 TestMeasure measure = new TestMeasure(); 051 measure.longValue = longValue; 052 return measure; 053 } 054 055 public static TestMeasure createMeasure(String stringValue) { 056 TestMeasure measure = new TestMeasure(); 057 measure.stringValue = requireNonNull(stringValue, "Value cannot be null"); 058 return measure; 059 } 060 061 public static TestMeasure createMeasure(boolean booleanValue) { 062 TestMeasure measure = new TestMeasure(); 063 measure.booleanValue = requireNonNull(booleanValue, "Value cannot be null"); 064 return measure; 065 } 066 067 @Override 068 public int getIntValue() { 069 checkState(intValue != null, "Not an integer measure"); 070 return intValue; 071 } 072 073 @Override 074 public long getLongValue() { 075 checkState(longValue != null, "Not a long measure"); 076 return longValue; 077 } 078 079 @Override 080 public double getDoubleValue() { 081 checkState(doubleValue != null, "Not a double measure"); 082 return doubleValue; 083 } 084 085 @Override 086 public String getStringValue() { 087 checkState(stringValue != null, "Not a string measure"); 088 return stringValue; 089 } 090 091 @Override 092 public boolean getBooleanValue() { 093 checkState(booleanValue != null, "Not a boolean measure"); 094 return booleanValue; 095 } 096}