/* * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package javafx.geometry; /** * A class representing four different radius values, one for the * top-left, top-right, bottom-right, and bottom-left corners of * some rectangle. This class does not allow for negative numbers. */ public final class Radii { /** * Empty radii. An {@code Radii} instance with all offsets equal to zero. */ public static final Radii EMPTY = new Radii(0); /** * The inset on the topLeft side */ public final double getTopLeft() { return topLeft; } private double topLeft; /** * The inset on the topRight side */ public final double getTopRight() { return topRight; } private double topRight; /** * The inset on the bottomRight side */ public final double getBottomRight() { return bottomRight; } private double bottomRight; /** * The inset on the bottomLeft side */ public final double getBottomLeft() { return bottomLeft; } private double bottomLeft; /** * The cached hash code, used to improve performance in situations where * we cache gradients, such as in the CSS routines. */ private int hash = 0; /** * Constructs a new Radii instance with four different offsets. * * @param topLeft the topLeft offset * @param topRight the topRight offset * @param bottomRight the bottomRight offset * @param bottomLeft the bottomLeft offset */ public Radii(double topLeft, double topRight, double bottomRight, double bottomLeft) { if (topLeft < 0 || topRight < 0 || bottomRight < 0 || bottomLeft < 0) { throw new IllegalArgumentException("No radius can be < 0"); } this.topLeft = topLeft; this.topRight = topRight; this.bottomRight = bottomRight; this.bottomLeft = bottomLeft; } /** * Constructs a new Radii instance with same value for all four offsets. * * @param radius the value used for topLeft, bottomRight, topRight and bottomLeft * offset */ public Radii(double radius) { if (radius < 0) { throw new IllegalArgumentException("The radius cannot be < 0"); } this.topLeft = radius; this.topRight = radius; this.bottomRight = radius; this.bottomLeft = radius; } /** * Indicates whether some other object is "equal to" this one. * * @param obj the reference object with which to compare * @return true if this object is the same as the obj argument; false otherwise */ @Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Radii) { Radii other = (Radii) obj; return topLeft == other.topLeft && topRight == other.topRight && bottomRight == other.bottomRight && bottomLeft == other.bottomLeft; } else return false; } /** * Returns a hash code value for the Radii. * @return a hash code value for the Radii. */ @Override public int hashCode() { if (hash == 0) { long bits = 17L; bits = 37L * bits + Double.doubleToLongBits(topLeft); bits = 37L * bits + Double.doubleToLongBits(topRight); bits = 37L * bits + Double.doubleToLongBits(bottomRight); bits = 37L * bits + Double.doubleToLongBits(bottomLeft); hash = (int) (bits ^ (bits >> 32)); } return hash; } /** * Returns a string representation for the Radii. * @return a string representation for the Radii. */ @Override public String toString() { return "Radii [topLeft=" + topLeft + ", topRight=" + topRight + ", bottomRight=" + bottomRight + ",bottomLeft=" + bottomLeft + "]"; } }