@Override public void calculateMetricValue(Entity entity) { SortedSet<Version> versions = entity.getVersions(); Version previousVersion = null; Double firstVersionMetricValue = null; if (!versions.isEmpty()) { previousVersion = versions.first(); firstVersionMetricValue = entity.getMetricValue(versions.first(), conventionalMetric); } onNewEntity(entity); for (Version version : versions) { Double previousMetricValue = entity.getMetricValue(previousVersion, conventionalMetric); Double currentMetricValue = entity.getMetricValue(version, conventionalMetric); Double value = calculateMetricValueForOneVersion( firstVersionMetricValue, previousMetricValue, currentMetricValue); entity.addMetricValue(version, this, value); previousVersion = version; } }
@Override public void acceptEntity(Entity entity, int level) { List<Rule> rules = entityRuleMap.get(entity.getClass()); if (rules != null) { SortedSet<Version> versions = entity.getVersions(); for (Version version : versions) { for (Rule rule : rules) { Bindings bindings = createBindings(entity, version); Detection detection = createOrRetrieveDetection(rule); try { Boolean detected = (Boolean) engine.eval(rule.getExpression(), bindings); if (detected) detection.addEntity(version, entity); } catch (ScriptException e) { errors.add(new RuleEvaluationError(version, entity, rule, e)); } } } } }