Search in sources :

Example 1 with FishSizeClassEnum

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.FishSizeClassEnum in project UVMS-ActivityModule-APP by UnionVMS.

the class FACatchSummaryPresentationHelper method populateTotalFishSizeMap.

@Override
public void populateTotalFishSizeMap(SummaryTableDTO summaryTableWithTotals, SummaryTableDTO summaryTable) {
    Map<FishSizeClassEnum, Object> fishSizeClassEnumMap = summaryTable.getSummaryFishSize();
    if (MapUtils.isEmpty(fishSizeClassEnumMap)) {
        return;
    }
    Map<FishSizeClassEnum, Object> totalFishSizeSpeciesMap = summaryTableWithTotals.getSummaryFishSize();
    if (MapUtils.isEmpty(totalFishSizeSpeciesMap)) {
        totalFishSizeSpeciesMap = new EnumMap<>(FishSizeClassEnum.class);
        summaryTableWithTotals.setSummaryFishSize(totalFishSizeSpeciesMap);
    }
    // Go through all the Fish classes  and calculate total for each fishclass
    for (Map.Entry<FishSizeClassEnum, Object> entry : fishSizeClassEnumMap.entrySet()) {
        // key fishSize
        FishSizeClassEnum fishSize = entry.getKey();
        Object value = entry.getValue();
        // Value will be Double if species are not present as grouping criteria Else it will be map of Species and its count
        if (value instanceof Map) {
            // check if already present
            Map<String, Map<String, Double>> fishSizeMap = (Map<String, Map<String, Double>>) totalFishSizeSpeciesMap.get(fishSize);
            fishSizeMap = populateSpeciesPresentationMapWithTotal((Map<String, Map<String, Double>>) value, fishSizeMap);
            totalFishSizeSpeciesMap.put(fishSize, fishSizeMap);
        }
    }
}
Also used : FishSizeClassEnum(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishSizeClassEnum) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FishSizeClassEnum

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.FishSizeClassEnum in project UVMS-ActivityModule-APP by UnionVMS.

the class FACatchSummaryReportHelper method populateTotalFishSizeMap.

/**
 * This method will calculate totals for FishSize section
 * @param summaryTableWithTotals Add the calculation to this final class
 * @param summaryTable           process this object to calculate totals
 */
@Override
public void populateTotalFishSizeMap(SummaryTableDTO summaryTableWithTotals, SummaryTableDTO summaryTable) {
    Map<FishSizeClassEnum, Object> fishSizeClassEnumMap = summaryTable.getSummaryFishSize();
    if (MapUtils.isEmpty(fishSizeClassEnumMap)) {
        return;
    }
    Map<FishSizeClassEnum, Object> totalFishSizeSpeciesMap = summaryTableWithTotals.getSummaryFishSize();
    if (MapUtils.isEmpty(totalFishSizeSpeciesMap)) {
        totalFishSizeSpeciesMap = new EnumMap<>(FishSizeClassEnum.class);
        summaryTableWithTotals.setSummaryFishSize(totalFishSizeSpeciesMap);
    }
    // Go through all the Fish classes  and calculate total for each fishclass
    for (Map.Entry<FishSizeClassEnum, Object> entry : fishSizeClassEnumMap.entrySet()) {
        // key fishSize
        FishSizeClassEnum fishSize = entry.getKey();
        Object value = entry.getValue();
        // Value will be Double if species are not present as grouping criteria Else it will be map of Species and its count
        if (value instanceof Map) {
            // check if already present
            Map<String, Double> totalSpeciesMap = (Map<String, Double>) totalFishSizeSpeciesMap.get(fishSize);
            totalSpeciesMap = extractSpeciesCountMap((Map<String, Double>) value, totalSpeciesMap);
            totalFishSizeSpeciesMap.put(fishSize, totalSpeciesMap);
        } else if (value instanceof Double) {
            totalFishSizeSpeciesMap.put(fishSize, calculateTotalValue((Double) value, (Double) totalFishSizeSpeciesMap.get(fishSize)));
        }
    }
}
Also used : FishSizeClassEnum(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishSizeClassEnum) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 3 with FishSizeClassEnum

use of eu.europa.ec.fisheries.uvms.activity.model.schemas.FishSizeClassEnum in project UVMS-ActivityModule-APP by UnionVMS.

the class FACatchSummaryMapper method getSummaryFishSizeList.

protected List<SummaryFishSize> getSummaryFishSizeList(Map<FishSizeClassEnum, Object> summaryFishSizeMap) {
    if (MapUtils.isEmpty(summaryFishSizeMap)) {
        return new ArrayList<>();
    }
    List<SummaryFishSize> summaryFishSizes = new ArrayList<>();
    for (Map.Entry<FishSizeClassEnum, Object> entry : summaryFishSizeMap.entrySet()) {
        SummaryFishSize summaryFishSize = new SummaryFishSize();
        summaryFishSize.setFishSize(entry.getKey());
        Object value = entry.getValue();
        if (value instanceof Map) {
            summaryFishSize.setSpecies(getSpeciesCounts((Map<String, Double>) value));
        } else if (value instanceof Double) {
            summaryFishSize.setFishSizeCount((Double) value);
        }
        summaryFishSizes.add(summaryFishSize);
    }
    log.debug("SummaryFishSize List is created");
    return summaryFishSizes;
}
Also used : FishSizeClassEnum(eu.europa.ec.fisheries.uvms.activity.model.schemas.FishSizeClassEnum) ArrayList(java.util.ArrayList) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Map(java.util.Map) SummaryFishSize(eu.europa.ec.fisheries.uvms.activity.model.schemas.SummaryFishSize)

Aggregations

FishSizeClassEnum (eu.europa.ec.fisheries.uvms.activity.model.schemas.FishSizeClassEnum)3 EnumMap (java.util.EnumMap)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 SummaryFishSize (eu.europa.ec.fisheries.uvms.activity.model.schemas.SummaryFishSize)1 ArrayList (java.util.ArrayList)1