Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 105   Methods: 8
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DefaultDataVersion.java 87.5% 93.8% 100% 93.8%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache.optimistic;
 8   
 9    /**
 10    * The default implementation of a DataVersion, uses a <code>long</code> to
 11    * compare versions.
 12    * This class is immutable.
 13    * <p/>
 14    * Also note that this is meant to control implicit, internal versioning. Do not attempt to instantiate or use instances
 15    * of this class explicitly, via the {@link org.jboss.cache.config.Option#setDataVersion(DataVersion)} API, as it WILL
 16    * break things.
 17    *
 18    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 19    */
 20    public class DefaultDataVersion implements DataVersion
 21    {
 22    private static final long serialVersionUID = -6896315742831861046L;
 23    /**
 24    * Version zero.
 25    * Assign this as the first version to your data.
 26    */
 27    public static final DataVersion ZERO = new DefaultDataVersion(0L);
 28   
 29    /**
 30    * Version one.
 31    */
 32    private static final DataVersion ONE = new DefaultDataVersion(1L);
 33   
 34    /**
 35    * Version two.
 36    */
 37    private static final DataVersion TWO = new DefaultDataVersion(2L);
 38   
 39    private long version;
 40   
 41    /**
 42    * Constructs with version 0.
 43    */
 44  11 public DefaultDataVersion()
 45    {
 46    }
 47   
 48    /**
 49    * Constructs with a version number.
 50    */
 51  526 public DefaultDataVersion(long version)
 52    {
 53  526 this.version = version;
 54    }
 55   
 56    /**
 57    * Returns a new DataVersion with a newer version number.
 58    */
 59  1238 public DataVersion increment()
 60    {
 61  1238 if (this == ZERO)
 62    {
 63  879 return ONE;
 64    }
 65  359 if (this == ONE)
 66    {
 67  186 return TWO;
 68    }
 69  173 return new DefaultDataVersion(version + 1);
 70    }
 71   
 72  544 public boolean newerThan(DataVersion other)
 73    {
 74  544 if (other instanceof DefaultDataVersion)
 75    {
 76  542 DefaultDataVersion dvOther = (DefaultDataVersion) other;
 77  542 return version > dvOther.version;
 78    }
 79  2 throw new DataVersioningException("Attempting to compare a custom data version (type " + other.getClass() + ") with a DefaultDataVersion instance. Don't know how to compare!");
 80    }
 81   
 82  35 public String toString()
 83    {
 84  35 return "Ver=" + version;
 85    }
 86   
 87  12 public boolean equals(Object other)
 88    {
 89  12 if (other instanceof DefaultDataVersion)
 90    {
 91  12 return version == ((DefaultDataVersion) other).version;
 92    }
 93  0 return false;
 94    }
 95   
 96  173 public int hashCode()
 97    {
 98  173 return (int) version;
 99    }
 100   
 101  218 public long getRawVersion()
 102    {
 103  218 return version;
 104    }
 105    }