From 9039d018c877e698b9d4e33011123c672df71f50 Mon Sep 17 00:00:00 2001 From: Brian Remedios Date: Tue, 17 Oct 2006 02:04:43 +0000 Subject: [PATCH] added property descriptors & references to them git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4695 51baf565-9d33-0410-a72c-fc3788e3496d --- .../sourceforge/pmd/stat/StatisticalRule.java | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java b/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java index daa092730b..1bbfa684c1 100644 --- a/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java +++ b/pmd/src/net/sourceforge/pmd/stat/StatisticalRule.java @@ -3,15 +3,19 @@ */ package net.sourceforge.pmd.stat; -import net.sourceforge.pmd.AbstractRule; -import net.sourceforge.pmd.RuleContext; - import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import net.sourceforge.pmd.AbstractRule; +import net.sourceforge.pmd.PropertyDescriptor; +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.properties.DoubleProperty; +import net.sourceforge.pmd.properties.IntegerProperty; + /** * @author David Dixon-Peugh * Aug 8, 2002 StatisticalRule.java @@ -25,6 +29,23 @@ public abstract class StatisticalRule extends AbstractRule { private int count = 0; private double total = 0.0; + private static final PropertyDescriptor sigmaDescriptor = new DoubleProperty( + "sigma", "Sigma value", 0, 1.0f + ); + + private static final PropertyDescriptor minimumDescriptor = new DoubleProperty( + "minimum", "Minimum value", 0, 1.0f + ); + + private static final PropertyDescriptor topScoreDescriptor = new IntegerProperty( + "topscore", "Top score value", 0, 1.0f + ); + + private static final Map propertyDescriptorsByName = asFixedMap( new PropertyDescriptor[] { + sigmaDescriptor, minimumDescriptor, topScoreDescriptor + }); + + public void addDataPoint(DataPoint point) { count++; total += point.getScore(); @@ -37,14 +58,14 @@ public abstract class StatisticalRule extends AbstractRule { double deviation; double minimum = 0.0; - if (hasProperty("sigma")) { + if (hasProperty("sigma")) { // TODO - need to come up with a good default value deviation = getStdDev(); - double sigma = getDoubleProperty("sigma"); + double sigma = getDoubleProperty(sigmaDescriptor); minimum = getMean() + (sigma * deviation); } - if (hasProperty("minimum")) { - double mMin = getDoubleProperty("minimum"); + if (hasProperty("minimum")) { // TODO - need to come up with a good default value + double mMin = getDoubleProperty(minimumDescriptor); if (mMin > minimum) { minimum = mMin; } @@ -52,8 +73,8 @@ public abstract class StatisticalRule extends AbstractRule { SortedSet newPoints = applyMinimumValue(dataPoints, minimum); - if (hasProperty("topscore")) { - int topScore = getIntProperty("topscore"); + if (hasProperty("topscore")) { // TODO - need to come up with a good default value + int topScore = getIntProperty(topScoreDescriptor); if (newPoints.size() >= topScore) { newPoints = applyTopScore(newPoints, topScore); } @@ -126,4 +147,8 @@ public abstract class StatisticalRule extends AbstractRule { addViolationWithMessage(ctx, point.getNode(), point.getMessage()); } } + + protected Map propertiesByName() { + return propertyDescriptorsByName; + } }