1 16 package org.apache.commons.attributes.test; 17 18 import org.apache.commons.attributes.Sealable; 19 20 24 public class BeanAttribute implements Sealable { 25 26 private final int number; 27 private final String string; 28 private String name; 29 private int anotherNumber; 30 31 private boolean sealed = false; 32 33 public BeanAttribute (int number, String string) { 34 this.number = number; 35 this.string = string; 36 } 37 38 protected void checkSealed () { 39 if (sealed) { 40 throw new IllegalStateException ("Attribute has been sealed and is read-only."); 41 } 42 } 43 44 public int getNumber () { 45 return number; 46 } 47 48 public String getString () { 49 return string; 50 } 51 52 public String 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 name) { 66 checkSealed (); 67 this.name = name; 68 } 69 70 public boolean equals (Object 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 toString () { 87 return "[BeanAttribute " + number + ", " + string + "; " + name + ", " + anotherNumber + "\"]"; 88 } 89 } | Popular Tags |