This is an automated email from the git hooks/post-receive script. New commit to branch feature/8228 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit e2a1d8ad4c5c9e5fa8ea8ae9b6c3b4933356f6a6 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 12 02:52:11 2016 +0200 Ne pas utiliser d'optional à tout bout de champ (IndividualObservationUICache#samplingCache) --- .../frequency/IndividualObservationUICache.java | 93 +++++++++++----------- .../frequency/SpeciesFrequencyUIHandler.java | 2 +- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/IndividualObservationUICache.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/IndividualObservationUICache.java index 03b7b97..f441d61 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/IndividualObservationUICache.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/IndividualObservationUICache.java @@ -27,7 +27,6 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.protocol.CalcifiedPiecesSamplingDefinition; import fr.ifremer.tutti.persistence.entities.protocol.Zone; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; @@ -68,7 +67,7 @@ public class IndividualObservationUICache implements Closeable { private static final Log log = LogFactory.getLog(IndividualObservationUICache.class); private final SamplingListener samplingListener; - private final Optional<CruiseSamplingCache> samplingCache; + private final CruiseSamplingCache samplingCache; private final SpeciesFrequencyUIModel uiModel; private SpeciesBatchRowModel speciesEditRow; @@ -95,7 +94,7 @@ public class IndividualObservationUICache implements Closeable { */ private boolean on; - public IndividualObservationUICache(Optional<CruiseSamplingCache> samplingCache, SpeciesFrequencyUIModel uiModel, Caracteristic sexCaracteristic) { + public IndividualObservationUICache(CruiseSamplingCache samplingCache, SpeciesFrequencyUIModel uiModel) { this.samplingCache = samplingCache; this.uiModel = uiModel; @@ -116,7 +115,7 @@ public class IndividualObservationUICache implements Closeable { } else { // model no more loading, cache is on if data cache is present - on = samplingCache.isPresent(); + on = withSamplingCache(); if (log.isInfoEnabled()) { if (on) { log.info("Cache is on : ui model loading is done and sampling cache is present"); @@ -181,25 +180,29 @@ public class IndividualObservationUICache implements Closeable { this.speciesEditRow = speciesEditRow; this.species = speciesEditRow.getSpecies(); this.fishingOperation = fishingOperation; - if (samplingCache.isPresent()) { - samplingCache.get().addSamplingListener(samplingListener); + if (withSamplingCache()) { + samplingCache.addSamplingListener(samplingListener); } this.samplingCodesAvailable.clear(); this.samplingCodesNotAvailable.clear(); - + individualObservationRows.stream() .filter(individualObservationRow -> individualObservationRow.getSamplingCode() != null) .forEach(individualObservationRow -> addSamplingCodeNotAvailable(individualObservationRow.getSamplingCode())); } + protected boolean withSamplingCache() { + return samplingCache != null; + } + @Override public void close() { this.ui = null; this.speciesEditRow = null; this.species = null; this.fishingOperation = null; - if (samplingCache.isPresent()) { - samplingCache.get().removeSamplingListener(samplingListener); + if (withSamplingCache()) { + samplingCache.removeSamplingListener(samplingListener); } } @@ -248,12 +251,12 @@ public class IndividualObservationUICache implements Closeable { return; } - Boolean maturity = samplingCache.get().getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); - samplingCache.get().addIndividualObservation(fishingOperation, - species, - gender, - maturity, - uiModel.getLengthStepInMm(lengthStep)); + Boolean maturity = samplingCache.getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); + samplingCache.addIndividualObservation(fishingOperation, + species, + gender, + maturity, + uiModel.getLengthStepInMm(lengthStep)); if (samplingCode.isPresent()) { incrementsSamplingNb(gender, maturityQualitativeValue, lengthStep, samplingCode.get()); @@ -280,14 +283,14 @@ public class IndividualObservationUICache implements Closeable { return; } - Boolean maturity = samplingCache.get().getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); + Boolean maturity = samplingCache.getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); Integer lengthStepInMm = lengthStep == null ? null : uiModel.getLengthStepInMm(lengthStep); - samplingCache.get().addSampling(fishingOperation, - species, - gender, - maturity, - lengthStepInMm, - samplingCode); + samplingCache.addSampling(fishingOperation, + species, + gender, + maturity, + lengthStepInMm, + samplingCode); // Le code n'est plus utilisable addSamplingCodeNotAvailable(samplingCode); @@ -340,12 +343,12 @@ public class IndividualObservationUICache implements Closeable { return; } - Boolean maturity = samplingCache.get().getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); - samplingCache.get().removeIndividualObservation(fishingOperation, - species, - gender, - maturity, - uiModel.getLengthStepInMm(lengthStep)); + Boolean maturity = samplingCache.getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); + samplingCache.removeIndividualObservation(fishingOperation, + species, + gender, + maturity, + uiModel.getLengthStepInMm(lengthStep)); if (samplingCode.isPresent()) { decrementsSamplingNb(gender, maturityQualitativeValue, lengthStep, samplingCode.get()); @@ -372,13 +375,13 @@ public class IndividualObservationUICache implements Closeable { return; } - Boolean maturity = samplingCache.get().getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); - samplingCache.get().removeSampling(fishingOperation, - species, - gender, - maturity, - uiModel.getLengthStepInMm(lengthStep), - samplingCode); + Boolean maturity = samplingCache.getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); + samplingCache.removeSampling(fishingOperation, + species, + gender, + maturity, + uiModel.getLengthStepInMm(lengthStep), + samplingCode); addSamplingCodeAvailable(samplingCode); @@ -442,8 +445,8 @@ public class IndividualObservationUICache implements Closeable { public void addSamplingCodeAvailable(String samplingCode) { int samplingCodeNumber = SamplingCodePrefix.extractSamplingCodeIdFromSamplingCode(samplingCode); - if (log.isInfoEnabled()) { - log.info(String.format("Make samplingCode: %s (%d) available", samplingCode, samplingCodeNumber)); + if (log.isDebugEnabled()) { + log.debug(String.format("Make samplingCode: %s (%d) available", samplingCode, samplingCodeNumber)); } samplingCodesNotAvailable.remove(samplingCodeNumber); samplingCodesAvailable.add(samplingCodeNumber); @@ -453,8 +456,8 @@ public class IndividualObservationUICache implements Closeable { public void addSamplingCodeNotAvailable(String samplingCode) { int samplingCodeNumber = SamplingCodePrefix.extractSamplingCodeIdFromSamplingCode(samplingCode); - if (log.isInfoEnabled()) { - log.info(String.format("Make samplingCode: %s (%d) not available", samplingCode, samplingCodeNumber)); + if (log.isDebugEnabled()) { + log.debug(String.format("Make samplingCode: %s (%d) not available", samplingCode, samplingCodeNumber)); } samplingCodesNotAvailable.add(samplingCodeNumber); samplingCodesAvailable.remove(samplingCodeNumber); @@ -464,17 +467,15 @@ public class IndividualObservationUICache implements Closeable { public void updateSelectedRow(Optional<IndividualObservationBatchRowModel> optSelectedRow) { Optional<SamplingEvent> event; - if (samplingCache.isPresent() && optSelectedRow.isPresent() && optSelectedRow.get().withSize()) { + if (withSamplingCache() && optSelectedRow.isPresent() && optSelectedRow.get().withSize()) { IndividualObservationBatchRowModel selectedRow = optSelectedRow.get(); - CruiseSamplingCache cruiseSamplingCache = samplingCache.get(); - Optional<CaracteristicQualitativeValue> maturityQualitativeValue = uiModel.getOptionalMaturityValue(selectedRow); - Boolean maturity = cruiseSamplingCache.getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); + Boolean maturity = samplingCache.getMaturity(uiModel.getBatch().getSpecies().getReferenceTaxonId(), maturityQualitativeValue); int lengthstep = uiModel.getLengthStepInMm(selectedRow.getSize()); - event = cruiseSamplingCache.getEventForSummary(fishingOperation, species, maturity, uiModel.getGender(selectedRow), lengthstep); + event = samplingCache.getEventForSummary(fishingOperation, species, maturity, uiModel.getGender(selectedRow), lengthstep); } else { event = Optional.empty(); @@ -505,8 +506,8 @@ public class IndividualObservationUICache implements Closeable { Decorator<Species> speciesDecorator = ui.getHandler().getDecorator(Species.class, DecoratorService.WITH_SURVEY_CODE); String key = speciesDecorator.toString(species) - + " " + Numbers.convertFromMm(event.getLengthStep(), uiModel.getLengthStepCaracteristicUnit()) - + " " + uiModel.getLengthStepCaracteristicUnit(); + + " " + Numbers.convertFromMm(event.getLengthStep(), uiModel.getLengthStepCaracteristicUnit()) + + " " + uiModel.getLengthStepCaracteristicUnit(); if (event.getGender() != null) { key += " " + event.getGender().getDescription(); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java index ee7faf3..c2b8b6d 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java @@ -504,7 +504,7 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci }); this.individualObservationUICache = new IndividualObservationUICache( - getDataContext().getOptionalCruiseSamplingCache(), model, sexCaracteristic); + getDataContext().getOptionalCruiseSamplingCache().orElse(null), model); } @Override -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.