Coverage Report - net.admin4j.entity.ExceptionInfoBase
 
Classes in this File Line Coverage Branch Coverage Complexity
ExceptionInfoBase
91%
34/37
75%
9/12
1.389
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.entity;
 15  
 
 16  
 import java.util.Date;
 17  
 import java.util.concurrent.atomic.AtomicLong;
 18  
 
 19  
 import net.admin4j.deps.commons.lang3.ArrayUtils;
 20  
 import net.admin4j.deps.commons.lang3.builder.ToStringBuilder;
 21  
 
 22  
 /**
 23  
  * Base information about an Exception
 24  
  * @author D. Ashmore
 25  
  * @since 1.0
 26  
  */
 27  198
 public class ExceptionInfoBase {
 28  
 
 29  
         private String exceptionClassName;
 30  
         private String lastOccurrenceMessage;
 31  
         protected StackTraceElement[] stackTrace;
 32  
         private String troubleTicketUrl;
 33  198
     protected AtomicLong totalNbrExceptions = new AtomicLong(0);
 34  198
     protected AtomicLong firstOccuranceDt = new AtomicLong(0);
 35  198
     protected AtomicLong lastOccuranceDt = new AtomicLong(0);
 36  
 
 37  
         public String getLastOccurrenceMessage() {
 38  45
                 return lastOccurrenceMessage;
 39  
         }
 40  
 
 41  
         public void setLastOccurrenceMessage(String message) {
 42  153
                 this.lastOccurrenceMessage = message;
 43  153
         }
 44  
 
 45  
         public StackTraceElement[] getStackTrace() {
 46  129
                 return stackTrace;
 47  
         }
 48  
 
 49  
         public void setStackTrace(StackTraceElement[] stackTrace) {
 50  3
                 this.stackTrace = stackTrace;
 51  3
         }
 52  
 
 53  
         @Override
 54  
         public boolean equals(Object obj) {
 55  123
                 if ( !(obj instanceof ExceptionInfoBase) ) {
 56  0
                         return false;
 57  
                 }
 58  0
                 return this.exceptionClassName.equals(((ExceptionInfoBase)obj).exceptionClassName) 
 59  
                         && ArrayUtils.isEquals(this.stackTrace, ((ExceptionInfoBase)obj).stackTrace);
 60  
         }
 61  
 
 62  
         @Override
 63  
         public int hashCode() {
 64  30206
             if (this.stackTrace.length >= 1) {
 65  30206
                 return stackTrace[0].hashCode();
 66  
             }
 67  
             else {
 68  0
                 return "EmptyStack".hashCode();
 69  
             }
 70  
         }
 71  
 
 72  
         @SuppressWarnings("rawtypes")
 73  
     public void setExceptionClass(Class exceptionClass) {
 74  21
             if (exceptionClass != null) {
 75  18
                 this.setExceptionClassName(exceptionClass.getName());
 76  
             }
 77  3
             else this.setExceptionClassName(null);
 78  21
         }
 79  
 
 80  
     public String getTroubleTicketUrl() {
 81  45
         return troubleTicketUrl;
 82  
     }
 83  
 
 84  
     public void setTroubleTicketUrl(String troubleTicketUrl) {
 85  39
         this.troubleTicketUrl = troubleTicketUrl;
 86  39
     }
 87  
     
 88  
     /* (non-Javadoc)
 89  
      * @see java.lang.Object#toString()
 90  
      */
 91  
     @Override
 92  
     public String toString() {
 93  
         return ToStringBuilder.reflectionToString(this);
 94  
     }
 95  
 
 96  
     public long getTotalNbrExceptions() {
 97  48
         return totalNbrExceptions.get();
 98  
     }
 99  
 
 100  
     public void setTotalNbrExceptions(long totalNbrOccurances) {
 101  111
         this.totalNbrExceptions.set(totalNbrOccurances);
 102  111
     }
 103  
 
 104  
     public Date getFirstOccuranceDt() {
 105  48
         return new Date(firstOccuranceDt.get());
 106  
     }
 107  
 
 108  
     public void setFirstOccuranceDt(Date firstOccuranceDt) {
 109  126
         this.firstOccuranceDt.set(firstOccuranceDt.getTime());
 110  126
     }
 111  
 
 112  
     public Date getLastOccuranceDt() {
 113  54
         return new Date(lastOccuranceDt.get());
 114  
     }
 115  
 
 116  
     public void setLastOccuranceDt(Date lastOccuranceDt) {
 117  162
         this.lastOccuranceDt.set(lastOccuranceDt.getTime());
 118  162
         if (this.firstOccuranceDt.get() == 0) {
 119  21
             this.firstOccuranceDt.set(lastOccuranceDt.getTime());
 120  
         }
 121  162
     }
 122  
 
 123  
     public String getExceptionClassName() {
 124  123
         return exceptionClassName;
 125  
     }
 126  
 
 127  
     public void setExceptionClassName(String exceptionClassName) {
 128  225
         this.exceptionClassName = exceptionClassName;
 129  225
     }
 130  
         
 131  
 }