Coverage report

  %line %branch
org.apache.commons.jelly.tags.threads.RunnableStatus
33% 
85% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.jelly.tags.threads;
 18  
 
 19  
 /**
 20  
  * Represents the status of {@link JellyThread}.
 21  
  *
 22  
  * @author <a href="mailto:jason@jhorman.org">Jason Horman</a>
 23  
  */
 24  
 
 25  
 public class RunnableStatus {
 26  
     public static final int NONE = 0;
 27  
     public static final int SUCCESS = 1;
 28  
     public static final int FAILURE = 2;
 29  
     public static final int AVOIDED = 3;
 30  
     public static final int TIMED_OUT = 4;
 31  
     public static final int KILLED = 5;
 32  
 
 33  76
     private int status = NONE;
 34  
 
 35  
     /** On a status change to FAILURE an exception can be set */
 36  76
     private Exception exception = null;
 37  
 
 38  76
     public RunnableStatus() {
 39  
 
 40  76
     }
 41  
 
 42  0
     public RunnableStatus(int status) {
 43  0
         set(status);
 44  0
     }
 45  
 
 46  
     public synchronized void set(int status) {
 47  32
         set(status, null);
 48  32
     }
 49  
 
 50  
     public synchronized void set(int status, Exception e) {
 51  
         // this check is important since I may call setStatus(BLAH) again
 52  
         // to trigger the callback
 53  34
         if (this.status != status) {
 54  34
             this.status = status;
 55  
 
 56  
             // store the exception if one was set
 57  34
             if (e != null)
 58  2
                 this.exception = e;
 59  
         }
 60  34
     }
 61  
 
 62  
     public synchronized int get() {
 63  0
         return status;
 64  
     }
 65  
 
 66  
     public synchronized boolean isSuccess() {
 67  0
         return (status == SUCCESS);
 68  
     }
 69  
 
 70  
     public synchronized boolean isFailure() {
 71  0
         return (status == FAILURE);
 72  
     }
 73  
 
 74  
     public synchronized boolean isAvoided() {
 75  0
         return (status == AVOIDED);
 76  
     }
 77  
 
 78  
     public synchronized boolean isTimedOut() {
 79  0
         return (status == TIMED_OUT);
 80  
     }
 81  
 
 82  
     public synchronized boolean isKilled() {
 83  0
         return (status == KILLED);
 84  
     }
 85  
 
 86  
     public synchronized Exception getException() {
 87  0
         return exception;
 88  
     }
 89  
 
 90  
     public synchronized boolean equals(RunnableStatus status) {
 91  0
         return status.get() == this.status;
 92  
     }
 93  
 
 94  
     public synchronized boolean equals(int status) {
 95  6
         return this.status == status;
 96  
     }
 97  
 
 98  
     /**
 99  
      * Used to get the status code from a string representation. Mainly used for
 100  
      * xml parsing.
 101  
      * @param status The status string rep.
 102  
      * @return The status enum value
 103  
      */
 104  
     public static int getStatusCode(String status) {
 105  6
         if (status.equalsIgnoreCase("SUCCESS")) {
 106  2
             return SUCCESS;
 107  4
         } else if (status.equalsIgnoreCase("FAILURE")) {
 108  2
             return FAILURE;
 109  2
         } else if (status.equalsIgnoreCase("TIMED_OUT")) {
 110  0
             return TIMED_OUT;
 111  2
         } else if (status.equalsIgnoreCase("AVOIDED")) {
 112  2
             return AVOIDED;
 113  0
         } else if (status.equalsIgnoreCase("KILLED")) {
 114  0
             return KILLED;
 115  
         } else {
 116  0
             throw new IllegalArgumentException(status + " is invalid status");
 117  
         }
 118  
     }
 119  
 
 120  
     /**
 121  
      * The reverse of getStatusCode
 122  
      */
 123  
     public static String getStatusString(int status) {
 124  0
         if (status == SUCCESS) {
 125  0
             return "SUCCESS";
 126  0
         } else if (status == FAILURE) {
 127  0
             return "FAILURE";
 128  0
         } else if (status == TIMED_OUT) {
 129  0
             return "TIMED_OUT";
 130  0
         } else if (status == AVOIDED) {
 131  0
             return "AVOIDED";
 132  0
         } else if (status == KILLED) {
 133  0
             return "KILLED";
 134  
         } else {
 135  0
             throw new IllegalArgumentException(status + " is invalid status");
 136  
         }
 137  
     }
 138  
 
 139  
     public static boolean isValidStatus(int status) {
 140  0
         if (status == SUCCESS) {
 141  0
             return true;
 142  0
         } else if (status == FAILURE) {
 143  0
             return true;
 144  0
         } else if (status == TIMED_OUT) {
 145  0
             return true;
 146  0
         } else if (status == AVOIDED) {
 147  0
             return true;
 148  0
         } else if (status == KILLED) {
 149  0
             return true;
 150  
         } else {
 151  0
             return false;
 152  
         }
 153  
     }
 154  
 
 155  
     public String toString() {
 156  0
         return getStatusString(status);
 157  
     }
 158  
 }

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