SystemConfiguration.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. import org.apache.commons.lang.builder.CompareToBuilder;
  20. import org.apache.commons.lang.builder.ToStringBuilder;

  21. import java.util.ArrayList;
  22. import java.util.Comparator;
  23. import java.util.List;

  24. /**
  25.  *
  26.  */
  27. public class SystemConfiguration extends AbstractEntity {


  28.     public static final Comparator<SystemConfiguration> VERSION_COMPARATOR = new SystemConfigurationComparator();
  29.     /**
  30.      *
  31.      */
  32.     private static final long serialVersionUID = 1L;

  33.     private String version;

  34.     private List<CustomField> customFields = new ArrayList<CustomField>();

  35.     private List<Configuration> resolutions = new ArrayList<Configuration>();
  36.     private List<Configuration> severities = new ArrayList<Configuration>();
  37.     private List<Configuration> statuses = new ArrayList<Configuration>();

  38.     public SystemConfiguration() {
  39.     }

  40.     public String getVersion() {
  41.         return (version == null ? "" : version);
  42.     }

  43.     public void setVersion(String value) {
  44.         version = value;
  45.     }

  46.     public List<CustomField> getCustomFields() {
  47.         return customFields;
  48.     }

  49.     public void setCustomFields(List<CustomField> value) {
  50.         if (value != null) {
  51.             customFields = value;
  52.         }
  53.     }

  54.     public List<Configuration> getResolutions() {
  55.         return (resolutions == null ? new ArrayList<Configuration>()
  56.                 : resolutions);
  57.     }

  58.     public void setResolutions(List<Configuration> value) {
  59.         if (value != null) {
  60.             resolutions = value;
  61.         }
  62.     }

  63.     public List<Configuration> getSeverities() {
  64.         return (severities == null ? new ArrayList<Configuration>()
  65.                 : severities);
  66.     }

  67.     public void setSeverities(List<Configuration> value) {
  68.         if (value != null) {
  69.             severities = value;
  70.         }
  71.     }

  72.     public List<Configuration> getStatuses() {
  73.         return (statuses == null ? new ArrayList<Configuration>() : statuses);
  74.     }

  75.     public void setStatuses(List<Configuration> value) {
  76.         if (value != null) {
  77.             statuses = value;
  78.         }
  79.     }

  80.     public void addConfiguration(Configuration configuration) {
  81.         if (configuration != null) {
  82.             switch (configuration.getType()) {
  83.                 case resolution:
  84.                     resolutions.add(configuration);
  85.                     break;
  86.                 case severity:
  87.                     severities.add(configuration);
  88.                     break;
  89.                 case status:
  90.                     statuses.add(configuration);
  91.                     break;
  92.                 default:
  93.                     return;
  94.             }
  95.         }
  96.     }

  97.     public String toString() {

  98.         return new ToStringBuilder(this).append("id", getId()).append("version", getVersion()).toString();

  99.     }

  100.     private static final class SystemConfigurationComparator implements
  101.             Comparator<SystemConfiguration> {
  102.         public int compare(SystemConfiguration o1, SystemConfiguration o2) {
  103.             return new CompareToBuilder().append(o1.getVersion(),
  104.                     o2.getVersion()).append(o1.getId(), o2.getId())
  105.                     .toComparison();
  106.         }
  107.     }
  108. }