Kaynağa Gözat

HADOOP-1756 Add toString() to some Writable-s.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@568856 13f79535-47bb-0310-9956-ffa450edef68
Andrzej Bialecki 18 yıl önce
ebeveyn
işleme
a4cf05f05a

+ 2 - 0
CHANGES.txt

@@ -49,6 +49,8 @@ Trunk (unreleased changes)
 
   IMPROVEMENTS
 
+    HADOOP-1756. Add toString() to some Writable-s. (ab)
+
     HADOOP-1727.  New classes: MapWritable and SortedMapWritable.
     (Jim Kellerman via ab)
 

+ 4 - 0
src/java/org/apache/hadoop/io/BooleanWritable.java

@@ -85,6 +85,10 @@ public class BooleanWritable implements WritableComparable {
     boolean b = ((BooleanWritable) o).value;
     return ((a == b) ? 0 : (a == false) ? -1 : 1);
   }
+  
+  public String toString() {
+    return Boolean.toString(get());
+  }
 
   /** 
    * A Comparator optimized for BooleanWritable. 

+ 5 - 0
src/java/org/apache/hadoop/io/GenericWritable.java

@@ -96,6 +96,11 @@ public abstract class GenericWritable implements Writable {
   public Writable get() {
     return instance;
   }
+  
+  public String toString() {
+    return "GW[" + (instance != null ? ("class=" + instance.getClass().getName() +
+        ",value=" + instance.toString()) : "(null)") + "]";
+  }
 
   public void readFields(DataInput in) throws IOException {
     type = in.readByte();

+ 4 - 0
src/java/org/apache/hadoop/io/NullWritable.java

@@ -29,6 +29,10 @@ public class NullWritable implements Writable {
 
   /** Returns the single instance of this class. */
   public static NullWritable get() { return THIS; }
+  
+  public String toString() {
+    return "(null)";
+  }
 
   public void readFields(DataInput in) throws IOException {}
   public void write(DataOutput out) throws IOException {}

+ 5 - 0
src/java/org/apache/hadoop/io/ObjectWritable.java

@@ -57,6 +57,11 @@ public class ObjectWritable implements Writable, Configurable {
     this.instance = instance;
   }
   
+  public String toString() {
+    return "OW[class=" + declaredClass + ",value=" + instance + "]";
+  }
+
+  
   public void readFields(DataInput in) throws IOException {
     readObject(in, this, this.conf);
   }

+ 17 - 1
src/java/org/apache/hadoop/mapred/Counters.java

@@ -367,6 +367,22 @@ public class Counters implements Writable {
       }
     }
   }
-
+  
+  /**
+   * Return textual representation of the counter values.
+   */
+  public String toString() {
+    StringBuilder sb = new StringBuilder("Counters: " + size());
+    Collection<String> groupNames = getGroupNames();
+    for (String groupName : groupNames) {
+      Group group = getGroup(groupName);
+      sb.append("\n\t" + group.getDisplayName());
+      for (String counterName : group.getCounterNames()) {
+        sb.append("\n\t\t" + group.getDisplayName(counterName) + "=" + 
+                 group.getCounter(counterName));
+      }
+    }
+    return sb.toString();
+  }
   
 }