Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
13   92   1   4.33
12   35   0.23   3
3     1  
1    
 
 
  RelativeDate       Line # 42 13 1 78.6% 0.78571427
 
No Tests
 
1    /*
2    * Copyright (c) 2000-2005, University of Salford
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * Neither the name of the University of Salford nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    * POSSIBILITY OF SUCH DAMAGE.
30    */
31   
32    package issrg.pba.rbac;
33   
34    /**
35    * This class is just a holder of relative year, month, day, etc integers. It is
36    * used as
37    * a pack of integers for calculating relative validity periods.
38    *
39    * @author A.Otenko
40    */
41   
 
42    public class RelativeDate {
43   
44    public int years;
45    public int months;
46    public int days;
47    public int hours;
48    public int minutes;
49    public int seconds;
50   
51    /**
52    * This constructor builds the RelativeDate using the number of years, months
53    * days, hours, minutes and seconds from now. The direction of increment (i.e.
54    * should they be added or subtracted from now) depends on the context, e.g.
55    * they are subtracted from now to compute Age, but added to compute min and
56    * max life span.
57    */
 
58  113 toggle public RelativeDate(int years, int months, int days, int hours, int minutes, int seconds) {
59  113 this.years=years;
60  113 this.months=months;
61  113 this.days=days;
62  113 this.hours=hours;
63  113 this.minutes=minutes;
64  113 this.seconds=seconds;
65    }
66   
67    /**
68    * This method returns the date as if it were counted from 0 AD.
69    */
 
70  38 toggle public java.util.Date getDate(){
71  38 java.util.Calendar c = new java.util.GregorianCalendar();
72  38 c.set(c.ZONE_OFFSET, 0);
73  38 c.set(c.DST_OFFSET, 0);
74   
75  38 c.set(years, months, days, hours, minutes, seconds);
76  38 c.set(c.MILLISECOND, 0);
77   
78  38 return c.getTime();
79    }
80   
 
81  9256 toggle public String toString(){
82  9256 return "relative date "
83  9256 +((years>=0)?"+":"")+years
84  9256 +((months>=0)?"+":"")+months
85  9256 +((days>=0)?"+":"")+days
86  9256 +" "+((hours>=0)?"+":"")+hours
87  9256 +((minutes>=0)?"+":"")+minutes
88  9256 +((seconds>=0)?"+":"")+seconds
89    ;
90    }
91    }
92