Coverage Report - com.jcabi.github.Status
 
Classes in this File Line Coverage Branch Coverage Complexity
Status
N/A
N/A
2
Status$State
88%
8/9
66%
4/6
2
 
 1  
 /**
 2  
  * Copyright (c) 2013-2015, jcabi.com
 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
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.github;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import javax.validation.constraints.NotNull;
 34  
 
 35  
 /**
 36  
  * Model class for adding a new Status via Status API.
 37  
  * @author Marcin Cylke (marcin.cylke+github@gmail.com)
 38  
  * @version $Id$
 39  
  * @since 0.23
 40  
  */
 41  
 @Immutable
 42  
 public interface Status {
 43  
 
 44  
     /**
 45  
      * Get state.
 46  
      * @return State as enum
 47  
      */
 48  
     @NotNull(message = "state is never NULL")
 49  
     State state();
 50  
 
 51  
     /**
 52  
      * Get URL.
 53  
      * @return URL as string.
 54  
      */
 55  
     String targetUrl();
 56  
 
 57  
     /**
 58  
      * Get description.
 59  
      * @return Description as string.
 60  
      */
 61  
     String description();
 62  
 
 63  
     /**
 64  
      * Get context.
 65  
      * @return Context as string
 66  
      */
 67  
     String context();
 68  
 
 69  
     /**
 70  
      * States of Status API.
 71  
      * @author Marcin Cylke(marcin.cylke+github@gmail.com)
 72  
      * @version $Id$
 73  
      */
 74  6
     public enum State {
 75  
         /**
 76  
          * Pending state.
 77  
          */
 78  1
         Pending,
 79  
         /**
 80  
          * Success state.
 81  
          */
 82  1
         Success,
 83  
         /**
 84  
          * Error state.
 85  
          */
 86  1
         Error,
 87  
         /**
 88  
          * Failure state.
 89  
          */
 90  1
         Failure;
 91  
 
 92  
         /**
 93  
          * Get enum value from string.
 94  
          * @param name Enum name
 95  
          * @return Matched enum name
 96  
          */
 97  
         public static State forValue(final String name) {
 98  4
             for (final State state : State.values()) {
 99  4
                 if (name != null && state.name().equalsIgnoreCase(name)) {
 100  1
                     return state;
 101  
                 }
 102  
             }
 103  0
             throw new IllegalArgumentException(
 104  
                     String.format("No enum value found for %s", name)
 105  
             );
 106  
         }
 107  
     }
 108  
 }