dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37888
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19346: Using type-safe intersection method
------------------------------------------------------------
revno: 19346
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-06-10 17:56:53 +0200
message:
Using type-safe intersection method
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-06-04 22:08:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-06-10 15:56:53 +0000
@@ -28,8 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
import static org.hisp.dhis.i18n.I18nUtils.i18n;
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
import java.awt.geom.Point2D;
import java.util.ArrayList;
@@ -43,23 +43,23 @@
import java.util.Map;
import java.util.Set;
-import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.common.IdentifiableObjectUtils;
+import org.hisp.dhis.commons.filter.Filter;
import org.hisp.dhis.configuration.ConfigurationService;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.organisationunit.comparator.OrganisationUnitLevelComparator;
import org.hisp.dhis.system.filter.OrganisationUnitPolygonCoveringCoordinateFilter;
-import org.hisp.dhis.commons.filter.Filter;
-import org.hisp.dhis.util.FilterUtils;
import org.hisp.dhis.system.util.GeoUtils;
import org.hisp.dhis.system.util.ValidationUtils;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
+import org.hisp.dhis.util.FilterUtils;
import org.hisp.dhis.version.VersionService;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
/**
* @author Torgeir Lorange Ostby
@@ -599,7 +599,6 @@
}
@Override
- @SuppressWarnings("unchecked")
public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name,
Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit )
{
@@ -607,17 +606,17 @@
boolean _limit = limit && parent == null;
- final Collection<OrganisationUnit> result = organisationUnitStore.getOrganisationUnitsByNameAndGroups( name,
- groups, _limit );
+ final Set<OrganisationUnit> result = new HashSet<>( organisationUnitStore.getOrganisationUnitsByNameAndGroups( name,
+ groups, _limit ) );
if ( parent == null )
{
return result;
}
- final Collection<OrganisationUnit> subTree = getOrganisationUnitWithChildren( parent.getId() );
+ final Set<OrganisationUnit> subTree = new HashSet<>( getOrganisationUnitWithChildren( parent.getId() ) );
- List<OrganisationUnit> intersection = new ArrayList<OrganisationUnit>( CollectionUtils.intersection( subTree,
+ List<OrganisationUnit> intersection = new ArrayList<OrganisationUnit>( Sets.intersection( subTree,
result ) );
return limit && intersection.size() > MAX_LIMIT ? intersection.subList( 0, MAX_LIMIT )
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java 2015-05-28 15:04:54 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/completeness/impl/AbstractDataSetCompletenessService.java 2015-06-10 15:56:53 +0000
@@ -33,12 +33,12 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.completeness.DataSetCompletenessResult;
@@ -59,6 +59,8 @@
import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.collect.Sets;
+
/**
* @author Lars Helge Overland
*/
@@ -155,9 +157,9 @@
for ( final OrganisationUnit unit : units )
{
- Collection<Integer> sources = hierarchy.getChildren( unit.getId() );
+ Set<Integer> sources = hierarchy.getChildren( unit.getId() );
- Collection<Integer> relevantSources = getRelevantSources( dataSet, sources, null );
+ Set<Integer> relevantSources = getRelevantSources( dataSet, sources, null );
for ( final Period period : periods )
{
@@ -192,19 +194,19 @@
{
final Period period = periodService.getPeriod( periodId );
- final Collection<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(
+ final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(
organisationUnitId );
final Collection<DataSet> dataSets = dataSetService.getAllDataSets();
- final Collection<DataSetCompletenessResult> results = new ArrayList<>();
+ final List<DataSetCompletenessResult> results = new ArrayList<>();
for ( final DataSet dataSet : dataSets )
{
- final Collection<Integer> periodsBetweenDates = getIdentifiers( Period.class,
+ final List<Integer> periodsBetweenDates = getIdentifiers( Period.class,
periodService.getPeriodsBetweenDates( dataSet.getPeriodType(), period.getStartDate(), period.getEndDate() ) );
- final Collection<Integer> relevantSources = getRelevantSources( dataSet, children, groupIds );
+ final Set<Integer> relevantSources = getRelevantSources( dataSet, children, groupIds );
final DataSetCompletenessResult result = new DataSetCompletenessResult();
@@ -236,18 +238,18 @@
final Period period = periodService.getPeriod( periodId );
- final Collection<Integer> periodsBetweenDates = getIdentifiers( Period.class, periodService.getPeriodsBetweenDates( dataSet.getPeriodType(), period.getStartDate(), period.getEndDate() ) );
+ final List<Integer> periodsBetweenDates = getIdentifiers( Period.class, periodService.getPeriodsBetweenDates( dataSet.getPeriodType(), period.getStartDate(), period.getEndDate() ) );
- final Collection<DataSetCompletenessResult> results = new ArrayList<>();
+ final List<DataSetCompletenessResult> results = new ArrayList<>();
for ( final Integer unitId : organisationUnitIds )
{
final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( unitId );
- final Collection<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(
+ final Set<Integer> children = organisationUnitService.getOrganisationUnitHierarchy().getChildren(
unit.getId() );
- final Collection<Integer> relevantSources = getRelevantSources( dataSet, children, groupIds );
+ final Set<Integer> relevantSources = getRelevantSources( dataSet, children, groupIds );
final DataSetCompletenessResult result = getDataSetCompleteness( period, periodsBetweenDates, unit, relevantSources, dataSet );
@@ -311,11 +313,10 @@
return result;
}
- @SuppressWarnings("unchecked")
- private Collection<Integer> getRelevantSources( DataSet dataSet, Collection<Integer> sources, Set<Integer> groupIds )
+ private Set<Integer> getRelevantSources( DataSet dataSet, Set<Integer> sources, Set<Integer> groupIds )
{
- Collection<Integer> dataSetSources = ConversionUtils.getIdentifiers( OrganisationUnit.class,
- new HashSet<>( dataSet.getSources() ) );
+ Set<Integer> dataSetSources = new HashSet<>( ConversionUtils.getIdentifiers( OrganisationUnit.class,
+ new HashSet<>( dataSet.getSources() ) ) );
if ( groupIds != null )
{
@@ -327,6 +328,6 @@
}
}
- return CollectionUtils.intersection( dataSetSources, sources );
+ return Sets.intersection( dataSetSources, sources );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/orgunitdistribution/impl/DefaultOrgUnitDistributionService.java 2015-06-10 15:56:53 +0000
@@ -30,13 +30,13 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
-import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.chart.ChartService;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
@@ -52,6 +52,8 @@
import org.jfree.chart.plot.PlotOrientation;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.collect.Sets;
+
/**
* @author Lars Helge Overland
*/
@@ -110,7 +112,6 @@
@Override
@Transactional
- @SuppressWarnings("unchecked")
public Grid getOrganisationUnitDistribution( OrganisationUnitGroupSet groupSet, OrganisationUnit organisationUnit, boolean organisationUnitOnly )
{
Grid grid = new ListGrid();
@@ -143,11 +144,11 @@
int totalGroup = 0;
- Collection<OrganisationUnit> subTree = organisationUnitService.getOrganisationUnitWithChildren( unit.getId() );
+ Set<OrganisationUnit> subTree = new HashSet<>( organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ) );
for ( OrganisationUnitGroup group : groups )
{
- Collection<OrganisationUnit> result = CollectionUtils.intersection( subTree, group.getMembers() );
+ Set<OrganisationUnit> result = Sets.intersection( subTree, group.getMembers() );
int count = result != null ? result.size() : 0;
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2015-06-02 10:18:48 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramService.java 2015-06-10 15:56:53 +0000
@@ -28,9 +28,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.i18n.I18nUtils.i18n;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.util.CollectionUtils;
import org.hisp.dhis.trackedentity.TrackedEntity;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
@@ -39,12 +45,7 @@
import org.hisp.dhis.validation.ValidationCriteria;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.hisp.dhis.i18n.I18nUtils.i18n;
+import com.google.common.collect.Sets;
/**
* @author Abyot Asalefew
@@ -239,7 +240,7 @@
for ( Program program : programStore.getAll() )
{
- if ( CollectionUtils.intersection( program.getUserRoles(), userRoles ).size() > 0 )
+ if ( Sets.intersection( program.getUserRoles(), userRoles ).size() > 0 )
{
programs.add( program );
}
@@ -265,7 +266,7 @@
for ( Program program : programStore.getByType( type ) )
{
- if ( CollectionUtils.intersection( program.getUserRoles(), userRoles ).size() > 0 )
+ if ( Sets.intersection( program.getUserRoles(), userRoles ).size() > 0 )
{
programs.add( program );
}
=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java 2015-06-01 20:07:22 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ConversionUtils.java 2015-06-10 15:56:53 +0000
@@ -48,11 +48,11 @@
* @param clazz the clazz of the argument objects.
* @param objects for which to get the identifiers.
*/
- public static Collection<Integer> getIdentifiers( Class<?> clazz, Collection<?> objects )
+ public static List<Integer> getIdentifiers( Class<?> clazz, Collection<?> objects )
{
try
{
- Collection<Integer> identifiers = new ArrayList<>();
+ List<Integer> identifiers = new ArrayList<>();
Method method = clazz.getMethod( "getId", new Class[0] );
@@ -77,9 +77,9 @@
* @param strings the collection of Strings.
* @return a collection of Integers.
*/
- public static Collection<Integer> getIntegerCollection( Collection<String> strings )
+ public static List<Integer> getIntegerCollection( Collection<String> strings )
{
- Collection<Integer> integers = new ArrayList<>();
+ List<Integer> integers = new ArrayList<>();
if ( strings != null )
{