This is an automated email from the git hooks/post-receive script. New commit to branch feature/8130 in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit d08a3f6c146be98e8ba09dc396b97f5c16daf6dc Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Mar 16 08:42:49 2016 +0100 Utilisation des méthodes withXXX + ne plus utiliser guava quand c'est possible --- .../species/frequency/SpeciesFrequencyUIModel.java | 105 ++++++++++----------- 1 file changed, 48 insertions(+), 57 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java index bc64ca0..c375999 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java @@ -22,14 +22,12 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency; * #L% */ -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; +import fr.ifremer.tutti.persistence.entities.data.CopyIndividualObservationMode; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.protocol.Rtp; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.FrequencyConfigurationMode; -import fr.ifremer.tutti.persistence.entities.data.CopyIndividualObservationMode; import fr.ifremer.tutti.ui.swing.content.operation.catches.individualobservation.IndividualObservationBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; @@ -44,6 +42,7 @@ import org.jfree.data.xy.XYSeriesCollection; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -90,7 +89,7 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa public static final String PROPERTY_TOTAL_NUMBER = "totalNumber"; - public static final String PROPERTY_TOTAL_COMPUTED_OR_NOT_WEIGHT = "totalComputedOrNotWeight"; +// public static final String PROPERTY_TOTAL_COMPUTED_OR_NOT_WEIGHT = "totalComputedOrNotWeight"; public static final String PROPERTY_TOTAL_WEIGHT = "totalWeight"; @@ -253,9 +252,9 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa */ protected boolean canEditLengthStep = true; - /** * What to copy from the individual observations to the data table + * * @since 4.5 */ protected CopyIndividualObservationMode copyIndividualObservationMode = CopyIndividualObservationMode.NOTHING; @@ -314,7 +313,7 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa this.individualObservationWeightUnit = individualObservationWeightUnit; this.sampleCategoryModel = sampleCategoryModel; this.totalComputedOrNotWeight.addPropagateListener(PROPERTY_TOTAL_WEIGHT, this); - setEmptyRows(Sets.<SpeciesFrequencyRowModel>newHashSet()); + setEmptyRows(new HashSet<>()); XYSeries series = new XYSeries("", true, false); @@ -328,16 +327,16 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa averageWeightsDataset.setIntervalPositionFactor(0); averageWeightsDataset.setIntervalWidth(0); - this.defaultCaracteristic = defaultCaracteristic == null ? - Lists.<Caracteristic>newArrayList() : - Lists.newArrayList(defaultCaracteristic); + this.defaultCaracteristic = defaultCaracteristic == null + ? new ArrayList<>() + : new ArrayList<>(defaultCaracteristic); setIndividualObservationRowsInError(new HashSet<>()); } public void reloadRows() { - setEmptyRows(Sets.<SpeciesFrequencyRowModel>newHashSet()); + setEmptyRows(new HashSet<>()); XYSeries frequenciesSeries = frequenciesDataset.getSeries(0); frequenciesSeries.clear(); @@ -350,21 +349,18 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa if (rows != null) { - for (SpeciesFrequencyRowModel row : rows) { - - if (row.isValid()) { + rows.stream().filter(SpeciesFrequencyRowModel::isValid).forEach(row -> { - Float lengthStep = row.getLengthStep(); - Integer number = row.getNumber(); + Float lengthStep = row.getLengthStep(); + Integer number = row.getNumber(); - frequenciesSeries.addOrUpdate(lengthStep, number); + frequenciesSeries.addOrUpdate(lengthStep, number); - Float averageWeight = individualObservationWeightUnit.convertWeight(row.computeAverageWeight(), weightUnit); - if (averageWeight != null) { - averageWeightsSeries.addOrUpdate(lengthStep, averageWeight); - } + Float averageWeight = individualObservationWeightUnit.convertWeight(row.computeAverageWeight(), weightUnit); + if (averageWeight != null) { + averageWeightsSeries.addOrUpdate(lengthStep, averageWeight); } - } + }); } recomputeTotalNumberAndWeight(); @@ -387,17 +383,15 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa if (valid) { - // number conditions : not null and positive number - Integer number = row.getNumber(); - valid = number != null && number > 0; + // number conditions : number filled + valid = row.withNumber(); } if (valid) { - // weight conditions - Float weight = row.getWeight(); - valid = getNbRowsWithWeight() == 0 || (weight != null && weight > 0); + // weight conditions : with no weight, or weight filled + valid = getNbRowsWithWeight() == 0 || row.withWeight(); } @@ -459,9 +453,9 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa return lengthStepCaracteristic == null ? null : lengthStepCaracteristic.getUnit(); } - public Float getLengthStepCaracteristicPrecision() { - return lengthStepCaracteristic == null ? null : lengthStepCaracteristic.getPrecision(); - } +// public Float getLengthStepCaracteristicPrecision() { +// return lengthStepCaracteristic == null ? null : lengthStepCaracteristic.getPrecision(); +// } public Float getMinStep() { return minStep; @@ -565,11 +559,11 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa return totalComputedOrNotWeight; } - public void setTotalComputedOrNotWeight(ComputableData<Float> totalComputedOrNotWeight) { - Object oldValue = getTotalComputedOrNotWeight(); - this.totalComputedOrNotWeight = totalComputedOrNotWeight; - firePropertyChange(PROPERTY_TOTAL_COMPUTED_OR_NOT_WEIGHT, oldValue, totalComputedOrNotWeight); - } +// public void setTotalComputedOrNotWeight(ComputableData<Float> totalComputedOrNotWeight) { +// Object oldValue = getTotalComputedOrNotWeight(); +// this.totalComputedOrNotWeight = totalComputedOrNotWeight; +// firePropertyChange(PROPERTY_TOTAL_COMPUTED_OR_NOT_WEIGHT, oldValue, totalComputedOrNotWeight); +// } public Float getTotalWeight() { return totalComputedOrNotWeight.getData(); @@ -591,11 +585,12 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa firePropertyChange(PROPERTY_TOTAL_COMPUTED_WEIGHT, oldValue, totalComputedWeight); } + // Utilisé dans un validateur, ne pas supprimer public boolean isTotalWeightSameAsComputedWeight() { Float totalWeight = getTotalWeight(); Float computedWeight = getTotalComputedWeight(); return totalWeight != null && computedWeight != null - && Weights.isEqualWeight(totalWeight, computedWeight); + && Weights.isEqualWeight(totalWeight, computedWeight); } public Rtp getRtp() { @@ -612,11 +607,11 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa return useRTP; } - public void setUseRTP(boolean useRTP) { - Object oldValue = isUseRTP(); - this.useRTP = useRTP; - firePropertyChange(PROPERTY_USE_RTP, oldValue, useRTP); - } +// public void setUseRTP(boolean useRTP) { +// Object oldValue = isUseRTP(); +// this.useRTP = useRTP; +// firePropertyChange(PROPERTY_USE_RTP, oldValue, useRTP); +// } public boolean isAddIndividualObservationOnRafale() { return addIndividualObservationOnRafale; @@ -699,9 +694,9 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa return cache.getNbRowsWithWeight(); } - public boolean isAllRowsWithWeight() { - return cache.getNbRowsWithWeight() == rows.size(); - } +// public boolean isAllRowsWithWeight() { +// return cache.getNbRowsWithWeight() == rows.size(); +// } public boolean isSomeRowsWithWeightAndOtherWithout() { @@ -782,7 +777,7 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa boolean result = true; - if (rows != null) { + if (rows != null) { for (SpeciesFrequencyRowModel row : rows) { if (row.isEmpty()) { @@ -833,7 +828,7 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa lengthStep = lengthStep / 10; } - float weight = (float)(number * rtp.getA() * Math.pow(lengthStep, rtp.getB())); + float weight = (float) (number * rtp.getA() * Math.pow(lengthStep, rtp.getB())); if (weightUnit == WeightUnit.KG) { weight = weight / 1000; } @@ -905,8 +900,8 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa } public boolean isNonEmptyIndividualObservationRowsInError() { - return individualObservationRowsInError != null && - individualObservationRowsInError.stream().anyMatch(row -> !row.isEmpty()); + return individualObservationRowsInError != null + && individualObservationRowsInError.stream().anyMatch(row -> !row.isEmpty()); } public void setNonEmptyIndividualObservationRowsInError(boolean oldNonEmptyIndividualObservationInError) { @@ -927,9 +922,7 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa log.info("Revalidate all rows"); } - for (SpeciesFrequencyRowModel r : rows) { - recomputeRowValidState(r); - } + rows.forEach(this::recomputeRowValidState); } @@ -939,19 +932,17 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa log.info("Revalidate all individual observation rows"); } - for (IndividualObservationBatchRowModel r : individualObservationRows) { - recomputeIndividualObservationRowValidState(r); - } + individualObservationRows.forEach(this::recomputeIndividualObservationRowValidState); } public boolean isIndividualObservationRowValid(IndividualObservationBatchRowModel row) { return copyIndividualObservationMode == CopyIndividualObservationMode.NOTHING || copyIndividualObservationMode == CopyIndividualObservationMode.SIZE - && row.getSize() != null + && row.getSize() != null || copyIndividualObservationMode == CopyIndividualObservationMode.ALL - && row.getSize() != null - && row.getWeight() != null; + && row.getSize() != null + && row.getWeight() != null; } public void setDataSetIntervalWidth(float step) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.