001/* 002 * SonarQube, open source software quality management tool. 003 * Copyright (C) 2008-2014 SonarSource 004 * mailto:contact AT sonarsource DOT com 005 * 006 * SonarQube 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 * SonarQube 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 */ 020 021package org.sonar.api.ce.measure.test; 022 023import javax.annotation.concurrent.Immutable; 024import org.sonar.api.ce.measure.Measure; 025 026import static com.google.common.base.Preconditions.checkState; 027import static java.util.Objects.requireNonNull; 028 029@Immutable 030public class TestMeasure implements Measure { 031 032 private Integer intValue; 033 private Long longValue; 034 private Double doubleValue; 035 private String stringValue; 036 private Boolean booleanValue; 037 038 public static TestMeasure createMeasure(double doubleValue){ 039 TestMeasure measure = new TestMeasure(); 040 measure.doubleValue = doubleValue; 041 return measure; 042 } 043 044 public static TestMeasure createMeasure(int intValue) { 045 TestMeasure measure = new TestMeasure(); 046 measure.intValue = intValue; 047 return measure; 048 } 049 050 public static TestMeasure createMeasure(long longValue) { 051 TestMeasure measure = new TestMeasure(); 052 measure.longValue = longValue; 053 return measure; 054 } 055 056 public static TestMeasure createMeasure(String stringValue) { 057 TestMeasure measure = new TestMeasure(); 058 measure.stringValue = requireNonNull(stringValue, "Value cannot be null"); 059 return measure; 060 } 061 062 public static TestMeasure createMeasure(boolean booleanValue) { 063 TestMeasure measure = new TestMeasure(); 064 measure.booleanValue = requireNonNull(booleanValue, "Value cannot be null"); 065 return measure; 066 } 067 068 @Override 069 public int getIntValue() { 070 checkState(intValue != null, "Not an integer measure"); 071 return intValue; 072 } 073 074 @Override 075 public long getLongValue() { 076 checkState(longValue != null, "Not a long measure"); 077 return longValue; 078 } 079 080 @Override 081 public double getDoubleValue() { 082 checkState(doubleValue != null, "Not a double measure"); 083 return doubleValue; 084 } 085 086 @Override 087 public String getStringValue() { 088 checkState(stringValue != null, "Not a string measure"); 089 return stringValue; 090 } 091 092 @Override 093 public boolean getBooleanValue() { 094 checkState(booleanValue != null, "Not a boolean measure"); 095 return booleanValue; 096 } 097}