Leaf extends TreeNode { public void removeValues(List<Alternative> list, int record) { for (Alternative a : list) { Values v = getValues(a.getName()); if ((v != null) && (v.getList().size() > record) && (v.getList().get(record) != null)) { log.debug("removing values:: " + getName() + " ," + record + ", " + a.getName()); v.getList().remove(record); } } } Leaf(); Map<String, Values> getValueMap(); void setValueMap(Map<String, Values> v); double getResult(Alternative a); TargetValues transformValues(Alternative a); Transformer getTransformer(); void setTransformer(Transformer transformer); void setValues(String alternative, Values values); Values getValues(String alternative); Scale getScale(); void setScale(Scale scale); void resetValues(List<Alternative> list); void setDefaultTransformer(); String getScaleByClassName(); void setScaleByClassName(String className); void changeScale(Scale newScale); void applyMeasure(final Measure m); void adjustScale(Scale newScale); @Override /** * This is a leaf, so: YES, I am. * @return true */ boolean isLeaf(); SampleAggregationMode getAggregationMode(); void setAggregationMode(SampleAggregationMode aggregationMode); EvaluationStatus getEvaluationStatus(); EvaluationStatus getTransformationStatus(); void removeValues(List<Alternative> list, int record); @Override boolean isValueMapProperlyInitialized(List<Alternative> alternatives, int numberRecords); void initValues(List<Alternative> list, int records, boolean addLinkage); void initScaleValueLinkage(List<Alternative> list, int records); @Override boolean isCompletelySpecified(List<ValidationError> errors); @Override boolean isCompletelyEvaluated(List<Alternative> alternatives, List<ValidationError> errors); @Override boolean isCompletelyTransformed(List<ValidationError> errors); @Override /** * Checks if the weight is in [0,1]. * @see Node#isCorrecltlyWeighted(List<String>) */ boolean isCorrectlyWeighted(List<ValidationError> errors); @Override /** * Returns a clone of this Leaf. Includes: <ul> * <li>{@link Scale}</li> * <li>{@link AggregationMode}</li> * <li>{@link ValueMap} which is initialised, but not cloned</li> * </ul> * Excludes transformer! The transformer is set to <code>null</code> */ TreeNode clone(); void handleChanges(IChangesHandler h); @Transient boolean isMapped(); void updateAlternativeName(String oldName, String newName); int removeLooseValues(List<String> alternatives, int records); void normalizeWeights(boolean recoursive); Measure getMeasure(); void setMeasure(Measure measure); void initTransformer(); void initTransformer(Double defaultTarget); double getPotentialOutputRange(); double getPotentialImpact(); double getActualOutputRange(); @Override void touchAll(String username); void touchIncludingScale();  }
@Test public void testRemoveValues() { Leaf l = new Leaf(); Alternative a = new Alternative("test", "test"); List<Alternative> alternatives = new ArrayList<Alternative>(); alternatives.add(a); Map<String, Values> map = new HashMap<String, Values>(); Value v1 = new IntegerValue(); Value v2 = new IntegerValue(); Value v3 = new IntegerValue(); v1.setScale(new IntegerScale()); Values values = new Values(); values.add(v1); values.add(v2); values.add(v3); map.put("test", values); l.setValueMap(map); Assert.assertTrue(l.getValueMap().get("test").size() == 3); l.removeValues(alternatives, 1); Assert.assertTrue(l.getValueMap().get("test").size() == 2); Assert.assertTrue(!l.getValueMap().get("test").getList().contains(v2)); l.removeValues(alternatives, 1); Assert.assertTrue(l.getValueMap().get("test").size() == 1); Assert.assertTrue(!l.getValueMap().get("test").getList().contains(v3)); }