This is an automated email from the git hooks/post-receive script. New commit to branch feature/8204 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit db0df76812d1a127a7de8e5490db5b4dc3bcc343 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Apr 4 10:23:53 2016 +0200 Amélioration du cache des codes de prélèvements (ne pas utiliser des Integer en valeurs d'une map) --- .../service/sampling/CruiseSamplingCache.java | 60 +++++++++++++++++----- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java index 3fc5dea..cfb80f0 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/sampling/CruiseSamplingCache.java @@ -39,6 +39,7 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.util.Numbers; +import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -111,7 +112,7 @@ public class CruiseSamplingCache implements Closeable { /** * Le code prélèvement le plus grand pour chaque espèce */ - private final Map<Integer, Integer> highestSamplingCodeBySpecies = new HashMap<>(); + private final Map<Integer, MutableInt> highestSamplingCodeBySpecies = new HashMap<>(); public CruiseSamplingCache(Integer cruiseId, TuttiProtocol protocol, Caracteristic sexCaracteristic, Collection<Caracteristic> maturityCaracteristics) { this.cruiseId = cruiseId; @@ -207,9 +208,13 @@ public class CruiseSamplingCache implements Closeable { if (samplingCode != null) { int code = SamplingCodePrefix.extractSamplingCodeIdFromSamplingCode(samplingCode); - Integer highestSamplingCode = highestSamplingCodeBySpecies.get(species.getReferenceTaxonId()); - if (highestSamplingCode == null || code > highestSamplingCode) { - highestSamplingCodeBySpecies.put(species.getReferenceTaxonId(), code); + MutableInt highestSamplingCode = highestSamplingCodeBySpecies.get(species.getReferenceTaxonId()); + if (highestSamplingCode == null) { + highestSamplingCode = new MutableInt(); + highestSamplingCodeBySpecies.put(species.getReferenceTaxonId(), highestSamplingCode); + } + if (code > highestSamplingCode.intValue()) { + highestSamplingCode.setValue(code); } addSampling(fishingOperationId, optionalZone, species, gender, maturity, lengthStepInMm, samplingCode); @@ -588,7 +593,8 @@ public class CruiseSamplingCache implements Closeable { int operationSamplingNb = operationCache.decrementSamplingNb(operationKey); - removeSamplingCode(species.getReferenceTaxonId(), samplingCode); + removeSamplingCode(species.getReferenceTaxonId()); +// removeSamplingCode(species.getReferenceTaxonId(), samplingCode); if (log.isInfoEnabled()) { log.info("remove Sampling " + samplingKey + " => op " + operationSamplingNb + " / zone " + zoneSamplingNb + " / cruise " + totalSamplingNb); @@ -729,7 +735,9 @@ public class CruiseSamplingCache implements Closeable { } public int getNextSamplingCodeId(Integer speciesId) { - return highestSamplingCodeBySpecies.getOrDefault(speciesId, 0) + 1; + MutableInt samplingCode = highestSamplingCodeBySpecies.get(speciesId); + return (samplingCode == null ? 0 : samplingCode.intValue()) + 1; +// return highestSamplingCodeBySpecies.getOrDefault(speciesId, 0) + 1; } public int addSamplingCode(Integer speciesId, String samplingCode) { @@ -737,17 +745,43 @@ public class CruiseSamplingCache implements Closeable { Integer code = Integer.parseInt(codeParts[codeParts.length - 1]); // increment the highest sampling code if it is this code - return highestSamplingCodeBySpecies.compute(speciesId, - (key, highestSamplingCode) -> highestSamplingCode == null ? code : Math.max(highestSamplingCode, code)); +// return highestSamplingCodeBySpecies.compute(speciesId, +// (key, highestSamplingCode) -> highestSamplingCode == null ? code : Math.max(highestSamplingCode, code)); + + MutableInt samplingCodeFound = highestSamplingCodeBySpecies.get(speciesId); + if (samplingCodeFound==null) { + samplingCodeFound = new MutableInt(code); + highestSamplingCodeBySpecies.put(speciesId, samplingCodeFound); + } else { + samplingCodeFound.setValue(Math.max(samplingCodeFound.intValue(), code)); + } + return samplingCodeFound.intValue(); + // Ce code ne compile pas. +// return highestSamplingCodeBySpecies.compute(speciesId, +// (key, highestSamplingCode) -> { +// if (highestSamplingCode == null) { +// highestSamplingCode = new MutableInt(code); +// } else { +// int nexValue = Math.max(highestSamplingCode.intValue(), code); +// highestSamplingCode.setValue(nexValue); +// } +// return highestSamplingCode; +// }); } - public int removeSamplingCode(Integer speciesId, String samplingCode) { - String[] codeParts = samplingCode.split("#"); - Integer code = Integer.parseInt(codeParts[codeParts.length - 1]); + + public void removeSamplingCode(Integer speciesId) { +// public void removeSamplingCode(Integer speciesId, String samplingCode) { +// String[] codeParts = samplingCode.split("#"); +// Integer code = Integer.parseInt(codeParts[codeParts.length - 1]); // decrement the highest sampling code if it is this code - return highestSamplingCodeBySpecies.computeIfPresent(speciesId, - (key, highestSamplingCode) -> code.equals(highestSamplingCode) ? code - 1 : highestSamplingCode); + MutableInt samplingCodeFound = highestSamplingCodeBySpecies.get(speciesId); + if (samplingCodeFound!=null) { + samplingCodeFound.decrement(); + } +// return highestSamplingCodeBySpecies.computeIfPresent(speciesId, +// (key, highestSamplingCode) -> code.equals(highestSamplingCode) ? code - 1 : highestSamplingCode); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.