package uk.ac.ebi.atlas.species;

import org.apache.commons.lang.StringUtils;

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class SpeciesFactory {

    private final SpeciesPropertiesTrader speciesPropertiesTrader;

    @Inject
    public SpeciesFactory(SpeciesPropertiesTrader speciesPropertiesTrader) {
        this.speciesPropertiesTrader = speciesPropertiesTrader;
    }

    public Species create(String name) {
        return StringUtils.isNotEmpty(name) ? new Species(name, speciesPropertiesTrader.get(name)) : new Species("", SpeciesProperties.UNKNOWN);
    }
}

package uk.ac.ebi.atlas.species;

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class SpeciesFactory {

    private final SpeciesPropertiesTrader speciesPropertiesTrader;

    @Inject
    public SpeciesFactory(SpeciesPropertiesTrader speciesPropertiesTrader) {
        this.speciesPropertiesTrader = speciesPropertiesTrader;
    }

    public Species create(String name) {
        return new Species(name, speciesPropertiesTrader.get(name));
    }

    public Species createUnknownSpecies() {
        return new Species("", SpeciesProperties.UNKNOWN);
    }
}

Add explicit method to create an unknown species to express a clearer intent (sometimes a species will be unknown if we can’t map it to a reference species, sometimes we actually want an unknown species, no matter what it is)