Browse Source

HADOOP-4823. Use SortedMap instead of NavigableMap in 0.18 due to the Java 5 requirement. (szetszwo)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.18@725540 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 16 years ago
parent
commit
2dc9f0798d

+ 3 - 0
CHANGES.txt

@@ -94,6 +94,9 @@ Release 0.18.3 - Unreleased
     HADOOP-4795. Prevent lease monitor getting into an infinite loop when
     leases and the namespace tree does not match. (szetszwo)
 
+    HADOOP-4823. Use SortedMap instead of NavigableMap in 0.18 due to the
+    Java 5 requirement.  (szetszwo)
+
 Release 0.18.2 - 2008-11-03
 
   BUG FIXES

+ 14 - 6
src/core/org/apache/hadoop/util/CyclicIteration.java

@@ -19,8 +19,8 @@ package org.apache.hadoop.util;
 
 import java.util.Iterator;
 import java.util.Map;
-import java.util.NavigableMap;
 import java.util.NoSuchElementException;
+import java.util.SortedMap;
 
 /** Provide an cyclic {@link Iterator} for a {@link NavigableMap}.
  * The {@link Iterator} navigates the entries of the map
@@ -29,22 +29,24 @@ import java.util.NoSuchElementException;
  * it will then continue from the first entry.
  */
 public class CyclicIteration<K, V> implements Iterable<Map.Entry<K, V>> {
-  private final NavigableMap<K, V> navigablemap;
-  private final NavigableMap<K, V> tailmap;
+  private final SortedMap<K, V> navigablemap;
+  private final SortedMap<K, V> tailmap;
+  private final K startingkey;
 
   /** Construct an {@link Iterable} object,
    * so that an {@link Iterator} can be created  
    * for iterating the given {@link NavigableMap}.
    * The iteration begins from the starting key exclusively.
    */
-  public CyclicIteration(NavigableMap<K, V> navigablemap, K startingkey) {
+  public CyclicIteration(SortedMap<K, V> navigablemap, K startingkey) {
+    this.startingkey = startingkey;
     if (navigablemap == null || navigablemap.isEmpty()) {
       this.navigablemap = null;
       this.tailmap = null;
     }
     else {
       this.navigablemap = navigablemap;
-      this.tailmap = navigablemap.tailMap(startingkey, false); 
+      this.tailmap = navigablemap.tailMap(startingkey);
     }
   }
 
@@ -66,7 +68,13 @@ public class CyclicIteration<K, V> implements Iterable<Map.Entry<K, V>> {
       hasnext = navigablemap != null;
       if (hasnext) {
         i = tailmap.entrySet().iterator();
-        first = nextEntry();
+        
+        Map.Entry<K, V> e = nextEntry();
+        if (e.getKey().equals(startingkey)) {
+          e = nextEntry();
+        }
+
+        first = e; 
         next = first;
       }
       else {

+ 1 - 1
src/hdfs/org/apache/hadoop/dfs/FSNamesystem.java

@@ -151,7 +151,7 @@ class FSNamesystem implements FSConstants, FSNamesystemMBean {
    * <p>
    * Mapping: StorageID -> DatanodeDescriptor
    */
-  NavigableMap<String, DatanodeDescriptor> datanodeMap = 
+  SortedMap<String, DatanodeDescriptor> datanodeMap = 
     new TreeMap<String, DatanodeDescriptor>();
 
   //

+ 1 - 1
src/test/org/apache/hadoop/dfs/AppendTestUtil.java

@@ -113,7 +113,7 @@ class AppendTestUtil {
       TestCase.assertEquals(-1, in.read()); //EOF  
       in.close();
     } catch(IOException ioe) {
-      throw new IOException("p=" + p + ", length=" + length + ", i=" + i, ioe);
+      throw (IOException)new IOException("p=" + p + ", length=" + length + ", i=" + i).initCause(ioe);
     }
   }
 }

+ 2 - 2
src/test/org/apache/hadoop/util/TestCyclicIteration.java

@@ -21,7 +21,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
-import java.util.NavigableMap;
+import java.util.SortedMap;
 import java.util.TreeMap;
 
 public class TestCyclicIteration extends junit.framework.TestCase {
@@ -33,7 +33,7 @@ public class TestCyclicIteration extends junit.framework.TestCase {
 
   private static void checkCyclicIteration(int numOfElements) {
     //create a tree map
-    final NavigableMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
+    final SortedMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
     final Integer[] integers = new Integer[numOfElements];
     for(int i = 0; i < integers.length; i++) {
       integers[i] = 2*i;