Spec-Zone .ru
спецификации, руководства, описания, API
|
001/* 002 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. Oracle designates this 008 * particular file as subject to the "Classpath" exception as provided 009 * by Oracle in the LICENSE file that accompanied this code. 010 * 011 * This code is distributed in the hope that it will be useful, but WITHOUT 012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * version 2 for more details (a copy is included in the LICENSE file that 015 * accompanied this code). 016 * 017 * You should have received a copy of the GNU General Public License version 018 * 2 along with this work; if not, write to the Free Software Foundation, 019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 020 * 021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 022 * or visit www.oracle.com if you need additional information or have any 023 * questions. 024 */ 025 026package javafx.geometry; 027 028/** 029 * A 2D dimension object that contains a width and a height. 030 * 031 * @since JavaFX 1.3 032 */ 033public class Dimension2D { 034 /** 035 * Constructs a <code>Dimension2D</code> with the specified width and 036 * height. 037 * 038 * @param width the width 039 * @param height the height 040 */ 041 public Dimension2D(double width, double height) { 042 this.width = width; 043 this.height = height; 044 } 045 046 /** 047 * The width of the dimension. 048 * 049 * @defaultValue 0.0 050 */ 051 private double width; 052 053 /** 054 * The width of the dimension. 055 * @return the width of the dimension 056 */ 057 public final double getWidth() { 058 return width; 059 } 060 061 /** 062 * The height of the dimension. 063 * 064 * @defaultValue 0.0 065 */ 066 private double height; 067 068 /** 069 * The height of the dimension. 070 * @return the height of the dimension 071 */ 072 public final double getHeight() { 073 return height; 074 } 075 076 /** 077 * Cache the hash code to make computing hashes faster. 078 */ 079 private int hash = 0; 080 081 /** 082 * Indicates whether some other object is "equal to" this one. 083 * 084 * @param obj the reference object with which to compare 085 * @return true if this Dimension2D instance is the same as the obj argument; false otherwise 086 */ 087 @Override public boolean equals(Object obj) { 088 if (obj == this) return true; 089 if (obj instanceof Dimension2D) { 090 Dimension2D other = (Dimension2D) obj; 091 return getWidth() == other.getWidth() && getHeight() == other.getHeight(); 092 } else return false; 093 } 094 095 /** 096 * Returns a hash code value for the Dimension2D object. 097 * @return a hash code value for the Dimension2D object. 098 */ 099 @Override public int hashCode() { 100 if (hash == 0) { 101 long bits = 7L; 102 bits = 31L * bits + Double.doubleToLongBits(getWidth()); 103 bits = 31L * bits + Double.doubleToLongBits(getHeight()); 104 hash = (int) (bits ^ (bits >> 32)); 105 } 106 return hash; 107 } 108 109 /** 110 * Returns a string representation of this {@code Dimension2D}. 111 * This method is intended to be used only for informational purposes. 112 * The content and format of the returned string might vary between 113 * implementations. 114 * The returned string might be empty but cannot be {@code null}. 115 */ 116 @Override public String toString() { 117 return "Dimension2D [width = " + getWidth() + ", height = " + getHeight() + "]"; 118 } 119}