1 10 package org.mmbase.util.images; 11 12 18 19 20 public class Dimension { 21 22 public static final Dimension UNDETERMINED = new Dimension(-1, -1); 23 protected int x; 24 protected int y; 25 26 protected Dimension() { 27 } 28 public Dimension(int x, int y) { 29 this.x = x; 30 this.y = y; 31 } 32 public Dimension(Dimension dim) { 33 this.x = dim.x; 34 this.y = dim.y; 35 } 36 37 public int getWidth() { 38 return x; 39 } 40 public int getHeight() { 41 return y; 42 } 43 44 public int getArea() { 45 return x * y; 46 } 47 48 public String toString() { 49 return "" + x + "x" + y; 50 } 51 public boolean equals(Object o) { 52 if (o instanceof Dimension) { 53 Dimension dim = (Dimension) o; 54 return dim.x == x && dim.y == y; 55 } else { 56 return false; 57 } 58 } 59 public int hashCode() { 60 return (x + 1) * (y + 1); 61 } 62 66 public boolean valid() { 67 return x > 0 && y > 0; 68 } 69 70 } 71 | Popular Tags |