Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 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 android.hardware.photography; |
| 18 | |
| 19 | /** |
| 20 | * A simple immutable class for describing the dimensions of camera image |
| 21 | * buffers. |
| 22 | */ |
| 23 | public final class Size { |
| 24 | /** |
| 25 | * Create a new immutable Size instance |
| 26 | * |
Igor Murashkin | b519cc5 | 2013-07-02 11:23:44 -0700 | [diff] [blame] | 27 | * @param width The width to store in the Size instance |
| 28 | * @param height The height to store in the Size instance |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 29 | */ |
Igor Murashkin | d7bf177 | 2013-07-12 18:01:31 -0700 | [diff] [blame] | 30 | public Size(int width, int height) { |
Igor Murashkin | b519cc5 | 2013-07-02 11:23:44 -0700 | [diff] [blame] | 31 | mWidth = width; |
| 32 | mHeight = height; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | public final int getWidth() { |
| 36 | return mWidth; |
| 37 | } |
| 38 | |
| 39 | public final int getHeight() { |
| 40 | return mHeight; |
| 41 | } |
| 42 | |
Igor Murashkin | d7bf177 | 2013-07-12 18:01:31 -0700 | [diff] [blame] | 43 | @Override |
| 44 | public boolean equals(Object obj) { |
| 45 | if (obj == null) { |
| 46 | return false; |
| 47 | } |
| 48 | if (this == obj) { |
| 49 | return true; |
| 50 | } |
| 51 | if (obj instanceof Size) { |
| 52 | Size other = (Size) obj; |
| 53 | return mWidth == other.mWidth && mHeight == other.mHeight; |
| 54 | } |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public String toString() { |
| 60 | return mWidth + "x" + mHeight; |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int hashCode() { |
| 65 | final long INT_MASK = 0xffffffffL; |
| 66 | |
| 67 | long asLong = INT_MASK & mWidth; |
| 68 | asLong <<= 32; |
| 69 | |
| 70 | asLong |= (INT_MASK & mHeight); |
| 71 | |
| 72 | return ((Long)asLong).hashCode(); |
| 73 | } |
| 74 | |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 75 | private final int mWidth; |
| 76 | private final int mHeight; |
| 77 | }; |