Coverage Report - net.sourceforge.pebble.domain.State
 
Classes in this File Line Coverage Branch Coverage Complexity
State
64%
18/28
42%
6/14
3.333
 
 1  
 /*
 2  
  * Copyright (c) 2003-2011, Simon Brown
 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
 9  
  *     notice, this list of conditions and the following disclaimer.
 10  
  *
 11  
  *   - Redistributions in binary form must reproduce the above copyright
 12  
  *     notice, this list of conditions and the following disclaimer in
 13  
  *     the documentation and/or other materials provided with the
 14  
  *     distribution.
 15  
  *
 16  
  *   - Neither the name of Pebble nor the names of its contributors may
 17  
  *     be used to endorse or promote products derived from this software
 18  
  *     without specific prior written permission.
 19  
  *
 20  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 21  
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22  
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23  
  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 24  
  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 25  
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 26  
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  
  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 28  
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 29  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 30  
  * POSSIBILITY OF SUCH DAMAGE.
 31  
  */
 32  
 package net.sourceforge.pebble.domain;
 33  
 
 34  
 import java.io.Serializable;
 35  
 
 36  
 /**
 37  
  * Represents a state.
 38  
  *
 39  
  * @author    Simon Brown
 40  
  */
 41  
 public class State implements Serializable {
 42  
 
 43  4
   public static final State APPROVED = new State("approved");
 44  4
   public static final State REJECTED = new State("rejected");
 45  4
   public static final State PENDING = new State("pending");
 46  
 
 47  4
   public static final State UNPUBLISHED = new State("unpublished");
 48  4
   public static final State PUBLISHED = new State("published");
 49  
 
 50  
   public static State getState(String name) {
 51  32
     if (name == null) {
 52  0
       return null;
 53  32
     } else if (name.equals("approved")) {
 54  4
       return APPROVED;
 55  28
     } else if (name.equals("rejected")) {
 56  0
       return REJECTED;
 57  28
     } else if (name.equals("pending")) {
 58  28
       return PENDING;
 59  0
     } else if (name.equals("unpublished")) {
 60  0
       return UNPUBLISHED;
 61  0
     } else if (name.equals("published")) {
 62  0
       return PUBLISHED;
 63  
     } else {
 64  0
       return null;
 65  
     }
 66  
   }
 67  
 
 68  
   /** the name of the state */
 69  
   private String name;
 70  
 
 71  
   /**
 72  
    * Creates a new instance.
 73  
    *
 74  
    * @param name    the name of the state
 75  
    */
 76  20
   private State(String name) {
 77  20
     this.name = name;
 78  20
   }
 79  
 
 80  
   /**
 81  
    * Gets the name of this state.
 82  
    *
 83  
    * @return    the name as a String
 84  
    */
 85  
   public String getName() {
 86  7588
     return name;
 87  
   }
 88  
 
 89  
   /**
 90  
    * Gets the hashcode of this object.
 91  
    *
 92  
    * @return  the hashcode as an int
 93  
    */
 94  
   public int hashCode() {
 95  0
     return name.hashCode();
 96  
   }
 97  
 
 98  
   /**
 99  
    * Determines whether the specified object is equal to this one.
 100  
    *
 101  
    * @param o   the object to compare against
 102  
    * @return    true if Object o represents the same category, false otherwise
 103  
    */
 104  
   public boolean equals(Object o) {
 105  7328
     if (!(o instanceof State)) {
 106  0
       return false;
 107  
     }
 108  
 
 109  7328
     State state = (State)o;
 110  7328
     return state.getName().equals(name);
 111  
   }
 112  
 
 113  
   /**
 114  
    * Returns a String representation of this object.
 115  
    *
 116  
    * @return  a String
 117  
    */
 118  
   public String toString() {
 119  0
     return this.name;
 120  
   }
 121  
 
 122  
 }