src/share/classes/java/awt/geom/Area.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2014, 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
@@ -95,13 +95,13 @@
* </ul>
*
* @since 1.2
*/
public class Area implements Shape, Cloneable {
- private static Vector EmptyCurves = new Vector();
+ private static Vector<Curve> EmptyCurves = new Vector<>();
- private Vector curves;
+ private Vector<Curve> curves;
/**
* Default constructor which creates an empty area.
* @since 1.2
*/
@@ -125,12 +125,12 @@
} else {
curves = pathToCurves(s.getPathIterator(null));
}
}
- private static Vector pathToCurves(PathIterator pi) {
- Vector curves = new Vector();
+ private static Vector<Curve> pathToCurves(PathIterator pi) {
+ Vector<Curve> curves = new Vector<>();
int windingRule = pi.getWindingRule();
// coords array is big enough for holding:
// coordinates returned from currentSegment (6)
// OR
// two subdivided quadratic curves (2+4+4=10)
@@ -332,11 +332,11 @@
* Removes all of the geometry from this <code>Area</code> and
* restores it to an empty area.
* @since 1.2
*/
public void reset() {
- curves = new Vector();
+ curves = new Vector<>();
invalidateBounds();
}
/**
* Tests whether this <code>Area</code> object encloses any area.
@@ -355,13 +355,13 @@
* <code>Area</code> consists entirely of line segments;
* <code>false</code> otherwise.
* @since 1.2
*/
public boolean isPolygonal() {
- Enumeration enum_ = curves.elements();
+ Enumeration<Curve> enum_ = curves.elements();
while (enum_.hasMoreElements()) {
- if (((Curve) enum_.nextElement()).getOrder() > 1) {
+ if (enum_.nextElement().getOrder() > 1) {
return false;
}
}
return true;
}
@@ -379,12 +379,12 @@
return true;
}
if (size > 3) {
return false;
}
- Curve c1 = (Curve) curves.get(1);
- Curve c2 = (Curve) curves.get(2);
+ Curve c1 = curves.get(1);
+ Curve c2 = curves.get(2);
if (c1.getOrder() != 1 || c2.getOrder() != 1) {
return false;
}
if (c1.getXTop() != c1.getXBot() || c2.getXTop() != c2.getXBot()) {
return false;
@@ -409,14 +409,14 @@
*/
public boolean isSingular() {
if (curves.size() < 3) {
return true;
}
- Enumeration enum_ = curves.elements();
+ Enumeration<Curve> enum_ = curves.elements();
enum_.nextElement(); // First Order0 "moveto"
while (enum_.hasMoreElements()) {
- if (((Curve) enum_.nextElement()).getOrder() == 0) {
+ if (enum_.nextElement().getOrder() == 0) {
return false;
}
}
return true;
}
@@ -429,15 +429,15 @@
if (cachedBounds != null) {
return cachedBounds;
}
Rectangle2D r = new Rectangle2D.Double();
if (curves.size() > 0) {
- Curve c = (Curve) curves.get(0);
+ Curve c = curves.get(0);
// First point is always an order 0 curve (moveto)
r.setRect(c.getX0(), c.getY0(), 0, 0);
for (int i = 1; i < curves.size(); i++) {
- ((Curve) curves.get(i)).enlarge(r);
+ curves.get(i).enlarge(r);
}
}
return (cachedBounds = r);
}
@@ -505,11 +505,11 @@
return true;
}
if (other == null) {
return false;
}
- Vector c = new AreaOp.XorOp().calculate(this.curves, other.curves);
+ Vector<Curve> c = new AreaOp.XorOp().calculate(this.curves, other.curves);
return c.isEmpty();
}
/**
* Transforms the geometry of this <code>Area</code> using the specified
@@ -553,14 +553,14 @@
*/
public boolean contains(double x, double y) {
if (!getCachedBounds().contains(x, y)) {
return false;
}
- Enumeration enum_ = curves.elements();
+ Enumeration<Curve> enum_ = curves.elements();
int crossings = 0;
while (enum_.hasMoreElements()) {
- Curve c = (Curve) enum_.nextElement();
+ Curve c = enum_.nextElement();
crossings += c.crossingsFor(x, y);
}
return ((crossings & 1) == 1);
}
@@ -656,20 +656,20 @@
}
}
class AreaIterator implements PathIterator {
private AffineTransform transform;
- private Vector curves;
+ private Vector<Curve> curves;
private int index;
private Curve prevcurve;
private Curve thiscurve;
- public AreaIterator(Vector curves, AffineTransform at) {
+ public AreaIterator(Vector<Curve> curves, AffineTransform at) {
this.curves = curves;
this.transform = at;
if (curves.size() >= 1) {
- thiscurve = (Curve) curves.get(0);
+ thiscurve = curves.get(0);
}
}
public int getWindingRule() {
// REMIND: Which is better, EVEN_ODD or NON_ZERO?
@@ -687,11 +687,11 @@
prevcurve = null;
} else {
prevcurve = thiscurve;
index++;
if (index < curves.size()) {
- thiscurve = (Curve) curves.get(index);
+ thiscurve = curves.get(index);
if (thiscurve.getOrder() != 0 &&
prevcurve.getX1() == thiscurve.getX0() &&
prevcurve.getY1() == thiscurve.getY0())
{
prevcurve = null;