dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37962
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19394: Support method
------------------------------------------------------------
revno: 19394
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-06-14 15:15:06 +0200
message:
Support method
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisServiceTest.java
dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ListUtils.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ListUtilsTest.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-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-06-14 12:54:38 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-06-14 13:15:06 +0000
@@ -148,7 +148,7 @@
import org.hisp.dhis.util.Timer;
import org.springframework.beans.factory.annotation.Autowired;
-import com.google.inject.internal.Lists;
+import com.google.common.collect.Lists;
/**
* @author Lars Helge Overland
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.java 2015-06-14 12:54:38 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/DataQueryParamsTest.java 2015-06-14 13:15:06 +0000
@@ -49,7 +49,7 @@
import org.hisp.dhis.period.Period;
import org.junit.Test;
-import com.google.inject.internal.Lists;
+import com.google.common.collect.Lists;
/**
* @author Lars Helge Overland
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisServiceTest.java 2015-06-14 12:54:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisServiceTest.java 2015-06-14 13:15:06 +0000
@@ -59,11 +59,10 @@
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import com.google.inject.internal.Lists;
+import com.google.common.collect.Lists;
/**
* @author eirikmi
- * @version $Id: MinMaxOutlierAnalysisServiceTest.java 883 2009-05-15 00:42:45Z daghf $
*/
public class MinMaxOutlierAnalysisServiceTest
extends DhisSpringTest
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisServiceTest.java 2015-06-14 12:54:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataanalysis/StdDevOutlierAnalysisServiceTest.java 2015-06-14 13:15:06 +0000
@@ -58,7 +58,7 @@
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import com.google.inject.internal.Lists;
+import com.google.common.collect.Lists;
/**
* @author Lars Helge Overland
=== modified file 'dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ListUtils.java'
--- dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ListUtils.java 2015-06-14 12:54:38 +0000
+++ dhis-2/dhis-support/dhis-support-commons/src/main/java/org/hisp/dhis/util/ListUtils.java 2015-06-14 13:15:06 +0000
@@ -290,4 +290,25 @@
{
return list != null ? list : new ArrayList<T>();
}
+
+ /**
+ * Moves the item at the given index to the beginning of the given list.
+ *
+ * @param list the list.
+ * @param index the index of the item in the list.
+ * @return true if the list was modified, false if not.
+ */
+ public static <T> boolean moveFirst( List<T> list, int index )
+ {
+ if ( list == null || list.isEmpty() || index <= 0 || list.size() <= index )
+ {
+ return false;
+ }
+
+ T item = list.get( index );
+ list.remove( index );
+ list.add( 0, item );
+
+ return true;
+ }
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ListUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ListUtilsTest.java 2015-05-28 14:33:21 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ListUtilsTest.java 2015-06-14 13:15:06 +0000
@@ -28,16 +28,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.hisp.dhis.util.ListUtils;
import org.junit.Test;
-import static org.junit.Assert.*;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
/**
* @author Lars Helge Overland
@@ -47,7 +50,7 @@
@Test
public void testRemoveAll()
{
- List<String> list = new ArrayList<>( Arrays.asList( "a", "b", "c", "d", "e", "f", "g", "h" ) );
+ List<String> list = Lists.newArrayList( "a", "b", "c", "d", "e", "f", "g", "h" );
Integer[] indexes = { 0, 2, 5, 7, -1, 78 };
@@ -65,11 +68,31 @@
@Test
public void testGetDuplicates()
{
- List<String> list = new ArrayList<>( Arrays.asList( "a", "b", "c", "c", "d", "e", "e", "e", "f" ) );
- Set<String> expected = new HashSet<>( Arrays.asList( "c", "e" ) );
+ List<String> list = Lists.newArrayList( "a", "b", "c", "c", "d", "e", "e", "e", "f" );
+ Set<String> expected = Sets.newHashSet( "c", "e" );
assertEquals( expected, ListUtils.getDuplicates( list ) );
list = new ArrayList<>( Arrays.asList( "a", "b", "c", "d", "e", "f", "g", "h" ) );
assertEquals( 0, ListUtils.getDuplicates( list ).size() );
}
+
+ @Test
+ public void testMoveFirst()
+ {
+ List<String> list = new ArrayList<>( Arrays.asList( "a", "b", "c", "c", "d", "e", "e", "e", "f" ) );
+
+ ListUtils.moveFirst( list, 2 );
+
+ assertEquals( "c", list.get( 0 ) );
+ assertEquals( "a", list.get( 1 ) );
+ assertEquals( "b", list.get( 2 ) );
+
+ list = new ArrayList<>( Arrays.asList( "a", "b", "c", "c", "d", "e", "e", "e", "f" ) );
+
+ ListUtils.moveFirst( list, 20 );
+
+ assertEquals( "a", list.get( 0 ) );
+ assertEquals( "b", list.get( 1 ) );
+ assertEquals( "c", list.get( 2 ) );
+ }
}