Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 290   Methods: 23
NCLOC: 172   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
Modification.java 37.5% 79.7% 91.3% 75.5%
coverage coverage
 1    /*
 2    * JBoss, the OpenSource J2EE webOS
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache;
 8   
 9   
 10    import java.io.Externalizable;
 11    import java.io.IOException;
 12    import java.io.ObjectInput;
 13    import java.io.ObjectOutput;
 14    import java.util.Map;
 15   
 16   
 17    /**
 18    * Represents a modification in the cache. Contains the nature of the modification
 19    * (e.g. PUT, REMOVE), the fqn of the node, the new value and the previous value.
 20    * A list of modifications will be sent to all nodes in a cluster when a transaction
 21    * has been committed (PREPARE phase). A Modification is also used to roll back changes,
 22    * e.g. since we know the previous value, we can reconstruct the previous state by
 23    * applying the changes in a modification listin reverse order.
 24    *
 25    * @author <a href="mailto:bela@jboss.org">Bela Ban</a> Apr 12, 2003
 26    * @version $Revision: 1.7 $
 27    */
 28    public class Modification implements Externalizable
 29    {
 30   
 31    private static final long serialVersionUID = 7463314130283897197L;
 32   
 33    public enum ModificationType
 34    {
 35    PUT_KEY_VALUE,
 36    PUT_DATA,
 37    PUT_DATA_ERASE,
 38    REMOVE_NODE,
 39    REMOVE_KEY_VALUE,
 40    REMOVE_DATA,
 41    MOVE,
 42    UNKNOWN
 43    }
 44   
 45    private ModificationType type = ModificationType.UNKNOWN;
 46    private Fqn fqn = null;
 47    private Fqn fqn2 = null;
 48    private Object key = null;
 49    private Object value = null;
 50    private Object old_value = null;
 51    private Map data = null;
 52   
 53    /**
 54    * Constructs a new modification.
 55    */
 56  406 public Modification()
 57    {
 58    }
 59   
 60    /**
 61    * Constructs a new modification with details.
 62    */
 63  42526 public Modification(ModificationType type, Fqn fqn, Object key, Object value)
 64    {
 65  42526 this.type = type;
 66  42526 this.fqn = fqn;
 67  42526 this.key = key;
 68  42526 this.value = value;
 69    }
 70   
 71    /**
 72    * Constructs a new modification with key.
 73    */
 74  2051 public Modification(ModificationType type, Fqn fqn, Object key)
 75    {
 76  2051 this.type = type;
 77  2051 this.fqn = fqn;
 78  2051 this.key = key;
 79    }
 80   
 81    /**
 82    * Constructs a new modification with data map.
 83    */
 84  2733 public Modification(ModificationType type, Fqn fqn, Map data)
 85    {
 86  2733 this.type = type;
 87  2733 this.fqn = fqn;
 88  2733 this.data = data;
 89    }
 90   
 91    /**
 92    * Constructs a new modification with fqn only.
 93    */
 94  2370 public Modification(ModificationType type, Fqn fqn)
 95    {
 96  2370 this.type = type;
 97  2370 this.fqn = fqn;
 98    }
 99   
 100    /**
 101    * Constructs a new modification with fqn only.
 102    */
 103  6 public Modification(ModificationType type, Fqn fqn1, Fqn fqn2)
 104    {
 105  6 this.type = type;
 106  6 this.fqn = fqn1;
 107  6 this.fqn2 = fqn2;
 108    }
 109   
 110   
 111    /**
 112    * Returns the type of modification.
 113    */
 114  131240 public ModificationType getType()
 115    {
 116  131240 return type;
 117    }
 118   
 119    /**
 120    * Sets the type of modification.
 121    */
 122  336 public void setType(ModificationType type)
 123    {
 124  336 this.type = type;
 125    }
 126   
 127    /**
 128    * Returns the modification fqn.
 129    */
 130  10877 public Fqn getFqn()
 131    {
 132  10877 return fqn;
 133    }
 134   
 135    /**
 136    * Sets the modification fqn.
 137    */
 138  336 public void setFqn(Fqn fqn)
 139    {
 140  336 this.fqn = fqn;
 141    }
 142   
 143  0 public void setFqn2(Fqn fqn2)
 144    {
 145  0 this.fqn2 = fqn2;
 146    }
 147   
 148  6 public Fqn getFqn2()
 149    {
 150  6 return fqn2;
 151    }
 152   
 153    /**
 154    * Returns the modification key.
 155    */
 156  4910 public Object getKey()
 157    {
 158  4910 return key;
 159    }
 160   
 161    /**
 162    * Sets the modification key.
 163    */
 164  194 public void setKey(Object key)
 165    {
 166  194 this.key = key;
 167    }
 168   
 169    /**
 170    * Returns the modification value.
 171    */
 172  2798 public Object getValue()
 173    {
 174  2798 return value;
 175    }
 176   
 177    /**
 178    * Sets the modification value.
 179    */
 180  164 public void setValue(Object value)
 181    {
 182  164 this.value = value;
 183    }
 184   
 185    /**
 186    * Returns the <i>post</i> modification old value.
 187    */
 188  4265 public Object getOldValue()
 189    {
 190  4265 return old_value;
 191    }
 192   
 193    /**
 194    * Sets the <i>post</i> modification old value.
 195    */
 196  4309 public void setOldValue(Object old_value)
 197    {
 198  4309 this.old_value = old_value;
 199    }
 200   
 201    /**
 202    * Returns the modification Map set.
 203    */
 204  2917 public Map getData()
 205    {
 206  2917 return data;
 207    }
 208   
 209    /**
 210    * Sets the modification Map set.
 211    */
 212  82 public void setData(Map data)
 213    {
 214  82 this.data = data;
 215    }
 216   
 217    /**
 218    * Writes data to an external stream.
 219    */
 220  70 public void writeExternal(ObjectOutput out) throws IOException
 221    {
 222  70 out.writeObject(type);
 223   
 224  70 out.writeBoolean(fqn != null);
 225  70 if (fqn != null)
 226    {
 227  70 fqn.writeExternal(out);
 228    }
 229   
 230  70 out.writeObject(key);
 231  70 out.writeObject(value);
 232  70 out.writeObject(old_value);
 233   
 234  70 out.writeBoolean(data != null);
 235  70 if (data != null)
 236    {
 237  7 out.writeObject(data);
 238    }
 239    }
 240   
 241    /**
 242    * Reads data from an external stream.
 243    */
 244  70 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
 245    {
 246  70 type = (ModificationType) in.readObject();
 247   
 248  70 if (in.readBoolean())
 249    {
 250  70 fqn = new Fqn();
 251  70 fqn.readExternal(in);
 252    }
 253   
 254  70 key = in.readObject();
 255  70 value = in.readObject();
 256  70 old_value = in.readObject();
 257   
 258  70 if (in.readBoolean())
 259    {
 260  7 data = (Map) in.readObject();
 261    }
 262    }
 263   
 264    /**
 265    * Returns debug information about this modification.
 266    */
 267  0 public String toString()
 268    {
 269  0 StringBuffer sb = new StringBuffer();
 270  0 sb.append(type.toString()).append(": ").append(fqn);
 271  0 if (key != null)
 272    {
 273  0 sb.append("\nkey=").append(key);
 274    }
 275  0 if (value != null)
 276    {
 277  0 sb.append("\nvalue=").append(value);
 278    }
 279  0 if (old_value != null)
 280    {
 281  0 sb.append("\nold_value=").append(old_value);
 282    }
 283  0 if (data != null)
 284    {
 285  0 sb.append("\ndata=").append(data);
 286    }
 287  0 return sb.toString();
 288    }
 289   
 290    }