Coverage Report - org.openpermis.policy.predicate.TimeConstant
 
Classes in this File Line Coverage Branch Coverage Complexity
TimeConstant
71%
15/21
50%
5/10
2.125
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.policy.predicate;
 11  
 
 12  
 import java.util.Map;
 13  
 
 14  
 import org.joda.time.DateTime;
 15  
 
 16  
 import org.openpermis.basic.PartialTime;
 17  
 import org.openpermis.policy.TimeStamp;
 18  
 
 19  
 
 20  
 /**
 21  
  * A time constant represents a time.
 22  
  * @since 0.1.0
 23  
  */
 24  5
 public class TimeConstant implements Value<DateTime> {
 25  
 
 26  
         //---- Static
 27  
         
 28  
         //---- State
 29  
         
 30  
         private PartialTime value;
 31  
         
 32  
         //---- Constructors
 33  
         
 34  
         /**
 35  
          * @since 0.1.0
 36  
          */
 37  109
         public TimeConstant (PartialTime value) {
 38  109
                 if (value == null) {
 39  0
                         throw new IllegalArgumentException("Value is null.");
 40  
                 }
 41  109
                 this.value = value;
 42  109
         }
 43  
         
 44  
         //---- Value
 45  
         
 46  
         /**
 47  
          * @since 0.1.0
 48  
          */
 49  
         public DateTime valueOf (TimeStamp timeStamp, Map<String, ?> arguments) {
 50  5
                 return this.value.toDateTime(timeStamp);
 51  
         }
 52  
         
 53  
         /**
 54  
          * @since 0.3.0
 55  
          */
 56  
         public boolean isMatchable (Map<String, Class<?>> arguments) {
 57  1
                 return true;
 58  
         }
 59  
         
 60  
         /**
 61  
          * @since 0.1.0
 62  
          */
 63  
         public Class<?> getType () {
 64  248
                 return DateTime.class;
 65  
         }
 66  
         
 67  
         /**
 68  
          * @since 0.3.0
 69  
          */
 70  
         public PartialTime getValue () {
 71  0
                 return this.value;
 72  
         }
 73  
         
 74  
         //---- Object
 75  
         
 76  
         /**
 77  
          * @since 0.1.0
 78  
          */
 79  
         public final boolean equals (Object obj) {
 80  16
                 if (obj == null) {
 81  0
                         return false;
 82  
                 }
 83  16
                 if (obj == this) {
 84  0
                         return true;
 85  
                 }
 86  16
                 if (obj instanceof TimeConstant) {
 87  16
                         final TimeConstant other = (TimeConstant) obj;
 88  16
                         if (this.value.equals(other.value)) {
 89  16
                                 return true;
 90  
                         }
 91  
                 }
 92  0
                 return false;
 93  
         }
 94  
 
 95  
         /**
 96  
          * @since 0.1.0
 97  
          */
 98  
         public int hashCode () {
 99  0
                 return this.value.hashCode();
 100  
         }
 101  
         
 102  
         /**
 103  
          * @since 0.1.0
 104  
          */
 105  
         public String toString () {
 106  8
                 return this.value.toString(); 
 107  
         }
 108  
 
 109  
 }