/** * Produces a ListMap based on the given list of values. The key for * each entry is produced by applying the given keyMapper function. * * @param values the values of the map. * @param keyMapper the function producing the key for each entry. * @return a ListMap. */ public static <T, V> ListMap<T, V> getListMap( List<V> values, Function<V, T> keyMapper ) { ListMap<T, V> map = new ListMap<>(); for ( V value : values ) { T key = keyMapper.apply( value ); map.putValue( key, value ); } return map; }
/** * Produces a ListMap based on the given list of values. The key for * each entry is produced by applying the given keyMapper function. The value * for each entry is produced by applying the given valueMapper function. * * @param values the values of the map. * @param keyMapper the function producing the key for each entry. * @param valueMapper the function producing the value for each entry. * @return a ListMap. */ public static <T, U, V> ListMap<T, U> getListMap( List<V> values, Function<V, T> keyMapper, Function<V, U> valueMapper ) { ListMap<T, U> map = new ListMap<>(); for ( V value : values ) { T key = keyMapper.apply( value ); U val = valueMapper.apply( value ); map.putValue( key, val ); } return map; }
public ListMap<U, V> putValue( T key1, U key2, V value ) { ListMap<U, V> listMap = this.get( key1 ); listMap = listMap == null ? new ListMap<>() : listMap; listMap.putValue( key2, value ); super.put( key1, listMap ); return null; }
/** * Creates a mapping between the period type and matching data elements for the * given list of data elements. * * @param dataElements the list of data elements. */ public static ListMap<PeriodType, DimensionalItemObject> getPeriodTypeDataElementMap( Collection<DimensionalItemObject> dataElements ) { ListMap<PeriodType, DimensionalItemObject> map = new ListMap<>(); dataElements.forEach( de -> map.putValue( ((DataElement) de).getPeriodType(), de ) ); return map; }
private static ListMap<String, DataQueryParams> getListMap( List<DataQueryParams> queries ) { ListMap<String, DataQueryParams> map = new ListMap<>(); for ( DataQueryParams query : queries ) { map.putValue( query.getSequentialQueryGroupKey(), query ); } return map; }
/** * Creates a mapping between filter dimension identifiers and filter dimensions. * Filters are guaranteed not to be null. */ public ListMap<String, DimensionalObject> getDimensionFilterMap() { ListMap<String, DimensionalObject> map = new ListMap<>(); for ( DimensionalObject filter : filters ) { if ( filter != null ) { map.putValue( filter.getDimension(), filter ); } } return map; }
/** * Creates a mapping between level and organisation unit for the given * organisation units. * * @param orgUnits list of organisation units. */ public static ListMap<Integer, DimensionalItemObject> getLevelOrgUnitMap( List<DimensionalItemObject> orgUnits ) { ListMap<Integer, DimensionalItemObject> map = new ListMap<>(); for ( DimensionalItemObject orgUnit : orgUnits ) { OrganisationUnit ou = (OrganisationUnit) orgUnit; map.putValue( ou.getLevel(), orgUnit ); } return map; }
/** * Creates a mapping between the number of days in the period interval and period * for the given periods. * * @param periods */ public static ListMap<Integer, DimensionalItemObject> getDaysPeriodMap( List<DimensionalItemObject> periods ) { ListMap<Integer, DimensionalItemObject> map = new ListMap<>(); for ( DimensionalItemObject period : periods ) { Period pe = (Period) period; map.putValue( pe.getDaysInPeriod(), pe ); } return map; }
/** * Returns an indexed map where the key is based on each distinct * combination of organisation unit level, period, and workflow. * * If multiple attributeOptionCombo values are needed for the same * combination of organisation unit level, period, and workflow, then * these are fetched at the same time time, for better performance. */ private ListMap<String, DataApproval> getIndexedListMap( List<DataApproval> dataApprovalList ) { ListMap<String, DataApproval> map = new ListMap<>(); for ( DataApproval approval : dataApprovalList ) { map.putValue( statusKey( approval ), approval ); } return map; }
/** * Creates a mapping between period type name and period for the given periods. */ public static ListMap<String, DimensionalItemObject> getPeriodTypePeriodMap( Collection<DimensionalItemObject> periods ) { ListMap<String, DimensionalItemObject> map = new ListMap<>(); for ( DimensionalItemObject period : periods ) { String periodTypeName = ((Period) period).getPeriodType().getName(); map.putValue( periodTypeName, period ); } return map; }
/** * Creates a mapping between the data periods, based on the data period type * for this query, and the aggregation periods for this query. */ public ListMap<DimensionalItemObject, DimensionalItemObject> getDataPeriodAggregationPeriodMap() { ListMap<DimensionalItemObject, DimensionalItemObject> map = new ListMap<>(); if ( dataPeriodType != null ) { for ( DimensionalItemObject aggregatePeriod : getDimensionOrFilterItems( PERIOD_DIM_ID ) ) { Period dataPeriod = dataPeriodType.createPeriod( ((Period) aggregatePeriod).getStartDate() ); map.putValue( dataPeriod, aggregatePeriod ); } } return map; }
@Override public List<Period> getDuplicatePeriods() { Collection<Period> periods = periodService.getAllPeriods(); List<Period> duplicates = new ArrayList<>(); ListMap<String, Period> map = new ListMap<>(); for ( Period period : periods ) { String key = period.getPeriodType().getName() + period.getStartDate().toString(); period.setName( period.toString() ); map.putValue( key, period ); } for ( String key : map.keySet() ) { List<Period> values = map.get( key ); if ( values != null && values.size() > 1 ) { duplicates.addAll( values ); } } return duplicates; }
/** * Creates a mapping between data type and data element for the given data * elements. * * @param dataElements list of data elements. */ public static ListMap<DataType, DimensionalItemObject> getDataTypeDataElementMap( List<DimensionalItemObject> dataElements ) { ListMap<DataType, DimensionalItemObject> map = new ListMap<>(); for ( DimensionalItemObject element : dataElements ) { DataElement dataElement = (DataElement) element; ValueType valueType = dataElement.getValueType(); // Both text and date types are recognized as DataType.TEXT DataType dataType = ( valueType.isText() || valueType.isDate() ) ? DataType.TEXT : DataType.NUMERIC; map.putValue( dataType, dataElement ); } return map; }
throws IOException ListMap<String, Option> nameOptionMap = new ListMap<>(); Map<String, OptionSet> nameOptionSetMap = new HashMap<>();
PeriodType periodType = predictor.getPeriodType(); ListMap<Period, Period> samplePeriodsMap = new ListMap<Period, Period>();
/** * Creates a mapping between the aggregation type and data element for the * given data elements and period type. * * @param params the data query parameters. */ public static ListMap<AnalyticsAggregationType, DimensionalItemObject> getAggregationTypeDataElementMap( DataQueryParams params ) { List<DimensionalItemObject> dataElements = params.getDataElements(); PeriodType aggregationPeriodType = PeriodType.getPeriodTypeByName( params.getPeriodType() ); ListMap<AnalyticsAggregationType, DimensionalItemObject> map = new ListMap<>(); for ( DimensionalItemObject element : dataElements ) { DataElement de = (DataElement) element; AnalyticsAggregationType aggregationType = ObjectUtils.firstNonNull( params.getAggregationType(), AnalyticsAggregationType.fromAggregationType( de.getAggregationType() ) ); AnalyticsAggregationType analyticsAggregationType = getAggregationType( aggregationType, de.getValueType(), aggregationPeriodType, de.getPeriodType() ); map.putValue( analyticsAggregationType, de ); } return map; }
@Override public List<Grid> getDefaultDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions, boolean selectedUnitOnly, I18nFormat format, I18n i18n ) { ListMap<CategoryCombo, DataElement> map = new ListMap<>(); for ( DataSetElement element : dataSet.getDataSetElements() ) { map.putValue( element.getResolvedCategoryCombo(), element.getDataElement() ); } DataSet tmpDataSet = new DataSet( dataSet.getName(), dataSet.getShortName(), dataSet.getPeriodType() ); tmpDataSet.setDataSetElements( dataSet.getDataSetElements() ); for ( CategoryCombo categoryCombo : map.keySet() ) { List<DataElement> dataElements = map.get( categoryCombo ); String name = categoryCombo.isDefault() ? dataSet.getName() : categoryCombo.getName(); Section section = new Section( name, dataSet, dataElements, null ); tmpDataSet.getSections().add( section ); } return getSectionDataSetReport( tmpDataSet, period, unit, dimensions, selectedUnitOnly, format, i18n ); }