/** * Increments an entry by one * * @param value the value that should be incremented * @return the current object */ public CountDistributionBuilder add(Object value) { return add(value, 1); }
/** * Shortcut for <code>build(true)</code> * * @return the built measure */ @Override public Measure build() { return build(true); }
protected void computeDistributionFromChildren(DecoratorContext context) { CountDistributionBuilder builder = new CountDistributionBuilder(TrackerMetrics.TEMP_METHOD_LINES); for (Measure childMeasure : context.getChildrenMeasures(TrackerMetrics.TEMP_METHOD_LINES)) { builder.add(childMeasure); } context.saveMeasure(builder.build().setPersistenceMode(PersistenceMode.MEMORY)); }
/** * Creates an empty CountDistributionBuilder for a specified metric * * @param metric the metric */ public CountDistributionBuilder(Metric metric) { setMetric(metric); this.countBag = new TreeBag(); }
/** * Used to build a measure from the current object * * @param allowEmptyData should be built if current object is empty * @return the built measure */ public Measure build(boolean allowEmptyData) { if (!isEmpty() || allowEmptyData) { //-1 is a hack to include zero values return new Measure(metric, KeyValueFormat.format(countBag, -1)); } return null; }
/** * Increments an entry * * @param value the value that should be incremented * @param count the number by which to increment * @return the current object */ public CountDistributionBuilder add(Object value, int count) { if (count == 0) { addZero(value); } else { if (this.countBag.add(value, count)) { //hack this.countBag.add(value, 1); } } return this; }
private void computeMethodDistribution(Resource resource, DecoratorContext context) { JavaMethod method = (JavaMethod) resource; int lineNumber = method.getFromLine(); int numberOfLines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.LINES), 0.0).intValue(); CountDistributionBuilder builder = new CountDistributionBuilder(TrackerMetrics.TEMP_METHOD_LINES); builder.add(lineNumber, numberOfLines); context.saveMeasure(builder.build().setPersistenceMode(PersistenceMode.MEMORY)); }
@Override public void decorate(Resource resource, DecoratorContext context) { CountDistributionBuilder nclocDistribution = new CountDistributionBuilder(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION); if (ResourceUtils.isFile(resource)) { Language language = resource.getLanguage(); Measure ncloc = context.getMeasure(CoreMetrics.NCLOC); if (ncloc != null) { nclocDistribution.add(language != null ? language.getKey() : UNKNOWN_LANGUAGE_KEY, ncloc.getIntValue()); } } else { for (Measure measure : context.getChildrenMeasures(CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION)) { nclocDistribution.add(measure); } } Measure measure = nclocDistribution.build(false); if (measure != null) { context.saveMeasure(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 * * @param measure the measure to add to the current one * @return the current object */ public CountDistributionBuilder add(Measure measure) { if (measure != null && measure.getData() != null) { Map<String, String> map = KeyValueFormat.parse(measure.getData()); for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); int value = StringUtils.isBlank(entry.getValue()) ? 0 : Integer.parseInt(entry.getValue()); if (NumberUtils.isNumber(key)) { add(NumberUtils.toInt(key), value); } else { add(key, value); } } } return this; }