KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > store > Option


1 /*
2  * Created on Nov 4, 2004
3  */

4 package com.openedit.store;
5
6 /**
7  * @author dbrown
8  *
9  */

10 public class Option implements Comparable JavaDoc
11 {
12     protected String JavaDoc fieldName;
13     protected String JavaDoc fieldId;
14     protected String JavaDoc fieldValue;
15     
16     protected PriceSupport fieldPriceSupport;
17     protected boolean fieldRequired = false;
18
19     public Option()
20     {
21     }
22     public Option(String JavaDoc inId, String JavaDoc inValue)
23     {
24         setId(inId);
25         setName(inId);
26         setValue(inValue);
27     }
28     public String JavaDoc getId()
29     {
30         return fieldId;
31     }
32     public void setId(String JavaDoc inId)
33     {
34         fieldId = inId;
35     }
36     public String JavaDoc getName()
37     {
38         if (fieldName == null)
39         {
40             fieldName = getId();
41         }
42         return fieldName;
43     }
44     public void setName(String JavaDoc inName)
45     {
46         fieldName = inName;
47     }
48     public PriceSupport getPriceSupport()
49     {
50         return fieldPriceSupport;
51     }
52     public void setPriceSupport(PriceSupport inPriceSupport)
53     {
54         fieldPriceSupport = inPriceSupport;
55     }
56
57     public void addTierPrice( int inQuantity, Price inPrice )
58     {
59         if (getPriceSupport() == null)
60         {
61             setPriceSupport(new PriceSupport());
62         }
63         getPriceSupport().addTierPrice( inQuantity, inPrice );
64     }
65
66     public boolean isRequired()
67     {
68         return fieldRequired;
69     }
70     public void setRequired(boolean inRequired)
71     {
72         fieldRequired = inRequired;
73     }
74
75     public String JavaDoc getValue()
76     {
77         return fieldValue;
78     }
79
80     public void setValue(String JavaDoc inValue)
81     {
82         fieldValue = inValue;
83     }
84     public String JavaDoc toString()
85     {
86         if( getValue() != null)
87         {
88             return getValue();
89         }
90         else
91         {
92             return "";
93         }
94     }
95     public boolean equals( Object JavaDoc inObj)
96     {
97         if( inObj instanceof Option)
98         {
99             Option in = (Option)inObj;
100             boolean ids = in.getId().equals(getId());
101             if( ids )
102             {
103                 if( in.getValue() == getValue() )
104                 {
105                     return true;
106                 }
107                 if( in.getValue() != null && in.getValue().equalsIgnoreCase( getValue() ) )
108                 {
109                     return true;
110                 }
111             }
112         }
113         return false;
114     }
115     public int compareTo(Object JavaDoc inO)
116     {
117         Option in = (Option)inO;
118         return in.getName().compareTo(in.getName());
119     }
120 }
121
Popular Tags