[jboss-cvs] JBossCache/src/org/jboss/cache ...

Manik Surtani msurtani at jboss.com
Fri Sep 22 12:27:56 EDT 2006


  User: msurtani
  Date: 06/09/22 12:27:56

  Modified:    src/org/jboss/cache  Modification.java
  Log:
  - Modification types to Enums.
  - Abstracted put(List)
  
  Revision  Changes    Path
  1.6       +138 -118  JBossCache/src/org/jboss/cache/Modification.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Modification.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Modification.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- Modification.java	31 Aug 2006 21:34:54 -0000	1.5
  +++ Modification.java	22 Sep 2006 16:27:56 -0000	1.6
  @@ -7,7 +7,10 @@
   package org.jboss.cache;
   
   
  -import java.io.*;
  +import java.io.Externalizable;
  +import java.io.IOException;
  +import java.io.ObjectInput;
  +import java.io.ObjectOutput;
   import java.util.Map;
   
   
  @@ -20,249 +23,266 @@
    * applying the changes in a modification listin reverse order.
    *
    * @author <a href="mailto:bela at jboss.org">Bela Ban</a> Apr 12, 2003
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
  -public class Modification implements Externalizable {
  +public class Modification implements Externalizable
  +{
   
  -   /**
  -    * Put key/value modification.
  -    */
  -   public static final byte PUT_KEY_VALUE=1;
  -
  -   /**
  -    * Put data (Map) modification.
  -    */
  -   public static final byte PUT_DATA=2;
  +   public enum ModificationType
  +   {
  +      PUT_KEY_VALUE,
  +      PUT_DATA,
  +      PUT_DATA_ERASE,
  +      REMOVE_NODE,
  +      REMOVE_KEY_VALUE,
  +      REMOVE_DATA,
  +      MOVE,
  +      UNKNOWN
  +   }
  +
  +   private ModificationType type = ModificationType.UNKNOWN;
  +   private Fqn fqn = null;
  +   private Fqn fqn2 = null;
  +   private Object key = null;
  +   private Object value = null;
  +   private Object old_value = null;
  +   private Map data = null;
   
  -   /**
  -    * Erase existing data, put data (Map) modification.
  -    */
  -   public static final byte PUT_DATA_ERASE=3;
  -
  -   /**
  -    * Remove a node modification.
  -    */
  -   public static final byte REMOVE_NODE=4;
  -
  -   /**
  -    * Remove a key/value modification.
  -    */
  -   public static final byte REMOVE_KEY_VALUE=5;
  -
  -   /**
  -    * Clear node's Map modification.
  -    */
  -   public static final byte REMOVE_DATA=6;
  -
  -   private static final long serialVersionUID = -3074622985730129009L;
  -
  -   private byte    type=0;
  -   private Fqn     fqn=null;
  -   private Object  key=null;
  -   private Object  value=null;
  -   private Object  old_value=null;
  -   private Map     data=null;
   
      /**
       * Constructs a new modification.
       */
  -   public Modification() {
  +   public Modification()
  +   {
      }
   
      /**
       * Constructs a new modification with details.
       */
  -   public Modification(byte type, Fqn fqn, Object key, Object value) {
  -      this.type=type;
  -      this.fqn=fqn;
  -      this.key=key;
  -      this.value=value;
  +   public Modification(ModificationType type, Fqn fqn, Object key, Object value)
  +   {
  +      this.type = type;
  +      this.fqn = fqn;
  +      this.key = key;
  +      this.value = value;
      }
   
      /**
       * Constructs a new modification with key.
       */
  -   public Modification(byte type, Fqn fqn, Object key) {
  -      this.type=type;
  -      this.fqn=fqn;
  -      this.key=key;
  +   public Modification(ModificationType type, Fqn fqn, Object key)
  +   {
  +      this.type = type;
  +      this.fqn = fqn;
  +      this.key = key;
      }
   
      /**
       * Constructs a new modification with data map.
       */
  -   public Modification(byte type, Fqn fqn, Map data) {
  -      this.type=type;
  -      this.fqn=fqn;
  -      this.data=data;
  +   public Modification(ModificationType type, Fqn fqn, Map data)
  +   {
  +      this.type = type;
  +      this.fqn = fqn;
  +      this.data = data;
  +   }
  +
  +   /**
  +    * Constructs a new modification with fqn only.
  +    */
  +   public Modification(ModificationType type, Fqn fqn)
  +   {
  +      this.type = type;
  +      this.fqn = fqn;
      }
   
      /**
       * Constructs a new modification with fqn only.
       */
  -   public Modification(byte type, Fqn fqn) {
  -      this.type=type;
  -      this.fqn=fqn;
  +   public Modification(ModificationType type, Fqn fqn1, Fqn fqn2)
  +   {
  +      this.type = type;
  +      this.fqn = fqn1;
  +      this.fqn2 = fqn2;
      }
   
  +
      /**
       * Returns the type of modification.
       */
  -   public byte getType() {
  +   public ModificationType getType()
  +   {
         return type;
      }
   
      /**
       * Sets the type of modification.
       */
  -   public void setType(byte type) {
  -      this.type=type;
  +   public void setType(ModificationType type)
  +   {
  +      this.type = type;
      }
   
      /**
       * Returns the modification fqn.
       */
  -   public Fqn getFqn() {
  +   public Fqn getFqn()
  +   {
         return fqn;
      }
   
      /**
       * Sets the modification fqn.
       */
  -   public void setFqn(Fqn fqn) {
  -      this.fqn=fqn;
  +   public void setFqn(Fqn fqn)
  +   {
  +      this.fqn = fqn;
  +   }
  +
  +   public void setFqn2(Fqn fqn2)
  +   {
  +      this.fqn2 = fqn2;
  +   }
  +
  +   public Fqn getFqn2()
  +   {
  +      return fqn2;
      }
   
      /**
       * Returns the modification key.
       */
  -   public Object getKey() {
  +   public Object getKey()
  +   {
         return key;
      }
   
      /**
       * Sets the modification key.
       */
  -   public void setKey(Object key) {
  -      this.key=key;
  +   public void setKey(Object key)
  +   {
  +      this.key = key;
      }
   
      /**
       * Returns the modification value.
       */
  -   public Object getValue() {
  +   public Object getValue()
  +   {
         return value;
      }
   
      /**
       * Sets the modification value.
       */
  -   public void setValue(Object value) {
  -      this.value=value;
  +   public void setValue(Object value)
  +   {
  +      this.value = value;
      }
   
      /**
       * Returns the <i>post</i> modification old value.
       */
  -   public Object getOldValue() {
  +   public Object getOldValue()
  +   {
         return old_value;
      }
   
      /**
       * Sets the <i>post</i> modification old value.
       */
  -   public void setOldValue(Object old_value) {
  -      this.old_value=old_value;
  +   public void setOldValue(Object old_value)
  +   {
  +      this.old_value = old_value;
      }
   
      /**
       * Returns the modification Map set.
       */
  -   public Map getData() {
  +   public Map getData()
  +   {
         return data;
      }
   
      /**
       * Sets the modification Map set.
       */
  -   public void setData(Map data) {
  -      this.data=data;
  +   public void setData(Map data)
  +   {
  +      this.data = data;
      }
   
      /**
       * Writes data to an external stream.
       */
  -   public void writeExternal(ObjectOutput out) throws IOException {
  -      out.writeByte(type);
  +   public void writeExternal(ObjectOutput out) throws IOException
  +   {
  +      out.writeObject(type);
   
         out.writeBoolean(fqn != null);
  -      if(fqn != null)
  +      if (fqn != null)
  +      {
            fqn.writeExternal(out);
  +      }
   
         out.writeObject(key);
         out.writeObject(value);
         out.writeObject(old_value);
   
         out.writeBoolean(data != null);
  -      if(data != null)
  +      if (data != null)
  +      {
            out.writeObject(data);
      }
  +   }
   
      /**
       * Reads data from an external stream.
       */
  -   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  -      type=in.readByte();
  -
  -      if(in.readBoolean()) {
  -         fqn=new Fqn();
  +   public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
  +   {
  +      type = (ModificationType) in.readObject();
  +
  +      if (in.readBoolean())
  +      {
  +         fqn = new Fqn();
            fqn.readExternal(in);
         }
   
  -      key=in.readObject();
  -      value=in.readObject();
  -      old_value=in.readObject();
  -
  -      if(in.readBoolean())
  -         data=(Map)in.readObject();
  -   }
  -
  -   /**
  -    * Returns the type of modification as a string.
  -    */
  -   private String typeToString(int type) {
  -      switch(type) {
  -         case PUT_KEY_VALUE:
  -            return "PUT_KEY_VALUE";
  -         case PUT_DATA:
  -            return "PUT_DATA";
  -         case PUT_DATA_ERASE:
  -            return "PUT_DATA_ERASE";
  -         case REMOVE_NODE:
  -            return "REMOVE_NODE";
  -         case REMOVE_KEY_VALUE:
  -            return "REMOVE_KEY_VALUE";
  -         case REMOVE_DATA:
  -            return "REMOVE_DATA";         
  -         default:
  -            return "<unknown>";
  +      key = in.readObject();
  +      value = in.readObject();
  +      old_value = in.readObject();
  +
  +      if (in.readBoolean())
  +      {
  +         data = (Map) in.readObject();
         }
      }
   
      /**
       * Returns debug information about this modification.
       */
  -   public String toString() {
  -      StringBuffer sb=new StringBuffer();
  -      sb.append(typeToString(type)).append(": ").append(fqn);
  -      if(key != null)
  +   public String toString()
  +   {
  +      StringBuffer sb = new StringBuffer();
  +      sb.append(type.toString()).append(": ").append(fqn);
  +      if (key != null)
  +      {
            sb.append("\nkey=").append(key);
  -      if(value != null)
  +      }
  +      if (value != null)
  +      {
            sb.append("\nvalue=").append(value);
  -      if(old_value != null)
  +      }
  +      if (old_value != null)
  +      {
            sb.append("\nold_value=").append(old_value);
  -      if(data != null)
  +      }
  +      if (data != null)
  +      {
            sb.append("\ndata=").append(data);
  +      }
         return sb.toString();
      }
   
  
  
  



More information about the jboss-cvs-commits mailing list