state.java

### File Source: state.java

         1  /*
         2   * Copyright (c) 2003-2006, 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
               /*
        P/P     *  Method: net.sourceforge.pebble.domain.State__static_init
                *
                *  Postconditions:
                *    APPROVED == &new State(State__static_init#1)
                *    PENDING == &new State(State__static_init#3)
                *    PUBLISHED == &new State(State__static_init#5)
                *    REJECTED == &new State(State__static_init#2)
                *    UNPUBLISHED == &new State(State__static_init#4)
                *    new State(State__static_init#1) num objects == 1
                *    new State(State__static_init#2) num objects == 1
                *    new State(State__static_init#3) num objects == 1
                *    new State(State__static_init#4) num objects == 1
                *    new State(State__static_init#5) num objects == 1
                *    ...
                */
        43    public static final State APPROVED = new State("approved");
        44    public static final State REJECTED = new State("rejected");
        45    public static final State PENDING = new State("pending");
        46
        47    public static final State UNPUBLISHED = new State("unpublished");
        48    public static final State PUBLISHED = new State("published");
        49
        50    public static State getState(String name) {
                 /*
        P/P       *  Method: State getState(String)
                  *
                  *  Postconditions:
                  *    return_value in Addr_Set{null,&new State(State__static_init#1),&new State(State__static_init#2),&new State(State__static_init#3),&new State(State__static_init#4),&new State(State__static_init#5)}
                  *
                  *  Test Vectors:
                  *    name: Inverse{null}, Addr_Set{null}
                  *    java.lang.String:equals(...)@53: {0}, {1}
                  *    java.lang.String:equals(...)@55: {0}, {1}
                  *    java.lang.String:equals(...)@57: {0}, {1}
                  *    java.lang.String:equals(...)@59: {0}, {1}
                  *    java.lang.String:equals(...)@61: {0}, {1}
                  */
        51      if (name == null) {
        52        return null;
        53      } else if (name.equals("approved")) {
        54        return APPROVED;
        55      } else if (name.equals("rejected")) {
        56        return REJECTED;
        57      } else if (name.equals("pending")) {
        58        return PENDING;
        59      } else if (name.equals("unpublished")) {
        60        return UNPUBLISHED;
        61      } else if (name.equals("published")) {
        62        return PUBLISHED;
        63      } else {
        64        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     */
               /*
        P/P     *  Method: void net.sourceforge.pebble.domain.State(String)
                *
                *  Postconditions:
                *    this.name == name
                *    init'ed(this.name)
                */
        76    private State(String name) {
        77      this.name = name;
        78    }
        79
        80    /**
        81     * Gets the name of this state.
        82     *
        83     * @return    the name as a String
        84     */
        85    public String getName() {
                 /*
        P/P       *  Method: String getName()
                  *
                  *  Preconditions:
                  *    init'ed(this.name)
                  *
                  *  Postconditions:
                  *    return_value == this.name
                  *    init'ed(return_value)
                  */
        86      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() {
                 /*
        P/P       *  Method: int hashCode()
                  *
                  *  Preconditions:
                  *    this.name != null
                  *
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
        95      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) {
                 /*
        P/P       *  Method: bool equals(Object)
                  *
                  *  Preconditions:
                  *    (soft) o.name != null
                  *    (soft) init'ed(this.name)
                  *
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
       105      if (!(o instanceof State)) {
       106        return false;
       107      }
       108
       109      State state = (State)o;
       110      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() {
                 /*
        P/P       *  Method: String toString()
                  *
                  *  Preconditions:
                  *    init'ed(this.name)
                  *
                  *  Postconditions:
                  *    return_value == this.name
                  *    init'ed(return_value)
                  */
       119      return this.name;
       120    }
       121
       122  }

SofCheck Inspector Build Version : 2.22510

state.java | 2010-Jun-25 19:40:32
state.class | 2010-Jul-19 20:23:40