Status.java

  1. /*
  2.  * This software was designed and created by Jason Carroll.
  3.  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
  4.  * The author can be reached at jcarroll@cowsultants.com
  5.  * ITracker website: http://www.cowsultants.com
  6.  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it only under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  */

  18. package org.itracker.model;

  19. /**
  20.  * Enumeration of Project, Component or Version statuses.
  21.  *
  22.  * @author johnny
  23.  */
  24. public enum Status implements IntCodeEnum<Status> {


  25.     DELETED(-1),

  26.     ACTIVE(1),

  27.     VIEWABLE(2),

  28.     LOCKED(3);


  29.     private final Integer code;

  30.     private Status(Integer code) {
  31.         this.code = code;
  32.     }

  33.     public Integer getCode() {
  34.         return code;
  35.     }

  36.     public Status fromCode(Integer code) {
  37.         return Status.valueOf(code);
  38.     }

  39.     public static Status valueOf(Integer code) {
  40.         switch (code) {
  41.             case -1:
  42.                 return DELETED;
  43.             case 1:
  44.                 return ACTIVE;
  45.             case 2:
  46.                 return VIEWABLE;
  47.             case 3:
  48.                 return LOCKED;
  49.             default:
  50.                 throw new IllegalArgumentException(
  51.                         "Unknown enum code : " + code);
  52.         }
  53.     }

  54. }