Coverage report

  %line %branch
org.apache.torque.om.DateKey
53% 
74% 

 1  
 package org.apache.torque.om;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 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 implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.util.Date;
 20  
 
 21  
 /**
 22  
  * This class can be used as an ObjectKey to uniquely identify an
 23  
  * object within an application where the id is a Date.
 24  
  *
 25  
  * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
 26  
  * @version $Id: DateKey.java 239630 2005-08-24 12:25:32Z henning $
 27  
  */
 28  
 public class DateKey extends SimpleKey
 29  
 {
 30  
 
 31  
     /**
 32  
      * Creates an DateKey whose internal representation will be
 33  
      * set later, through a set method
 34  
      */
 35  
     public DateKey()
 36  0
     {
 37  0
     }
 38  
 
 39  
     /**
 40  
      * Creates a DateKey whose internal representation is a Date
 41  
      * given by the long number given by the String
 42  
      *
 43  
      * @param key the key value
 44  
      * @throws NumberFormatException if key is not valid
 45  
      */
 46  
     public DateKey(String key) throws NumberFormatException
 47  1
     {
 48  1
         this.key = new Date(Long.parseLong(key));
 49  1
     }
 50  
 
 51  
     /**
 52  
      * Creates a DateKey
 53  
      *
 54  
      * @param key the key value
 55  
      */
 56  
     public DateKey(Date key)
 57  10
     {
 58  10
         this.key = key;
 59  10
     }
 60  
 
 61  
     /**
 62  
      * Creates a DateKey that is equivalent to key.
 63  
      *
 64  
      * @param key the key value
 65  
      */
 66  
     public DateKey(DateKey key)
 67  0
     {
 68  0
         if (key != null)
 69  
         {
 70  0
             this.key = key.getValue();
 71  
         }
 72  
         else
 73  
         {
 74  0
             this.key = null;
 75  
         }
 76  0
     }
 77  
 
 78  
     /**
 79  
      * Sets the internal representation to a String
 80  
      *
 81  
      * @param key the key value
 82  
      */
 83  
     public void setValue(String key)
 84  
     {
 85  0
         this.key = new Date(Long.parseLong(key));
 86  0
     }
 87  
 
 88  
     /**
 89  
      * Sets the internal representation to the same object used by key.
 90  
      *
 91  
      * @param key the key value
 92  
      */
 93  
     public void setValue(DateKey key)
 94  
     {
 95  0
         if (key != null)
 96  
         {
 97  0
             this.key = key.getValue();
 98  
         }
 99  
         else
 100  
         {
 101  0
             this.key = null;
 102  
         }
 103  0
     }
 104  
 
 105  
     /**
 106  
      * Access the underlying Date object.
 107  
      *
 108  
      * @return a <code>Date</code> value
 109  
      */
 110  
     public Date getDate()
 111  
     {
 112  1
         return (Date) key;
 113  
     }
 114  
 
 115  
     /**
 116  
      * keyObj is equal to this DateKey if keyObj is a DateKey or String
 117  
      * that contains the same information this key contains.  Two ObjectKeys
 118  
      * that both contain null values are not considered equal.
 119  
      *
 120  
      * @param keyObj the comparison value
 121  
      * @return whether the two objects are equal
 122  
      */
 123  
     public boolean equals(Object keyObj)
 124  
     {
 125  1
         boolean isEqual = false;
 126  
 
 127  1
         if (key != null)
 128  
         {
 129  1
             if (keyObj instanceof String)
 130  
             {
 131  0
                 isEqual =  toString().equals(keyObj);
 132  
             }
 133  
             // check against a DateKey. Two keys are equal, if their
 134  
             // internal keys equivalent.
 135  1
             else if (keyObj instanceof DateKey)
 136  
             {
 137  1
                 Object obj = ((DateKey) keyObj).getValue();
 138  1
                 isEqual =  key.equals(obj);
 139  
             }
 140  
         }
 141  1
         return isEqual;
 142  
     }
 143  
 
 144  
     /**
 145  
      * get a String representation
 146  
      *
 147  
      * @return a String representation of the Date or an empty String if the
 148  
      *          Date is null
 149  
      */
 150  
     public String toString()
 151  
     {
 152  1
         Date dt = getDate();
 153  1
         return (dt == null ? "" : Long.toString(dt.getTime()));
 154  
     }
 155  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.