KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > client > models > ConfigurationModel


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
19 package cowsultants.itracker.ejb.client.models;
20
21 import java.util.Comparator JavaDoc;
22
23 public class ConfigurationModel extends GenericModel implements Comparator JavaDoc {
24     private int type;
25     private int order;
26     private String JavaDoc version;
27     private String JavaDoc configValue;
28     private String JavaDoc 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 JavaDoc value) {
42         setType(type);
43         setValue(value);
44     }
45
46     public ConfigurationModel(int type, String JavaDoc value, String JavaDoc version) {
47         this(type, value);
48         setVersion(version);
49     }
50
51     public ConfigurationModel(int type, String JavaDoc value, int order) {
52         this(type, value);
53         setOrder(order);
54     }
55
56     public ConfigurationModel(int type, String JavaDoc value, String JavaDoc 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 JavaDoc getVersion() {
78         return version;
79     }
80
81     public void setVersion(String JavaDoc value) {
82         version = value;
83     }
84
85     public String JavaDoc getValue() {
86         return (configValue == null ? "" : configValue);
87     }
88
89     public void setValue(String JavaDoc value) {
90         this.configValue = value;
91     }
92
93     public String JavaDoc getName() {
94         return (name == null ? "" : name);
95     }
96
97     public void setName(String JavaDoc value) {
98         this.name = value;
99     }
100
101     public String JavaDoc 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 JavaDoc a, Object JavaDoc b) {
106         if(! (a instanceof ConfigurationModel) || ! (b instanceof ConfigurationModel)) {
107             throw new ClassCastException JavaDoc();
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