[Schmitzm-commits] r1070 - in branches/2.2.x: src/skrueger/geotools src_junit/skrueger src_junit/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 5 10:09:17 CEST 2010


Author: alfonx
Date: 2010-10-05 10:09:10 +0200 (Tue, 05 Oct 2010)
New Revision: 1070

Added:
   branches/2.2.x/src_junit/skrueger/geotools/
   branches/2.2.x/src_junit/skrueger/geotools/AttributeMetadataMapTest.java
Modified:
   branches/2.2.x/src/skrueger/geotools/AttributeMetadataMap.java
Log:
Corrected the "sortedValues" function in AttributeMetadataMap.java and added a test for it.

Modified: branches/2.2.x/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- branches/2.2.x/src/skrueger/geotools/AttributeMetadataMap.java	2010-10-05 08:05:40 UTC (rev 1069)
+++ branches/2.2.x/src/skrueger/geotools/AttributeMetadataMap.java	2010-10-05 08:09:10 UTC (rev 1070)
@@ -1,6 +1,7 @@
 package skrueger.geotools;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -143,8 +144,9 @@
 	 *         (heavier => further down)
 	 */
 	public List<AMD_IMPL> sortedValues() {
-		final ArrayList<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
-		list.addAll(values());
+		final List<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
+		final Collection<AMD_IMPL> values = values();
+		list.addAll(values);
 		Collections.sort(list);
 		return list;
 	}

Added: branches/2.2.x/src_junit/skrueger/geotools/AttributeMetadataMapTest.java
===================================================================
--- branches/2.2.x/src_junit/skrueger/geotools/AttributeMetadataMapTest.java	2010-10-05 08:05:40 UTC (rev 1069)
+++ branches/2.2.x/src_junit/skrueger/geotools/AttributeMetadataMapTest.java	2010-10-05 08:09:10 UTC (rev 1070)
@@ -0,0 +1,72 @@
+package skrueger.geotools;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.geotools.feature.NameImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import skrueger.AttributeMetadataImpl;
+
+public class AttributeMetadataMapTest {
+	
+	AttributeMetadataMap<AttributeMetadataImpl> amdMap;
+	List<String> langs; 
+	
+	@Before
+	public void before() {
+		langs = new ArrayList<String>(); 
+		langs.add("en");
+		langs.add("de");
+		
+		amdMap = new AttributeMetadataImplMap();
+		
+	}
+	
+	@After
+	public void after() {
+		amdMap.clear();
+		langs.clear();
+	}
+
+
+	@Test
+	public void testSortedValues() {
+		AttributeMetadataImpl amdG = new AttributeMetadataImpl("g", langs);
+		amdMap.put(new NameImpl("g"), amdG);
+		
+		AttributeMetadataImpl amdA = new AttributeMetadataImpl("a", langs);
+		amdMap.put(new NameImpl("a"), amdA);
+		
+		AttributeMetadataImpl amdC = new AttributeMetadataImpl("c", langs);
+		amdMap.put(new NameImpl("c"), amdC);
+
+		assertEquals(3, amdMap.values().size());
+		
+		assertEquals(3, amdMap.sortedValues().size());
+		
+		assertEquals(3, amdMap.sortedValuesVisibleOnly().size());
+		amdA.setVisible(false);
+		assertEquals(2, amdMap.sortedValuesVisibleOnly().size());
+		
+		// Now we are setting some weights and check the correct order
+		amdG.setWeight(-1);
+		amdA.setWeight(4);
+		amdC.setWeight(-4);
+		assertEquals(-4, amdMap.sortedValuesVisibleOnly().get(0).getWeight(), 0.00000001);
+		assertEquals(-1, amdMap.sortedValuesVisibleOnly().get(1).getWeight(), 0.00000001);
+
+		// Now we are setting some weights and check the correct order
+		amdG.setWeight(1);
+		amdA.setWeight(2);
+		amdC.setWeight(3);
+		assertEquals(1, amdMap.sortedValuesVisibleOnly().get(0).getWeight(), 0.00000001);
+		assertEquals(3, amdMap.sortedValuesVisibleOnly().get(1).getWeight(), 0.00000001);
+
+	}
+
+}


Property changes on: branches/2.2.x/src_junit/skrueger/geotools/AttributeMetadataMapTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list