1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.util.Comparator ; 22 23 public class ConfigurationModel extends GenericModel implements Comparator { 24 private int type; 25 private int order; 26 private String version; 27 private String configValue; 28 private String name; 29 30 public ConfigurationModel() { 31 } 32 33 public ConfigurationModel(int type, NameValuePairModel model) { 34 setType(type); 35 if(model != null) { 36 setValue(model.getValue()); 37 setName(model.getName()); 38 } 39 } 40 41 public ConfigurationModel(int type, String value) { 42 setType(type); 43 setValue(value); 44 } 45 46 public ConfigurationModel(int type, String value, String version) { 47 this(type, value); 48 setVersion(version); 49 } 50 51 public ConfigurationModel(int type, String value, int order) { 52 this(type, value); 53 setOrder(order); 54 } 55 56 public ConfigurationModel(int type, String value, String version, int order) { 57 this(type, value, version); 58 setOrder(order); 59 } 60 61 public int getType() { 62 return type; 63 } 64 65 public void setType(int value) { 66 type = value; 67 } 68 69 public int getOrder() { 70 return order; 71 } 72 73 public void setOrder(int value) { 74 order = value; 75 } 76 77 public String getVersion() { 78 return version; 79 } 80 81 public void setVersion(String value) { 82 version = value; 83 } 84 85 public String getValue() { 86 return (configValue == null ? "" : configValue); 87 } 88 89 public void setValue(String value) { 90 this.configValue = value; 91 } 92 93 public String getName() { 94 return (name == null ? "" : name); 95 } 96 97 public void setName(String value) { 98 this.name = value; 99 } 100 101 public String toString() { 102 return "Configuration [" + this.getId() + "] Name: " + this.getName() + " Value: " + this.getValue() + " Type: " + this.getType() + " Version: " + this.getVersion(); 103 } 104 105 public int compare(Object a, Object b) { 106 if(! (a instanceof ConfigurationModel) || ! (b instanceof ConfigurationModel)) { 107 throw new ClassCastException (); 108 } 109 110 ConfigurationModel ma = (ConfigurationModel) a; 111 ConfigurationModel mb = (ConfigurationModel) b; 112 113 if(ma.getOrder() == mb.getOrder()) { 114 if(! "".equals(ma.getName()) && ! "".equals(mb.getName()) && ! ma.getName().equals(mb.getName())) { 115 return ma.getValue().compareTo(mb.getValue()); 116 } else { 117 return ma.getValue().compareTo(mb.getValue()); 118 } 119 } else if(ma.getOrder() > mb.getOrder()) { 120 return 1; 121 } else if(mb.getOrder() < mb.getOrder()) { 122 return -1; 123 } 124 125 return 0; 126 } 127 } 128 | Popular Tags |