1 7 package org.jdesktop.swing.utils; 8 9 20 public final class Spatial { 21 25 private int top; 26 30 private int left; 31 34 private int width; 35 38 private int height; 39 private int cachedHash; 40 private String cachedAsString; 41 42 49 public Spatial(int top, int left, int width, int height) { 50 this.top = top; 51 this.left = left; 52 this.width = width; 53 this.height = height; 54 55 cachedHash = (top << 4) + (left << 3) + (width << 2) + (height << 1); 56 StringBuffer buffer = new StringBuffer (); 57 buffer.append("{"); 58 buffer.append(top); 59 buffer.append(","); 60 buffer.append(left); 61 buffer.append(","); 62 buffer.append(width); 63 buffer.append(","); 64 buffer.append(height); 65 buffer.append("}"); 66 cachedAsString = buffer.toString(); 67 } 68 69 73 public int getHeight() { 74 return height; 75 } 76 77 81 public int getLeft() { 82 return left; 83 } 84 85 89 public int getTop() { 90 return top; 91 } 92 93 97 public int getWidth() { 98 return width; 99 } 100 101 104 public boolean equals(Object obj) { 105 if (obj instanceof Spatial) { 106 Spatial s = (Spatial)obj; 107 return height == s.height && left == s.left && top == s.top && width == s.width; 108 } 109 return false; 110 } 111 112 115 public int hashCode() { 116 return cachedHash; 117 } 118 119 122 public String toString() { 123 return cachedAsString; 124 } 125 } 126 | Popular Tags |