[Schmitzm-commits] r1069 - in trunk: 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:05:49 CEST 2010


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

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

Modified: trunk/src/skrueger/geotools/AttributeMetadataMap.java
===================================================================
--- trunk/src/skrueger/geotools/AttributeMetadataMap.java	2010-09-28 15:03:55 UTC (rev 1068)
+++ trunk/src/skrueger/geotools/AttributeMetadataMap.java	2010-10-05 08:05:40 UTC (rev 1069)
@@ -1,10 +1,11 @@
 package skrueger.geotools;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
-import java.util.TreeSet;
 
 import org.apache.log4j.Logger;
 import org.geotools.feature.NameImpl;
@@ -142,10 +143,11 @@
 	 * @return List of {@link AMD_IMPL} objects ordered by their weight.
 	 *         (heavier => further down)
 	 */
-	public TreeSet<AMD_IMPL> sortedValues() {
-		final TreeSet<AMD_IMPL> list = new TreeSet<AMD_IMPL>();
-		list.addAll(values());
-//		Collections.sort(list);
+	public List<AMD_IMPL> sortedValues() {
+		final List<AMD_IMPL> list = new ArrayList<AMD_IMPL>();
+		Collection<AMD_IMPL> values = values();
+		list.addAll(values);
+		Collections.sort(list);
 		return list;
 	}
 

Added: trunk/src_junit/skrueger/geotools/AttributeMetadataMapTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/AttributeMetadataMapTest.java	2010-09-28 15:03:55 UTC (rev 1068)
+++ trunk/src_junit/skrueger/geotools/AttributeMetadataMapTest.java	2010-10-05 08:05:40 UTC (rev 1069)
@@ -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: trunk/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