| 1 | /* |
| 2 | * Copyright 2012 ZXing authors |
| 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 | |
| 17 | package com.google.zxing; |
| 18 | |
| 19 | /** |
| 20 | * Simply encapsulates a width and height. |
| 21 | */ |
| 22 | public final class Dimension { |
| 23 | |
| 24 | private final int width; |
| 25 | private final int height; |
| 26 | |
| 27 | public Dimension(int width, int height) { |
| 28 | if (width < 0 || height < 0) { |
| 29 | throw new IllegalArgumentException(); |
| 30 | } |
| 31 | this.width = width; |
| 32 | this.height = height; |
| 33 | } |
| 34 | |
| 35 | public int getWidth() { |
| 36 | return width; |
| 37 | } |
| 38 | |
| 39 | public int getHeight() { |
| 40 | return height; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public boolean equals(Object other) { |
| 45 | if (other instanceof Dimension) { |
| 46 | Dimension d = (Dimension) other; |
| 47 | return width == d.width && height == d.height; |
| 48 | } |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public int hashCode() { |
| 54 | return width * 32713 + height; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public String toString() { |
| 59 | return width + "x" + height; |
| 60 | } |
| 61 | |
| 62 | } |
| 63 | |