KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > attributes > test > BeanAttribute


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.attributes.test;
17
18 import org.apache.commons.attributes.Sealable;
19
20 /**
21  * A sample attribute with bean-like properties. Used to test the
22  * named parameter syntax.
23  */

24 public class BeanAttribute implements Sealable {
25     
26     private final int number;
27     private final String JavaDoc string;
28     private String JavaDoc name;
29     private int anotherNumber;
30     
31     private boolean sealed = false;
32     
33     public BeanAttribute (int number, String JavaDoc string) {
34         this.number = number;
35         this.string = string;
36     }
37     
38     protected void checkSealed () {
39         if (sealed) {
40             throw new IllegalStateException JavaDoc ("Attribute has been sealed and is read-only.");
41         }
42     }
43     
44     public int getNumber () {
45         return number;
46     }
47     
48     public String JavaDoc getString () {
49         return string;
50     }
51     
52     public String JavaDoc getName () {
53         return name;
54     }
55     
56     public int getAnotherNumber () {
57         return anotherNumber;
58     }
59     
60     public void setAnotherNumber (int anotherNumber) {
61         checkSealed ();
62         this.anotherNumber = anotherNumber;
63     }
64     
65     public void setName (String JavaDoc name) {
66         checkSealed ();
67         this.name = name;
68     }
69     
70     public boolean equals (Object JavaDoc o) {
71         return o instanceof BeanAttribute &&
72             ((BeanAttribute) o).string.equals (string) &&
73             ((BeanAttribute) o).anotherNumber == anotherNumber &&
74             ((BeanAttribute) o).number == number &&
75             ((BeanAttribute) o).name.equals (name);
76     }
77     
78     public int hashCode () {
79         return string.hashCode ();
80     }
81     
82     public void seal () {
83         sealed = true;
84     }
85     
86     public String JavaDoc toString () {
87         return "[BeanAttribute " + number + ", " + string + "; " + name + ", " + anotherNumber + "\"]";
88     }
89 }
Popular Tags