=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Weighted.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Weighted.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Weighted.java 1970-01-01 00:00:00 +0000 @@ -1,37 +0,0 @@ -package org.hisp.dhis.common; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @author Lars Helge Overland - */ -public interface Weighted -{ - int getWeight(); -} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2015-01-17 07:41:26 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2015-07-04 17:06:08 +0000 @@ -28,15 +28,11 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonView; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import java.text.SimpleDateFormat; +import java.util.Date; + import org.hisp.dhis.common.BaseNameableObject; import org.hisp.dhis.common.DxfNamespaces; -import org.hisp.dhis.common.Weighted; import org.hisp.dhis.common.adapter.JacksonPeriodTypeDeserializer; import org.hisp.dhis.common.adapter.JacksonPeriodTypeSerializer; import org.hisp.dhis.common.view.DetailedView; @@ -44,8 +40,12 @@ import org.joda.time.DateTime; import org.joda.time.Days; -import java.text.SimpleDateFormat; -import java.util.Date; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; /** * @author Kristian Nordal @@ -53,7 +53,6 @@ @JacksonXmlRootElement( localName = "period", namespace = DxfNamespaces.DXF_2_0 ) public class Period extends BaseNameableObject - implements Weighted { /** * Determines if a de-serialized file is compatible with this class. @@ -190,12 +189,6 @@ return periodType != null ? periodType.getFrequencyOrder() : YearlyPeriodType.FREQUENCY_ORDER; } - @Override - public int getWeight() - { - return frequencyOrder() + 15; - } - /** * Returns start date formatted as string. * === removed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/collection/WeightedPaginatedList.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/collection/WeightedPaginatedList.java 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/collection/WeightedPaginatedList.java 1970-01-01 00:00:00 +0000 @@ -1,115 +0,0 @@ -package org.hisp.dhis.system.collection; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.hisp.dhis.common.Weighted; - -/** - * @author Lars Helge Overland - */ -public class WeightedPaginatedList - extends ArrayList -{ - private int pages = 0; - private int totalWeight = 0; - private int weightPageBreak = 0; - private int startIndex = 0; - - public WeightedPaginatedList( Collection collection, int pages ) - { - super( collection ); - this.pages = pages; - this.init(); - } - - private void init() - { - Iterator iterator = super.iterator(); - - while ( iterator.hasNext() ) - { - T element = iterator.next(); - - totalWeight += element != null ? element.getWeight() : 0; - } - - weightPageBreak = (int) Math.ceil( (double) totalWeight / pages ); - } - - /** - * Returns the next page in the list. Returns null if there are no more pages. - */ - public List nextPage() - { - int size = size(); - - if ( startIndex >= size ) - { - return null; - } - - int currentWeight = 0; - int currentIndex = startIndex; - - while ( currentWeight < weightPageBreak && currentIndex < size ) - { - T element = get( currentIndex++ ); - - currentWeight += element != null ? element.getWeight() : 0; - } - - List page = super.subList( startIndex, currentIndex ); - - startIndex = currentIndex; - - return page; - } - - /** - * Returns a list of all pages. - */ - public List> getPages() - { - List> pages = new ArrayList<>(); - - List page = null; - - while ( ( page = nextPage() ) != null ) - { - pages.add( page ); - } - - return pages; - } -} === removed file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/WeightedPaginatedListTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/WeightedPaginatedListTest.java 2015-06-15 13:44:20 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/WeightedPaginatedListTest.java 1970-01-01 00:00:00 +0000 @@ -1,175 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2015, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; - -import org.hisp.dhis.common.Weighted; -import org.hisp.dhis.system.collection.WeightedPaginatedList; -import org.junit.Test; - -/** - * @author Lars Helge Overland - */ -public class WeightedPaginatedListTest -{ - private Weighted one = new One(); - private Weighted two = new Two(); - private Weighted three = new Three(); - - // ------------------------------------------------------------------------- - // Tests - // ------------------------------------------------------------------------- - - @Test - public void testNextPageA() - { - WeightedPaginatedList list = new WeightedPaginatedList<>( - Arrays.asList( one, one, three, three, three, one, one, one ), 3 ); - - List page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 3, page.size() ); - assertTrue( page.contains( one ) ); - assertTrue( page.contains( three ) ); - - page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 2, page.size() ); - assertTrue( page.contains( three ) ); - - page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 3, page.size() ); - assertTrue( page.contains( one ) ); - } - - @Test - public void testNextPageB() - { - WeightedPaginatedList list = new WeightedPaginatedList<>( - Arrays.asList( one, two, three, two, three, one, one, two, three, one ), 4 ); - - List page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 3, page.size() ); - assertTrue( page.contains( one ) ); - assertTrue( page.contains( two ) ); - assertTrue( page.contains( three ) ); - - page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 2, page.size() ); - assertTrue( page.contains( two ) ); - assertTrue( page.contains( three ) ); - - page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 4, page.size() ); - assertTrue( page.contains( one ) ); - assertTrue( page.contains( two ) ); - assertTrue( page.contains( three ) ); - - page = list.nextPage(); - - assertNotNull( page ); - assertEquals( 1, page.size() ); - assertTrue( page.contains( one ) ); - } - - @Test - public void testGetPages() - { - WeightedPaginatedList list = new WeightedPaginatedList<>( - Arrays.asList( three, three, one, one, one, one, two, two ), 3 ); - - List> pages = list.getPages(); - - List page = pages.get( 0 ); - - assertNotNull( page ); - assertEquals( 2, page.size() ); - assertTrue( page.contains( three ) ); - - page = pages.get( 1 ); - - assertNotNull( page ); - assertEquals( 5, page.size() ); - assertTrue( page.contains( one ) ); - assertTrue( page.contains( two ) ); - - page = pages.get( 2 ); - - assertNotNull( page ); - assertEquals( 1, page.size() ); - assertTrue( page.contains( two ) ); - } - - // ------------------------------------------------------------------------- - // Test support classes - // ------------------------------------------------------------------------- - - class One implements Weighted - { - @Override - public int getWeight() - { - return 1; - } - } - - class Two implements Weighted - { - @Override - public int getWeight() - { - return 2; - } - } - - class Three implements Weighted - { - @Override - public int getWeight() - { - return 3; - } - } -}