org.sonar.api.measures
Class RangeDistributionBuilder

java.lang.Object
  extended by org.sonar.api.measures.RangeDistributionBuilder
All Implemented Interfaces:
MeasureBuilder

public class RangeDistributionBuilder
extends Object
implements MeasureBuilder

Utility to build a distribution based on defined ranges

An example of usage : you wish to record the percentage of lines of code that belong to method with pre-defined ranges of complexity.

Since:
1.10

Constructor Summary
RangeDistributionBuilder(Metric<String> metric)
           
RangeDistributionBuilder(Metric<String> metric, Number[] bottomLimits)
          RangeDistributionBuilder for a metric and a defined range Each entry is initialized at zero
 
Method Summary
 RangeDistributionBuilder add(Measure<String> measure)
          Adds an existing Distribution to the current one.
 RangeDistributionBuilder add(Number value)
          Increments an entry by 1
 RangeDistributionBuilder add(Number value, int count)
          Increments an entry
 Measure<String> build()
          Shortcut for build(true)
 Measure<String> build(boolean allowEmptyData)
          Used to build a measure from the current object
 RangeDistributionBuilder clear()
          Resets all entries to zero
 Number[] getBottomLimits()
          Gives the bottom limits of ranges used
 boolean isEmpty()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangeDistributionBuilder

public RangeDistributionBuilder(Metric<String> metric,
                                Number[] bottomLimits)
RangeDistributionBuilder for a metric and a defined range Each entry is initialized at zero

Parameters:
metric - the metric to record the measure against
bottomLimits - the bottom limits of ranges to be used

RangeDistributionBuilder

public RangeDistributionBuilder(Metric<String> metric)
Method Detail

getBottomLimits

public Number[] getBottomLimits()
Gives the bottom limits of ranges used

Returns:
the bottom limits of defined range for the distribution

add

public RangeDistributionBuilder add(Number value)
Increments an entry by 1

Parameters:
value - the value to use to pick the entry to increment
Returns:
the current object

add

public RangeDistributionBuilder add(Number value,
                                    int count)
Increments an entry

Parameters:
value - the value to use to pick the entry to increment
count - the number by which to increment
Returns:
the current object

add

public RangeDistributionBuilder add(@Nullable
                                    Measure<String> measure)
Adds an existing Distribution to the current one. It will create the entries if they don't exist. Can be used to add the values of children resources for example

Since 2.2, the distribution returned will be invalidated in case the measure given does not use the same bottom limits

Parameters:
measure - the measure to add to the current one
Returns:
the current object

clear

public RangeDistributionBuilder clear()
Resets all entries to zero

Returns:
the current object

isEmpty

public boolean isEmpty()
Returns:
whether the current object is empty or not

build

public Measure<String> build()
Shortcut for build(true)

Specified by:
build in interface MeasureBuilder
Returns:
the built measure

build

public Measure<String> build(boolean allowEmptyData)
Used to build a measure from the current object

Parameters:
allowEmptyData - should be built if current object is empty
Returns:
the built measure


Copyright © 2009–2014 SonarSource. All rights reserved.