@Test public void testRemoveLooseValues() { List<String> list = new ArrayList<String>(); list.add("test1"); list.add("test2"); Leaf l = new Leaf(); Map<String, Values> map = new HashMap<String, Values>(); Value v1 = new IntegerValue(); v1.setScale(new IntegerScale()); Values values1 = new Values(); values1.add(v1); map.put("test1", values1); Value v2 = new IntegerValue(); v2.setScale(new IntegerScale()); Values values2 = new Values(); values2.add(v2); map.put("test2", values2); Value v3 = new IntegerValue(); v3.setScale(new IntegerScale()); Values values3 = new Values(); values3.add(v3); map.put("test3", values3); l.setValueMap(map); l.removeLooseValues(list, 5); Map<String, Values> res = l.getValueMap(); Assert.assertTrue(res.containsKey("test1")); Assert.assertTrue(res.containsKey("test2")); Assert.assertFalse(res.containsKey("test3")); }
public int removeLooseValues(List<String> alternatives, int records) { int number = 0; Iterator<String> it = valueMap.keySet().iterator(); List<String> namesToRemove = new ArrayList<String>(); while (it.hasNext()) { String altName = it.next(); if (!alternatives.contains(altName)) { log.warn("removing Values for " + altName + " at leaf " + getName()); namesToRemove.add(altName); number++; } else { Values v = valueMap.get(altName); int removed = v.removeLooseValues(isSingle() ? 1 : records); log.warn("removed " + removed + " Value objects " + "for " + altName + " at leaf " + getName()); number += removed; } } for (String s : namesToRemove) { valueMap.remove(s); } return number; }
Leaf extends TreeNode { public int removeLooseValues(List<String> alternatives, int records) { int number = 0; Iterator<String> it = valueMap.keySet().iterator(); List<String> namesToRemove = new ArrayList<String>(); while (it.hasNext()) { String altName = it.next(); if (!alternatives.contains(altName)) { log.warn("removing Values for " + altName + " at leaf " + getName()); namesToRemove.add(altName); number++; } else { Values v = valueMap.get(altName); int removed = v.removeLooseValues(isSingle() ? 1 : records); log.warn("removed " + removed + " Value objects " + "for " + altName + " at leaf " + getName()); number += removed; } } for (String s : namesToRemove) { valueMap.remove(s); } return number; } }
Leaf extends TreeNode { public int removeLooseValues(List<String> alternatives, int records) { int number = 0; Iterator<String> it = valueMap.keySet().iterator(); List<String> namesToRemove = new ArrayList<String>(); while (it.hasNext()) { String altName = it.next(); if (!alternatives.contains(altName)) { log.warn("removing Values for " + altName + " at leaf " + getName()); namesToRemove.add(altName); number++; } else { Values v = valueMap.get(altName); int removed = v.removeLooseValues(isSingle() ? 1 : records); log.warn("removed " + removed + " Value objects " + "for " + altName + " at leaf " + getName()); number += removed; } } for (String s : namesToRemove) { valueMap.remove(s); } return number; } Leaf(); }
Leaf extends TreeNode { public int removeLooseValues(List<String> alternatives, int records) { int number = 0; Iterator<String> it = valueMap.keySet().iterator(); List<String> namesToRemove = new ArrayList<String>(); while (it.hasNext()) { String altName = it.next(); if (!alternatives.contains(altName)) { log.warn("removing Values for " + altName + " at leaf " + getName()); namesToRemove.add(altName); number++; } else { Values v = valueMap.get(altName); int removed = v.removeLooseValues(isSingle() ? 1 : records); log.warn("removed " + removed + " Value objects " + "for " + altName + " at leaf " + getName()); number += removed; } } for (String s : namesToRemove) { valueMap.remove(s); } return number; } 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(); }
Leaf extends TreeNode { public int removeLooseValues(List<String> alternatives, int records) { int number = 0; Iterator<String> it = valueMap.keySet().iterator(); List<String> namesToRemove = new ArrayList<String>(); while (it.hasNext()) { String altName = it.next(); if (!alternatives.contains(altName)) { log.warn("removing Values for " + altName + " at leaf " + getName()); namesToRemove.add(altName); number++; } else { Values v = valueMap.get(altName); int removed = v.removeLooseValues(isSingle() ? 1 : records); log.warn("removed " + removed + " Value objects " + "for " + altName + " at leaf " + getName()); number += removed; } } for (String s : namesToRemove) { valueMap.remove(s); } return number; } 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();  }