Coverage Report - org.simpleframework.xml.core.Revision
 
Classes in this File Line Coverage Branch Coverage Complexity
Revision
80%
8/10
25%
1/4
1.5
 
 1  
 /*
 2  
  * Revision.java July 2008
 3  
  *
 4  
  * Copyright (C) 2008, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.core;
 20  
 
 21  
 /**
 22  
  * The <code>Revision</code> object is used represent the revision
 23  
  * of a class as read from a version attribute. It determines the
 24  
  * type of deserialization that takes place. 
 25  
  * 
 26  
  * @author Niall Gallagher
 27  
  */
 28  
 class Revision {
 29  
   
 30  
    /**
 31  
     * This is used to track the revision comparision of the class.
 32  
     */
 33  
    private boolean equal;
 34  
    
 35  
    /**
 36  
     * Constructor of the <code>Revision</code> object. This is used
 37  
     * to create a comparator object that will compare and cache the
 38  
     * comparison of the expected and current version of the class.
 39  
     */
 40  935502
    public Revision() {
 41  935502
       this.equal = true;
 42  935502
    }
 43  
    
 44  
    /**
 45  
     * This is used to acquire the default revision. The default
 46  
     * revision is the revision expected if there is not attribute
 47  
     * representing the version in the XML element for the object.
 48  
     * 
 49  
     * @return this returns the default version for the object
 50  
     */
 51  
    public double getDefault() {
 52  6
       return 1.0;
 53  
    }
 54  
 
 55  
    /**
 56  
     * This is used to compare the expected and current versions of
 57  
     * the class. Once compared the comparison result is cached
 58  
     * within the revision class so that it can be used repeatedly.
 59  
     * 
 60  
     * @param expected this is the expected version of the class
 61  
     * @param current this is the current version of the class
 62  
     * 
 63  
     * @return this returns true if the versions are the same
 64  
     */
 65  
    public boolean compare(Object expected, Object current) {
 66  13
       if(current != null) {
 67  13
          equal = current.equals(expected);
 68  0
       } else if(expected != null) {
 69  0
          equal = expected.equals(1.0);
 70  
       }
 71  13
       return equal;
 72  
    }
 73  
    
 74  
    /**
 75  
     * This returns the cached comparision of the revisions. This
 76  
     * will be true if not comparison was performed. If however one
 77  
     * was performed then this will represent the result.
 78  
     * 
 79  
     * @return this returns the cached version of the comparison
 80  
     */
 81  
    public boolean isEqual() {
 82  29
       return equal;
 83  
    }
 84  
 }