Project

General

Profile

Revision cde6a65d

IDcde6a65d427fcb5b9c577e06c0ebad9f66352616
Parent ab96570c
Child 85d65189

Added by Andreas Müller about 2 years ago

cleanup

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/generate/PolytomousKeyGenerator.java
197 197
    private void handleLeaf(PolytomousKeyNode parent, Set<KeyTaxon> taxaCovered) {
198 198
        KeyStatement parentStatement = parent.getStatement();
199 199
        for(KeyTaxon taxon: taxaCovered){
200
            if  (taxon.taxon instanceof Taxon){
200
            if  (taxon.taxon != null){
201 201
                parent.setOrAddTaxon(taxon.taxon);
202 202
            }else{
203 203
                //FIXME handle other descriptions like specimen descriptions better
......
219 219
    private void handleCategorialFeature(PolytomousKeyNode parent, List<Feature> featuresLeft,
220 220
            Set<KeyTaxon> taxaCovered,
221 221
            Feature winnerFeature,
222
            Map<Feature, Set<State>> featureStatesFilter,
223
            boolean taxaDiscriminatedInPreviousStep) {
222
            Map<Feature, Set<State>> featureStatesFilter) {
224 223

  
225 224
        Map<Set<KeyTaxon>,Boolean> reuseWinner = new HashMap<>();
226 225

  
......
288 287
            Feature winnerFeature, Map<Set<KeyTaxon>, Boolean> reuseWinner,
289 288
            Map<Set<KeyTaxon>, List<State>> taxonStatesMap, Set<KeyTaxon> newTaxaCovered, Map<Feature,Set<State>> featureStatesFilter) {
290 289

  
290
        //to restore old state
291
        Set<State> oldFilterSet = featureStatesFilter.get(winnerFeature);
291 292
        Set<Feature> featuresAdded = new HashSet<>();
293

  
292 294
        boolean areTheTaxaDiscriminated = false;
293
        PolytomousKeyNode pkNode = PolytomousKeyNode.NewInstance();
294
        parent.addChild(pkNode);
295
        PolytomousKeyNode childNode = PolytomousKeyNode.NewInstance();
296
        parent.addChild(childNode);
295 297

  
296 298
        List<State> listOfStates = taxonStatesMap.get(newTaxaCovered);
297
        Set<State> oldFilterSet = featureStatesFilter.get(winnerFeature);
298 299
        if ((newTaxaCovered.size() > 0)){ //old: if the taxa are discriminated compared to those of the parent node, a child is created
299 300
        	areTheTaxaDiscriminated = (newTaxaCovered.size()!=taxaCovered.size());
300 301

  
......
310 311

  
311 312
        	String statementLabel = createStatement(listOfStates, numberOfStates);
312 313
            KeyStatement statement = KeyStatement.NewInstance(statementLabel);
313
        	pkNode.setStatement(statement);
314
        	childNode.setStatement(statement);
314 315
        	parent.setFeature(winnerFeature);
315 316

  
316 317
        	if (reuseWinner.get(newTaxaCovered)== Boolean.TRUE){
317 318
        	    featuresLeft.add(winnerFeature);
318
        	    addStatesToFilter(featureStatesFilter, winnerFeature, listOfStates);
319
        	    setStatesFilter(featureStatesFilter, winnerFeature, listOfStates);
319 320
        	}else{
320 321
        	    featuresLeft.remove(winnerFeature);
321 322
        	}
......
323 324

  
324 325
        boolean hasChildren = areTheTaxaDiscriminated && newTaxaCovered.size()>1;
325 326
        if (hasChildren){
326
            buildBranches(pkNode, featuresLeft, newTaxaCovered, featureStatesFilter, areTheTaxaDiscriminated);
327
            buildBranches(childNode, featuresLeft, newTaxaCovered, featureStatesFilter, areTheTaxaDiscriminated);
327 328
        }else{
328
            handleLeaf(pkNode, newTaxaCovered);
329
            handleLeaf(childNode, newTaxaCovered);
329 330
        }
331
        //restore old state before returning to parent node
330 332
        removeAddedDependendFeatures(featuresLeft, featuresAdded);
331 333
        featureStatesFilter.put(winnerFeature, oldFilterSet);
332 334
    }
333 335

  
334
    private void addStatesToFilter(Map<Feature, Set<State>> filter, Feature feature,
336
    private void setStatesFilter(Map<Feature, Set<State>> filter, Feature feature,
335 337
            List<State> listOfStates) {
336 338
        if (filter.get(feature)==null){
337 339
            filter.put(feature, new HashSet<>(listOfStates));

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)