* SPDX-FileCopyrightText: 2020, microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/
packagecom.google.android.gms.common.images;
importorg.microg.gms.common.PublicApi;
/**
* Immutable class for describing width and height dimensions in pixels.
*/
@PublicApi
publicclassSize{
privateintwidth;
privateintheight;
/**
* Create a new immutable Size instance.
*
* @param width The width of the size, in pixels
* @param height The height of the size, in pixels
*/
publicSize(intwidth,intheight){
this.width=width;
this.height=height;
}
/**
* Check if this size is equal to another size.
* <p>
* Two sizes are equal if and only if both their widths and heights are equal.
* <p>
* A size object is never equal to any other type of object.
*
* @return {@code true} if the objects were equal, {@code false} otherwise
*/
@Override
publicbooleanequals(Objecto){
if(this==o)returntrue;
if(!(oinstanceofSize))returnfalse;
Sizesize=(Size)o;
if(width!=size.width)returnfalse;
returnheight==size.height;
}
/**
* Get the height of the size (in pixels).
*
* @return height
*/
publicintgetHeight(){
returnheight;
}
/**
* Get the width of the size (in pixels).
*
* @return width
*/
publicintgetWidth(){
returnwidth;
}
@Override
publicinthashCode(){
intresult=width;
result=31*result+height;
returnresult;
}
/**
* Parses the specified string as a size value.
* <p>
* The ASCII characters {@code \}{@code u002a} ('*') and {@code \}{@code u0078} ('x') are recognized as separators between the width and height.
* <p>
* For any {@code Size s}: {@code Size.parseSize(s.toString()).equals(s)}. However, the method also handles sizes expressed in the following forms:
* <p>
* "width{@code x}height" or "width{@code *}height" => new Size(width, height), where width and height are string integers potentially containing a sign, such as "-10", "+7" or "5".
*
* @param string the string representation of a size value.
* @return the size value represented by {@code string}.
* @throws NumberFormatException if {@code string} cannot be parsed as a size value.
* @throws NullPointerException if {@code string} was null
*/
publicstaticSizeparseSize(Stringstring){
if(string==null)thrownewNullPointerException("string must not be null");