scg/ch14/util/AttributeValuePair

From FANG

Jump to: navigation, search

01 package scg.ch14.util;
02 
03 /**
04  * A class for holding an attribute and a value together. An
05  * AttributeValuePair compares to another by comparing only the
06  * attribute fields. Two pairs with the same attribute name are
07  * considered the same.
08  */
09 public class AttributeValuePair
10   implements Comparable<AttributeValuePair> {
11   /** the name of the attribute */
12   private final String attribute;
13 
14   /** the value of the named attribute */
15   private String value;
16 
17   /**
18    * Construct a new attribute-value pair with the given name and value.
19    *
20    @param  attribute  name of the attribute
21    @param  value      value of the attribute
22    */
23   public AttributeValuePair(String attribute, String value{
24     this.attribute = attribute;
25     this.value = value;
26   }
27 
28   /**
29    * Compare to another {@link AttributeValuePair}. Comparison is based
30    * solely on the attribute portion of each pair.
31    *
32    @param   rhs  the right-hand-side of the comparison (the this
33    *               reference is lhs).
34    *
35    @return  negative, 0, positive for comes before, equals, or comes
36    *          after rhs.
37    */
38   public int compareTo(AttributeValuePair rhs{
39     return attribute.compareTo(rhs.attribute);
40   }
41 
42   /**
43    * Get the name of the attribute in the attribute-value pair
44    *
45    @return  the attribute
46    */
47   public String getAttribute() {
48     return attribute;
49   }
50 
51   /**
52    * Get the value
53    *
54    @return  the value of the attribute
55    */
56   public String getValue() {
57     return value;
58   }
59 
60   /**
61    Set the value
62    *
63    @param  value  the value to set
64    */
65   public void setValue(String value{
66     this.value = value;
67   }
68 
69   /* (non-Javadoc)
70    @see java.lang.Object#toString()
71    */
72   @Override
73   public String toString() {
74     return attribute + "=" + value;
75   }
76 }
77 
78 //Uploaded on Mon Mar 29 21:42:33 EDT 2010


Download/View scg/ch14/util/AttributeValuePair.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter

Games
Games