dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38377
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19543: Removed unused Weighted interface
------------------------------------------------------------
revno: 19543
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2015-07-04 19:06:08 +0200
message:
Removed unused Weighted interface
removed:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Weighted.java
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/test/java/org/hisp/dhis/system/util/WeightedPaginatedListTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.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
=== 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<T extends Weighted>
- extends ArrayList<T>
-{
- private int pages = 0;
- private int totalWeight = 0;
- private int weightPageBreak = 0;
- private int startIndex = 0;
-
- public WeightedPaginatedList( Collection<T> collection, int pages )
- {
- super( collection );
- this.pages = pages;
- this.init();
- }
-
- private void init()
- {
- Iterator<T> 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<T> 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<T> page = super.subList( startIndex, currentIndex );
-
- startIndex = currentIndex;
-
- return page;
- }
-
- /**
- * Returns a list of all pages.
- */
- public List<List<T>> getPages()
- {
- List<List<T>> pages = new ArrayList<>();
-
- List<T> 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<Weighted> list = new WeightedPaginatedList<>(
- Arrays.asList( one, one, three, three, three, one, one, one ), 3 );
-
- List<Weighted> 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<Weighted> list = new WeightedPaginatedList<>(
- Arrays.asList( one, two, three, two, three, one, one, two, three, one ), 4 );
-
- List<Weighted> 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<Weighted> list = new WeightedPaginatedList<>(
- Arrays.asList( three, three, one, one, one, one, two, two ), 3 );
-
- List<List<Weighted>> pages = list.getPages();
-
- List<Weighted> 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;
- }
- }
-}