diff options
author | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-12-19 17:03:15 +0000 |
---|---|---|
committer | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-12-19 17:03:15 +0000 |
commit | 6fec1adc6432eeafcdea2ab165989e170cb6e64e (patch) | |
tree | 9b478aacc6b13f1beadacec2ade096dcb732af53 /libjava/classpath/java | |
parent | abae7d71da9352babb77917224e837ffdfa118be (diff) | |
download | gcc-6fec1adc6432eeafcdea2ab165989e170cb6e64e.tar.gz |
2012-12-19 Matthias Klose <doko@ubuntu.com>
Import GNU Classpath (20121202).
* Regenerate class and header files.
* Regenerate auto* files.
* sources.am, gcj/javaprims.h: Regenerate.
* gnu/java/nio/FileLockImpl.java (close): New override.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194618 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/java')
45 files changed, 921 insertions, 345 deletions
diff --git a/libjava/classpath/java/awt/geom/Area.java b/libjava/classpath/java/awt/geom/Area.java index a1eaf63f3c3..51f914f288f 100644 --- a/libjava/classpath/java/awt/geom/Area.java +++ b/libjava/classpath/java/awt/geom/Area.java @@ -91,18 +91,18 @@ public class Area implements Shape, Cloneable * Segment vectors containing solid areas and holes * This is package-private to avoid an accessor method. */ - Vector solids; + Vector<Segment> solids; /** * Segment vectors containing solid areas and holes * This is package-private to avoid an accessor method. */ - Vector holes; + Vector<Segment> holes; /** * Vector (temporary) storing curve-curve intersections */ - private Vector cc_intersections; + private Vector<double[]> ccIntersections; /** * Winding rule WIND_NON_ZERO used, after construction, @@ -115,8 +115,8 @@ public class Area implements Shape, Cloneable */ public Area() { - solids = new Vector(); - holes = new Vector(); + solids = new Vector<Segment>(); + holes = new Vector<Segment>(); } /** @@ -135,7 +135,7 @@ public class Area implements Shape, Cloneable { this(); - Vector p = makeSegment(s); + Vector<Segment> p = makeSegment(s); // empty path if (p == null) @@ -143,7 +143,7 @@ public class Area implements Shape, Cloneable // delete empty paths for (int i = 0; i < p.size(); i++) - if (((Segment) p.elementAt(i)).getSignedArea() == 0.0) + if (p.elementAt(i).getSignedArea() == 0.0) p.remove(i--); /* @@ -157,12 +157,11 @@ public class Area implements Shape, Cloneable * 4: Repeat (3) until no segments remain in the list * 5: Remove redundant paths and sort into solids and holes */ - Vector paths = new Vector(); Segment v; for (int i = 0; i < p.size(); i++) { - Segment path = (Segment) p.elementAt(i); + Segment path = p.elementAt(i); createNodesSelf(path); } @@ -171,18 +170,18 @@ public class Area implements Shape, Cloneable for (int i = 0; i < p.size() - 1; i++) for (int j = i + 1; j < p.size(); j++) { - Segment path1 = (Segment) p.elementAt(i); - Segment path2 = (Segment) p.elementAt(j); + Segment path1 = p.elementAt(i); + Segment path2 = p.elementAt(j); createNodes(path1, path2); } } // we have intersecting points. - Vector segments = new Vector(); + Vector<Segment> segments = new Vector<Segment>(); for (int i = 0; i < p.size(); i++) { - Segment path = v = (Segment) p.elementAt(i); + Segment path = v = p.elementAt(i); do { segments.add(v); @@ -191,7 +190,7 @@ public class Area implements Shape, Cloneable while (v != path); } - paths = weilerAtherton(segments); + Vector<Segment> paths = weilerAtherton(segments); deleteRedundantPaths(paths); } @@ -208,36 +207,34 @@ public class Area implements Shape, Cloneable Area B = (Area) area.clone(); - Vector pathA = new Vector(); - Vector pathB = new Vector(); + Vector<Segment> pathA = new Vector<Segment>(); + Vector<Segment> pathB = new Vector<Segment>(); pathA.addAll(solids); pathA.addAll(holes); pathB.addAll(B.solids); pathB.addAll(B.holes); - int nNodes = 0; - for (int i = 0; i < pathA.size(); i++) { - Segment a = (Segment) pathA.elementAt(i); + Segment a = pathA.elementAt(i); for (int j = 0; j < pathB.size(); j++) { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); + Segment b = pathB.elementAt(j); + createNodes(a, b); } } - Vector paths = new Vector(); + Vector<Segment> paths = new Vector<Segment>(); Segment v; // we have intersecting points. - Vector segments = new Vector(); + Vector<Segment> segments = new Vector<Segment>(); // In a union operation, we keep all // segments of A oustide B and all B outside A for (int i = 0; i < pathA.size(); i++) { - v = (Segment) pathA.elementAt(i); + v = pathA.elementAt(i); Segment path = v; do { @@ -250,7 +247,7 @@ public class Area implements Shape, Cloneable for (int i = 0; i < pathB.size(); i++) { - v = (Segment) pathB.elementAt(i); + v = pathB.elementAt(i); Segment path = v; do { @@ -281,7 +278,7 @@ public class Area implements Shape, Cloneable return; } - Vector pathA = new Vector(); + Vector<Segment> pathA = new Vector<Segment>(); Area B = (Area) area.clone(); pathA.addAll(solids); pathA.addAll(holes); @@ -290,27 +287,23 @@ public class Area implements Shape, Cloneable setDirection(B.holes, true); setDirection(B.solids, false); - Vector pathB = new Vector(); + Vector<Segment> pathB = new Vector<Segment>(); pathB.addAll(B.solids); pathB.addAll(B.holes); - int nNodes = 0; - // create nodes for (int i = 0; i < pathA.size(); i++) { - Segment a = (Segment) pathA.elementAt(i); + Segment a = pathA.elementAt(i); for (int j = 0; j < pathB.size(); j++) { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); + Segment b = pathB.elementAt(j); + createNodes(a, b); } } - Vector paths = new Vector(); - // we have intersecting points. - Vector segments = new Vector(); + Vector<Segment> segments = new Vector<Segment>(); // In a subtraction operation, we keep all // segments of A oustide B and all B within A @@ -318,7 +311,7 @@ public class Area implements Shape, Cloneable // and the segments before and after any node for (int i = 0; i < pathA.size(); i++) { - Segment v = (Segment) pathA.elementAt(i); + Segment v = pathA.elementAt(i); Segment path = v; if (v.isSegmentOutside(area) && v.node == null) segments.add(v); @@ -357,7 +350,7 @@ public class Area implements Shape, Cloneable while (v != path); } - paths = weilerAtherton(segments); + Vector<Segment> paths = weilerAtherton(segments); deleteRedundantPaths(paths); } @@ -376,32 +369,28 @@ public class Area implements Shape, Cloneable if (equals(area)) return; - Vector pathA = new Vector(); + Vector<Segment> pathA = new Vector<Segment>(); Area B = (Area) area.clone(); pathA.addAll(solids); pathA.addAll(holes); - Vector pathB = new Vector(); + Vector<Segment> pathB = new Vector<Segment>(); pathB.addAll(B.solids); pathB.addAll(B.holes); - int nNodes = 0; - // create nodes for (int i = 0; i < pathA.size(); i++) { - Segment a = (Segment) pathA.elementAt(i); + Segment a = pathA.elementAt(i); for (int j = 0; j < pathB.size(); j++) { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); + Segment b = pathB.elementAt(j); + createNodes(a, b); } } - Vector paths = new Vector(); - // we have intersecting points. - Vector segments = new Vector(); + Vector<Segment> segments = new Vector<Segment>(); // In an intersection operation, we keep all // segments of A within B and all B within A @@ -410,7 +399,7 @@ public class Area implements Shape, Cloneable // and the segments before and after any node for (int i = 0; i < pathA.size(); i++) { - Segment v = (Segment) pathA.elementAt(i); + Segment v = pathA.elementAt(i); Segment path = v; if (! v.isSegmentOutside(area) && v.node == null) segments.add(v); @@ -430,7 +419,7 @@ public class Area implements Shape, Cloneable for (int i = 0; i < pathB.size(); i++) { - Segment v = (Segment) pathB.elementAt(i); + Segment v = pathB.elementAt(i); Segment path = v; if (! v.isSegmentOutside(this) && v.node == null) segments.add(v); @@ -449,7 +438,7 @@ public class Area implements Shape, Cloneable while (v != path); } - paths = weilerAtherton(segments); + Vector<Segment> paths = weilerAtherton(segments); deleteRedundantPaths(paths); } @@ -476,10 +465,10 @@ public class Area implements Shape, Cloneable return; } - Vector pathA = new Vector(); + Vector<Segment> pathA = new Vector<Segment>(); Area B = (Area) area.clone(); - Vector pathB = new Vector(); + Vector<Segment> pathB = new Vector<Segment>(); pathA.addAll(solids); pathA.addAll(holes); @@ -489,28 +478,25 @@ public class Area implements Shape, Cloneable pathB.addAll(B.solids); pathB.addAll(B.holes); - int nNodes = 0; - for (int i = 0; i < pathA.size(); i++) { - Segment a = (Segment) pathA.elementAt(i); + Segment a = pathA.elementAt(i); for (int j = 0; j < pathB.size(); j++) { - Segment b = (Segment) pathB.elementAt(j); - nNodes += createNodes(a, b); + Segment b = pathB.elementAt(j); + createNodes(a, b); } } - Vector paths = new Vector(); Segment v; // we have intersecting points. - Vector segments = new Vector(); + Vector<Segment> segments = new Vector<Segment>(); // In an XOR operation, we operate on all segments for (int i = 0; i < pathA.size(); i++) { - v = (Segment) pathA.elementAt(i); + v = pathA.elementAt(i); Segment path = v; do { @@ -522,7 +508,7 @@ public class Area implements Shape, Cloneable for (int i = 0; i < pathB.size(); i++) { - v = (Segment) pathB.elementAt(i); + v = pathB.elementAt(i); Segment path = v; do { @@ -532,7 +518,7 @@ public class Area implements Shape, Cloneable while (v != path); } - paths = weilerAtherton(segments); + Vector<Segment> paths = weilerAtherton(segments); deleteRedundantPaths(paths); } @@ -541,8 +527,8 @@ public class Area implements Shape, Cloneable */ public void reset() { - solids = new Vector(); - holes = new Vector(); + solids = new Vector<Segment>(); + holes = new Vector<Segment>(); } /** @@ -556,9 +542,9 @@ public class Area implements Shape, Cloneable double totalArea = 0; for (int i = 0; i < solids.size(); i++) - totalArea += Math.abs(((Segment) solids.elementAt(i)).getSignedArea()); + totalArea += Math.abs(solids.elementAt(i).getSignedArea()); for (int i = 0; i < holes.size(); i++) - totalArea -= Math.abs(((Segment) holes.elementAt(i)).getSignedArea()); + totalArea -= Math.abs(holes.elementAt(i).getSignedArea()); if (totalArea <= EPSILON) return true; @@ -572,10 +558,10 @@ public class Area implements Shape, Cloneable public boolean isPolygonal() { for (int i = 0; i < holes.size(); i++) - if (! ((Segment) holes.elementAt(i)).isPolygonal()) + if (!holes.elementAt(i).isPolygonal()) return false; for (int i = 0; i < solids.size(); i++) - if (! ((Segment) solids.elementAt(i)).isPolygonal()) + if (!solids.elementAt(i).isPolygonal()) return false; return true; } @@ -599,7 +585,7 @@ public class Area implements Shape, Cloneable if (holes.size() != 0 || solids.size() != 1) return false; - Segment path = (Segment) solids.elementAt(0); + Segment path = solids.elementAt(0); if (! path.isPolygonal()) return false; @@ -657,12 +643,12 @@ public class Area implements Shape, Cloneable double xmax; double ymin; double ymax; - xmin = xmax = ((Segment) solids.elementAt(0)).P1.getX(); - ymin = ymax = ((Segment) solids.elementAt(0)).P1.getY(); + xmin = xmax = solids.elementAt(0).P1.getX(); + ymin = ymax = solids.elementAt(0).P1.getY(); for (int path = 0; path < solids.size(); path++) { - Rectangle2D r = ((Segment) solids.elementAt(path)).getPathBounds(); + Rectangle2D r = solids.elementAt(path).getPathBounds(); xmin = Math.min(r.getMinX(), xmin); ymin = Math.min(r.getMinY(), ymin); xmax = Math.max(r.getMaxX(), xmax); @@ -696,9 +682,9 @@ public class Area implements Shape, Cloneable { Area clone = new Area(); for (int i = 0; i < solids.size(); i++) - clone.solids.add(((Segment) solids.elementAt(i)).cloneSegmentList()); + clone.solids.add(solids.elementAt(i).cloneSegmentList()); for (int i = 0; i < holes.size(); i++) - clone.holes.add(((Segment) holes.elementAt(i)).cloneSegmentList()); + clone.holes.add(holes.elementAt(i).cloneSegmentList()); return clone; } catch (CloneNotSupportedException e) @@ -727,10 +713,10 @@ public class Area implements Shape, Cloneable || holes.size() != area.holes.size()) return false; - Vector pathA = new Vector(); + Vector<Segment> pathA = new Vector<Segment>(); pathA.addAll(solids); pathA.addAll(holes); - Vector pathB = new Vector(); + Vector<Segment> pathB = new Vector<Segment>(); pathB.addAll(area.solids); pathB.addAll(area.holes); @@ -741,8 +727,8 @@ public class Area implements Shape, Cloneable { for (int j = 0; j < nPaths; j++) { - Segment p1 = (Segment) pathA.elementAt(i); - Segment p2 = (Segment) pathB.elementAt(j); + Segment p1 = pathA.elementAt(i); + Segment p2 = pathB.elementAt(j); if (! match[0][i] && ! match[1][j]) if (p1.pathEquals(p2)) match[0][i] = match[1][j] = true; @@ -763,9 +749,9 @@ public class Area implements Shape, Cloneable public void transform(AffineTransform at) { for (int i = 0; i < solids.size(); i++) - ((Segment) solids.elementAt(i)).transformSegmentList(at); + solids.elementAt(i).transformSegmentList(at); for (int i = 0; i < holes.size(); i++) - ((Segment) holes.elementAt(i)).transformSegmentList(at); + holes.elementAt(i).transformSegmentList(at); // Note that the orientation is not invariant under inversion if ((at.getType() & AffineTransform.TYPE_FLIP) != 0) @@ -800,11 +786,11 @@ public class Area implements Shape, Cloneable { int n = 0; for (int i = 0; i < solids.size(); i++) - if (((Segment) solids.elementAt(i)).contains(x, y)) + if (solids.elementAt(i).contains(x, y)) n++; for (int i = 0; i < holes.size(); i++) - if (((Segment) holes.elementAt(i)).contains(x, y)) + if (holes.elementAt(i).contains(x, y)) n--; return (n != 0); @@ -854,7 +840,7 @@ public class Area implements Shape, Cloneable { Segment v; Segment start; - start = v = (Segment) solids.elementAt(path); + start = v = solids.elementAt(path); do { if (l[i].hasIntersections(v)) @@ -867,7 +853,7 @@ public class Area implements Shape, Cloneable { Segment v; Segment start; - start = v = (Segment) holes.elementAt(path); + start = v = holes.elementAt(path); do { if (l[i].hasIntersections(v)) @@ -886,7 +872,7 @@ public class Area implements Shape, Cloneable // but encloses a hole? Rectangle2D r = new Rectangle2D.Double(x, y, w, h); for (int path = 0; path < holes.size(); path++) - if (! ((Segment) holes.elementAt(path)).isSegmentOutside(r)) + if (! holes.elementAt(path).isSegmentOutside(r)) return false; return true; @@ -938,7 +924,7 @@ public class Area implements Shape, Cloneable { Segment v; Segment start; - start = v = (Segment) solids.elementAt(path); + start = v = solids.elementAt(path); do { if (l[i].hasIntersections(v)) @@ -951,7 +937,7 @@ public class Area implements Shape, Cloneable { Segment v; Segment start; - start = v = (Segment) holes.elementAt(path); + start = v = holes.elementAt(path); do { if (l[i].hasIntersections(v)) @@ -967,7 +953,7 @@ public class Area implements Shape, Cloneable return true; // What if the rectangle encloses the whole shape? - Point2D p = ((Segment) solids.elementAt(0)).getMidPoint(); + Point2D p = solids.elementAt(0).getMidPoint(); if ((new Rectangle2D.Double(x, y, w, h)).contains(p)) return true; return false; @@ -1020,7 +1006,7 @@ public class Area implements Shape, Cloneable */ private class AreaIterator implements PathIterator { - private Vector segments; + private Vector<IteratorSegment> segments; private int index; private AffineTransform at; @@ -1045,14 +1031,14 @@ public class Area implements Shape, Cloneable { this.at = at; index = 0; - segments = new Vector(); - Vector allpaths = new Vector(); + segments = new Vector<IteratorSegment>(); + Vector<Segment> allpaths = new Vector<Segment>(); allpaths.addAll(solids); allpaths.addAll(holes); for (int i = 0; i < allpaths.size(); i++) { - Segment v = (Segment) allpaths.elementAt(i); + Segment v = allpaths.elementAt(i); Segment start = v; IteratorSegment is = new IteratorSegment(); @@ -1078,7 +1064,7 @@ public class Area implements Shape, Cloneable public int currentSegment(double[] coords) { - IteratorSegment s = (IteratorSegment) segments.elementAt(index); + IteratorSegment s = segments.elementAt(index); if (at != null) at.transform(s.coords, 0, coords, 0, 3); else @@ -1089,7 +1075,7 @@ public class Area implements Shape, Cloneable public int currentSegment(float[] coords) { - IteratorSegment s = (IteratorSegment) segments.elementAt(index); + IteratorSegment s = segments.elementAt(index); double[] d = new double[6]; if (at != null) { @@ -1129,13 +1115,13 @@ public class Area implements Shape, Cloneable * * Returns a Vector of the resulting paths. */ - private Vector weilerAtherton(Vector segments) + private Vector<Segment> weilerAtherton(Vector<Segment> segments) { - Vector paths = new Vector(); + Vector<Segment> paths = new Vector<Segment>(); while (segments.size() > 0) { // Iterate over the path - Segment start = (Segment) segments.elementAt(0); + Segment start = segments.elementAt(0); Segment s = start; do { @@ -1252,7 +1238,7 @@ public class Area implements Shape, Cloneable double[] temp = new double[2]; temp[0] = t1 + s * w1; temp[1] = t2 + t * w1; - cc_intersections.add(temp); + ccIntersections.add(temp); return; } @@ -1328,28 +1314,28 @@ public class Area implements Shape, Cloneable if (! r1.intersects(r2)) return null; - cc_intersections = new Vector(); + ccIntersections = new Vector<double[]>(); recursiveSubdivide(curve1.getCubicCurve2D(), curve2.getCubicCurve2D(), getRecursionDepth(curve1), getRecursionDepth(curve2), 0.0, 0.0, 1.0, 1.0); - if (cc_intersections.size() == 0) + if (ccIntersections.size() == 0) return null; - Intersection[] results = new Intersection[cc_intersections.size()]; - for (int i = 0; i < cc_intersections.size(); i++) + Intersection[] results = new Intersection[ccIntersections.size()]; + for (int i = 0; i < ccIntersections.size(); i++) { - double[] temp = (double[]) cc_intersections.elementAt(i); + double[] temp = ccIntersections.elementAt(i); results[i] = new Intersection(curve1.evaluatePoint(temp[0]), temp[0], temp[1]); } - cc_intersections = null; + ccIntersections = null; return (results); } /** * Returns the intersections between a line and a quadratic bezier - * Or null if no intersections are found1 + * Or null if no intersections are found. * This is done through combining the line's equation with the * parametric form of the Bezier and solving the resulting quadratic. * This is package-private to avoid an accessor method. @@ -1622,9 +1608,9 @@ public class Area implements Shape, Cloneable * Helper method * Turns a shape into a Vector of Segments */ - private Vector makeSegment(Shape s) + private Vector<Segment> makeSegment(Shape s) { - Vector paths = new Vector(); + Vector<Segment> paths = new Vector<Segment>(); PathIterator pi = s.getPathIterator(null); double[] coords = new double[6]; Segment subpath = null; @@ -1786,7 +1772,7 @@ public class Area implements Shape, Cloneable } while (a != A); // until one wrap. - return (nNodes); + return nNodes; } /** @@ -1824,7 +1810,7 @@ public class Area implements Shape, Cloneable * solid areas) Clears any nodes. Sorts the remaining paths into solids * and holes, sets their orientation and sets the solids and holes lists. */ - private void deleteRedundantPaths(Vector paths) + private void deleteRedundantPaths(Vector<Segment> paths) { int npaths = paths.size(); @@ -1836,19 +1822,19 @@ public class Area implements Shape, Cloneable neg = ((windingRule == PathIterator.WIND_NON_ZERO) ? -1 : 1); for (int i = 0; i < npaths; i++) - bb[i] = ((Segment) paths.elementAt(i)).getPathBounds(); + bb[i] = paths.elementAt(i).getPathBounds(); // Find which path contains which, assign winding numbers for (int i = 0; i < npaths; i++) { - Segment pathA = (Segment) paths.elementAt(i); + Segment pathA = paths.elementAt(i); pathA.nullNodes(); // remove any now-redundant nodes, in case. int windingA = pathA.hasClockwiseOrientation() ? 1 : neg; for (int j = 0; j < npaths; j++) if (i != j) { - Segment pathB = (Segment) paths.elementAt(j); + Segment pathB = paths.elementAt(j); // A contains B if (bb[i].intersects(bb[j])) @@ -1876,8 +1862,8 @@ public class Area implements Shape, Cloneable windingNumbers[i][1] = contains[i][i]; } - Vector solids = new Vector(); - Vector holes = new Vector(); + Vector<Segment> solids = new Vector<Segment>(); + Vector<Segment> holes = new Vector<Segment>(); if (windingRule == PathIterator.WIND_NON_ZERO) { @@ -1913,12 +1899,12 @@ public class Area implements Shape, Cloneable * @param clockwise gives the direction, * true = clockwise, false = counter-clockwise */ - private void setDirection(Vector paths, boolean clockwise) + private void setDirection(Vector<Segment> paths, boolean clockwise) { Segment v; for (int i = 0; i < paths.size(); i++) { - v = (Segment) paths.elementAt(i); + v = paths.elementAt(i); if (clockwise != v.hasClockwiseOrientation()) v.reverseAll(); } @@ -2157,7 +2143,7 @@ public class Area implements Shape, Cloneable */ Segment cloneSegmentList() throws CloneNotSupportedException { - Vector list = new Vector(); + Vector<Segment> list = new Vector<Segment>(); Segment v = next; while (v != this) @@ -2170,7 +2156,7 @@ public class Area implements Shape, Cloneable v = clone; for (int i = 0; i < list.size(); i++) { - clone.next = (Segment) ((Segment) list.elementAt(i)).clone(); + clone.next = (Segment) list.elementAt(i).clone(); clone = clone.next; } clone.next = v; @@ -2209,7 +2195,7 @@ public class Area implements Shape, Cloneable */ protected int createNodes(Segment b, Intersection[] x) { - Vector v = new Vector(); + Vector<Intersection> v = new Vector<Intersection>(); for (int i = 0; i < x.length; i++) { Point2D p = x[i].p; @@ -2222,7 +2208,7 @@ public class Area implements Shape, Cloneable Intersection[] A = new Intersection[nNodes]; Intersection[] B = new Intersection[nNodes]; for (int i = 0; i < nNodes; i++) - A[i] = B[i] = (Intersection) v.elementAt(i); + A[i] = B[i] = v.elementAt(i); // Create two lists sorted by the parameter // Bubble sort, OK I suppose, since the number of intersections diff --git a/libjava/classpath/java/beans/XMLDecoder.java b/libjava/classpath/java/beans/XMLDecoder.java index 26896393a9e..bafafe400a9 100644 --- a/libjava/classpath/java/beans/XMLDecoder.java +++ b/libjava/classpath/java/beans/XMLDecoder.java @@ -104,6 +104,7 @@ import java.util.NoSuchElementException; * @status updated to 1.5 */ public class XMLDecoder + implements AutoCloseable { private Object owner; diff --git a/libjava/classpath/java/beans/XMLEncoder.java b/libjava/classpath/java/beans/XMLEncoder.java index 40cb6dbfb59..894e4b873c4 100644 --- a/libjava/classpath/java/beans/XMLEncoder.java +++ b/libjava/classpath/java/beans/XMLEncoder.java @@ -50,7 +50,9 @@ import java.io.OutputStream; * @author Robert Schuster (robertschuster@fsfe.org) * @since 1.4 */ -public class XMLEncoder extends Encoder +public class XMLEncoder + extends Encoder + implements AutoCloseable { Object owner; diff --git a/libjava/classpath/java/io/Closeable.java b/libjava/classpath/java/io/Closeable.java index b8523d79e63..f5f808381aa 100644 --- a/libjava/classpath/java/io/Closeable.java +++ b/libjava/classpath/java/io/Closeable.java @@ -48,6 +48,7 @@ package java.io; * @since 1.5 */ public interface Closeable + extends AutoCloseable { /** diff --git a/libjava/classpath/java/io/ObjectInput.java b/libjava/classpath/java/io/ObjectInput.java index f8d51e00d07..071f67d9031 100644 --- a/libjava/classpath/java/io/ObjectInput.java +++ b/libjava/classpath/java/io/ObjectInput.java @@ -48,7 +48,8 @@ package java.io; * * @see DataInput */ -public interface ObjectInput extends DataInput +public interface ObjectInput + extends DataInput, AutoCloseable { /** * This method returns the number of bytes that can be read without diff --git a/libjava/classpath/java/io/ObjectInputStream.java b/libjava/classpath/java/io/ObjectInputStream.java index c37f7665f1c..657072d5a30 100644 --- a/libjava/classpath/java/io/ObjectInputStream.java +++ b/libjava/classpath/java/io/ObjectInputStream.java @@ -529,12 +529,13 @@ public class ObjectInputStream extends InputStream if (dump) dumpElementln("ENUM="); ObjectStreamClass osc = (ObjectStreamClass) readObject(); + int enumHandle = assignNewHandle(null, shared); String constantName = (String) readObject(); if (dump) dumpElementln("CONSTANT NAME = " + constantName); Class clazz = osc.forClass(); Enum instance = Enum.valueOf(clazz, constantName); - assignNewHandle(instance,shared); + rememberHandle(instance, shared, enumHandle); ret_val = instance; break; } diff --git a/libjava/classpath/java/io/ObjectOutput.java b/libjava/classpath/java/io/ObjectOutput.java index 628f8b97b86..4ec6c6f0768 100644 --- a/libjava/classpath/java/io/ObjectOutput.java +++ b/libjava/classpath/java/io/ObjectOutput.java @@ -48,7 +48,8 @@ package java.io; * * @see DataOutput */ -public interface ObjectOutput extends DataOutput +public interface ObjectOutput + extends DataOutput, AutoCloseable { /** * This method writes the specified byte to the output stream. diff --git a/libjava/classpath/java/lang/AssertionError.java b/libjava/classpath/java/lang/AssertionError.java index 778eb583051..cf953f4498b 100644 --- a/libjava/classpath/java/lang/AssertionError.java +++ b/libjava/classpath/java/lang/AssertionError.java @@ -1,5 +1,5 @@ /* AssertionError.java -- indication of a failed assertion - Copyright (C) 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -145,4 +145,16 @@ public class AssertionError extends Error { super(Double.toString(msg)); } + + /** + * Construct an AssertionError with detail message and cause. + * + * @param msg Detail message. + * @param cause The cause of this exception, may be null + * @since 1.7 + */ + public AssertionError(String msg, Throwable cause) + { + super(msg, cause); + } } diff --git a/libjava/classpath/java/lang/AutoCloseable.java b/libjava/classpath/java/lang/AutoCloseable.java new file mode 100644 index 00000000000..4c1ddaa3204 --- /dev/null +++ b/libjava/classpath/java/lang/AutoCloseable.java @@ -0,0 +1,50 @@ +/* AutoCloseable.java -- Resource that must be closed after it is no longer + used. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Resource that must be closed after it is no longer used. + * + * @since 1.7 + */ +public interface AutoCloseable +{ + void close() throws Exception; +} diff --git a/libjava/classpath/java/lang/Boolean.java b/libjava/classpath/java/lang/Boolean.java index f2eaf412592..0e4afa813bf 100644 --- a/libjava/classpath/java/lang/Boolean.java +++ b/libjava/classpath/java/lang/Boolean.java @@ -237,6 +237,21 @@ public final class Boolean implements Serializable, Comparable<Boolean> } /** + * Compares two unboxed boolean values. + * + * @param x First value to compare. + * @param y Second value to compare. + * @return 0 if both Booleans represent the same value, a positive number + * if this Boolean represents true and the other false, and a negative + * number otherwise. + * @since 1.7 + */ + public static int compare(boolean x, boolean y) + { + return Boolean.valueOf(x).compareTo(Boolean.valueOf(y)); + } + + /** * If the String argument is "true", ignoring case, return true. * Otherwise, return false. * diff --git a/libjava/classpath/java/lang/Byte.java b/libjava/classpath/java/lang/Byte.java index a1536e1be1b..01e0e03d2f6 100644 --- a/libjava/classpath/java/lang/Byte.java +++ b/libjava/classpath/java/lang/Byte.java @@ -370,4 +370,21 @@ public final class Byte extends Number implements Comparable<Byte> return value - b.value; } + /** + * Compares two unboxed byte values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(byte x, byte y) + { + return Byte.valueOf(x).compareTo(Byte.valueOf(y)); + } + } diff --git a/libjava/classpath/java/lang/Character.java b/libjava/classpath/java/lang/Character.java index 05e641c3a48..f87cde62c1e 100644 --- a/libjava/classpath/java/lang/Character.java +++ b/libjava/classpath/java/lang/Character.java @@ -4200,6 +4200,23 @@ public final class Character implements Serializable, Comparable<Character> } /** + * Compares two unboxed char values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(char x, char y) + { + return Character.valueOf(x).compareTo(Character.valueOf(y)); + } + + /** * Returns an <code>Character</code> object wrapping the value. * In contrast to the <code>Character</code> constructor, this method * will cache some values. It is used by boxing conversion. diff --git a/libjava/classpath/java/lang/ClassNotFoundException.java b/libjava/classpath/java/lang/ClassNotFoundException.java index 142bc5d0306..fe1424dc2b1 100644 --- a/libjava/classpath/java/lang/ClassNotFoundException.java +++ b/libjava/classpath/java/lang/ClassNotFoundException.java @@ -1,5 +1,5 @@ /* ClassNotFoundException.java -- thrown when class definition cannot be found - Copyright (C) 1998, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -47,9 +47,9 @@ package java.lang; * @see Class#forName(String) * @see ClassLoader#findSystemClass(String) * @see ClassLoader#loadClass(String, boolean) - * @status updated to 1.4 + * @status updated to 1.7 */ -public class ClassNotFoundException extends Exception +public class ClassNotFoundException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/IllegalAccessException.java b/libjava/classpath/java/lang/IllegalAccessException.java index a352c8b1b31..2574f66047c 100644 --- a/libjava/classpath/java/lang/IllegalAccessException.java +++ b/libjava/classpath/java/lang/IllegalAccessException.java @@ -1,6 +1,6 @@ /* IllegalAccessException.java -- thrown on attempt to reflect on inaccessible data - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -71,9 +71,9 @@ import java.lang.reflect.Method; * @see Field#getDouble(Object) * @see Method#invoke(Object, Object[]) * @see Constructor#newInstance(Object[]) - * @status updated to 1.4 + * @status updated to 1.7 */ -public class IllegalAccessException extends Exception +public class IllegalAccessException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/InstantiationException.java b/libjava/classpath/java/lang/InstantiationException.java index 367b14bd278..cb2cad15432 100644 --- a/libjava/classpath/java/lang/InstantiationException.java +++ b/libjava/classpath/java/lang/InstantiationException.java @@ -1,6 +1,6 @@ /* InstantiationException.java -- thrown when reflection cannot create an instance - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,9 +46,9 @@ package java.lang; * @author Brian Jones * @author Warren Levy (warrenl@cygnus.com) * @see Class#newInstance() - * @status updated to 1.4 + * @status updated to 1.7 */ -public class InstantiationException extends Exception +public class InstantiationException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/Integer.java b/libjava/classpath/java/lang/Integer.java index f379795ea3d..25eb5d5265d 100644 --- a/libjava/classpath/java/lang/Integer.java +++ b/libjava/classpath/java/lang/Integer.java @@ -586,6 +586,23 @@ public final class Integer extends Number implements Comparable<Integer> } /** + * Compares two unboxed int values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(int x, int y) + { + return Integer.valueOf(x).compareTo(Integer.valueOf(y)); + } + + /** * Return the number of bits set in x. * @param x value to examine * @since 1.5 diff --git a/libjava/classpath/java/lang/LinkageError.java b/libjava/classpath/java/lang/LinkageError.java index 028702081ba..34b072572cf 100644 --- a/libjava/classpath/java/lang/LinkageError.java +++ b/libjava/classpath/java/lang/LinkageError.java @@ -1,6 +1,6 @@ /* LinkageError.java -- thrown when classes valid at separate compile times cannot be linked to each other - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,7 +46,7 @@ package java.lang; * * @author Brian Jones * @author Tom Tromey (tromey@cygnus.com) - * @status updated to 1.4 + * @status updated to 1.7 */ public class LinkageError extends Error { @@ -71,4 +71,17 @@ public class LinkageError extends Error { super(s); } + + /** + * Construct an LinkageError with detail message and cause. + * + * @param msg Detail message. + * @param cause The cause of this exception, may be null + * @since 1.7 + */ + public LinkageError(String msg, Throwable cause) + { + super(msg, cause); + } + } diff --git a/libjava/classpath/java/lang/Long.java b/libjava/classpath/java/lang/Long.java index e7579d86556..6f31dfa9953 100644 --- a/libjava/classpath/java/lang/Long.java +++ b/libjava/classpath/java/lang/Long.java @@ -585,6 +585,23 @@ public final class Long extends Number implements Comparable<Long> } /** + * Compares two unboxed long values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(long x, long y) + { + return Long.valueOf(x).compareTo(Long.valueOf(y)); + } + + /** * Return the number of bits set in x. * @param x value to examine * @since 1.5 diff --git a/libjava/classpath/java/lang/NoSuchFieldException.java b/libjava/classpath/java/lang/NoSuchFieldException.java index 74d52d137c4..b43b53206ad 100644 --- a/libjava/classpath/java/lang/NoSuchFieldException.java +++ b/libjava/classpath/java/lang/NoSuchFieldException.java @@ -1,5 +1,5 @@ /* NoSuchFieldException.java -- thrown when reflecting a non-existant field - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,9 +45,9 @@ package java.lang; * @author Brian Jones * @author Warren Levy (warrenl@cygnus.com) * @since 1.1 - * @status updated to 1.4 + * @status updated to 1.7 */ -public class NoSuchFieldException extends Exception +public class NoSuchFieldException extends ReflectiveOperationException { /** * Compatible with JDK 1.1+. diff --git a/libjava/classpath/java/lang/NoSuchMethodException.java b/libjava/classpath/java/lang/NoSuchMethodException.java index e423efb79f6..116238220be 100644 --- a/libjava/classpath/java/lang/NoSuchMethodException.java +++ b/libjava/classpath/java/lang/NoSuchMethodException.java @@ -1,5 +1,5 @@ /* NoSuchMethodException.java -- thrown when reflecting a non-existant method - Copyright (C) 1998, 1999, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,9 +44,9 @@ package java.lang; * * @author Brian Jones * @author Warren Levy (warrenl@cygnus.com) - * @status updated to 1.4 + * @status updated to 1.7 */ -public class NoSuchMethodException extends Exception +public class NoSuchMethodException extends ReflectiveOperationException { /** * Compatible with JDK 1.0+. diff --git a/libjava/classpath/java/lang/ReflectiveOperationException.java b/libjava/classpath/java/lang/ReflectiveOperationException.java new file mode 100644 index 00000000000..8b84c0e290f --- /dev/null +++ b/libjava/classpath/java/lang/ReflectiveOperationException.java @@ -0,0 +1,88 @@ +/* ReflectiveOperationException.java -- thrown when reflective operation fails + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * This exception is thrown when reflective operations fail. + * + * @since 1.7 + */ +public class ReflectiveOperationException extends Exception +{ + private static final long serialVersionUID = 123456789L; + + /** + * Create an exception without a message. + */ + public ReflectiveOperationException() + { + } + + /** + * Create an exception with a message. + * + * @param s the message + */ + public ReflectiveOperationException(String s) + { + super(s); + } + + /** + * Create an exception with a message and a cause. + * + * @param s the message + * @param cause the cause, may be null + */ + public ReflectiveOperationException(String message, Throwable cause) + { + super(message, cause); + } + + /** + * Create an exception with a cause. + * + * @param cause the cause, may be null + */ + public ReflectiveOperationException(Throwable cause) + { + super(cause); + } + +} diff --git a/libjava/classpath/java/lang/Short.java b/libjava/classpath/java/lang/Short.java index ec87f933e93..fae9fe7635b 100644 --- a/libjava/classpath/java/lang/Short.java +++ b/libjava/classpath/java/lang/Short.java @@ -373,6 +373,23 @@ public final class Short extends Number implements Comparable<Short> } /** + * Compares two unboxed short values. + * The result is positive if the first is greater, negative if the second + * is greater, and 0 if the two are equal. + * + * @param x First value to compare. + * @param y Second value to compare. + * + * @return positive int if the first value is greater, negative if the second + * is greater, and 0 if the two are equal. + * @since 1.7 + */ + public static int compare(short x, short y) + { + return Short.valueOf(x).compareTo(Short.valueOf(y)); + } + + /** * Reverse the bytes in val. * @since 1.5 */ diff --git a/libjava/classpath/java/lang/String.java b/libjava/classpath/java/lang/String.java index 45c0daff673..27294cdd4eb 100644 --- a/libjava/classpath/java/lang/String.java +++ b/libjava/classpath/java/lang/String.java @@ -705,6 +705,8 @@ public final class String */ public synchronized int codePointAt(int index) { + if (index < 0 || index >= count) + throw new StringIndexOutOfBoundsException(index); // Use the CharSequence overload as we get better range checking // this way. return Character.codePointAt(this, index); @@ -716,12 +718,14 @@ public final class String * <code>index-2</code> to see if they form a supplementary code point. * @param index the index just past the codepoint to get, starting at 0 * @return the codepoint at the specified index - * @throws IndexOutOfBoundsException if index is negative or >= length() + * @throws IndexOutOfBoundsException if index is less than 1 or > length() * (while unspecified, this is a StringIndexOutOfBoundsException) * @since 1.5 */ public synchronized int codePointBefore(int index) { + if (index < 1 || index > count) + throw new StringIndexOutOfBoundsException(index); // Use the CharSequence overload as we get better range checking // this way. return Character.codePointBefore(this, index); diff --git a/libjava/classpath/java/lang/System.java b/libjava/classpath/java/lang/System.java index 51b3259fa8b..9d869918300 100644 --- a/libjava/classpath/java/lang/System.java +++ b/libjava/classpath/java/lang/System.java @@ -97,6 +97,8 @@ public final class System */ public static final PrintStream out = VMSystem.makeStandardOutputStream(); + private static final String LINE_SEPARATOR = SystemProperties.getProperty("line.separator"); + /** * The standard output PrintStream. This is assigned at startup and * starts its life perfectly valid. Although it is marked final, you can @@ -713,6 +715,16 @@ public final class System } /** + * Returns the system-dependent line separator. + * + * @return the system-dependent line separator. + */ + public static String lineSeparator() + { + return LINE_SEPARATOR; + } + + /** * This is a specialised <code>Collection</code>, providing * the necessary provisions for the collections used by the * environment variable map. Namely, it prevents diff --git a/libjava/classpath/java/lang/reflect/InvocationTargetException.java b/libjava/classpath/java/lang/reflect/InvocationTargetException.java index af79d3a199d..4480fc6d006 100644 --- a/libjava/classpath/java/lang/reflect/InvocationTargetException.java +++ b/libjava/classpath/java/lang/reflect/InvocationTargetException.java @@ -1,5 +1,5 @@ /* InvocationTargetException.java -- Wrapper exception for reflection - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -50,9 +50,9 @@ package java.lang.reflect; * @see Method#invoke(Object,Object[]) * @see Constructor#newInstance(Object[]) * @since 1.1 - * @status updated to 1.4 + * @status updated to 1.7 */ -public class InvocationTargetException extends Exception +public class InvocationTargetException extends ReflectiveOperationException { /** * Compatible with JDK 1.1+. diff --git a/libjava/classpath/java/lang/reflect/Member.java b/libjava/classpath/java/lang/reflect/Member.java index fed962cf913..945fbf69663 100644 --- a/libjava/classpath/java/lang/reflect/Member.java +++ b/libjava/classpath/java/lang/reflect/Member.java @@ -79,7 +79,7 @@ public interface Member * * @return the class that declared this member */ - Class getDeclaringClass(); + Class<?> getDeclaringClass(); /** * Gets the simple name of this member. This will be a valid Java diff --git a/libjava/classpath/java/lang/reflect/Modifier.java b/libjava/classpath/java/lang/reflect/Modifier.java index 15bad05e738..c75f7b81823 100644 --- a/libjava/classpath/java/lang/reflect/Modifier.java +++ b/libjava/classpath/java/lang/reflect/Modifier.java @@ -1,5 +1,5 @@ /* java.lang.reflect.Modifier - Copyright (C) 1998, 1999, 2001, 2002, 2005, 2008 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2002, 2005, 2008, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -300,6 +300,46 @@ public class Modifier } /** + * @since 1.7 + */ + public static int classModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | STRICT; + } + + /** + * @since 1.7 + */ + public static int interfaceModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | STRICT; + } + + /** + * @since 1.7 + */ + public static int constructorModifiers() + { + return PUBLIC | PROTECTED | PRIVATE; + } + + /** + * @since 1.7 + */ + public static int methodModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | ABSTRACT | FINAL | STRICT | SYNCHRONIZED | NATIVE; + } + + /** + * @since 1.7 + */ + public static int fieldModifiers() + { + return PUBLIC | PROTECTED | PRIVATE | STATIC | FINAL | TRANSIENT | VOLATILE; + } + + /** * Get a string representation of all the modifiers represented by the * given int. The keywords are printed in this order: * <code><public|protected|private> abstract static final transient diff --git a/libjava/classpath/java/nio/channels/FileLock.java b/libjava/classpath/java/nio/channels/FileLock.java index 78210b34d4d..02b561a5690 100644 --- a/libjava/classpath/java/nio/channels/FileLock.java +++ b/libjava/classpath/java/nio/channels/FileLock.java @@ -45,6 +45,7 @@ import java.io.IOException; * @since 1.4 */ public abstract class FileLock + implements AutoCloseable { private final FileChannel channel; private final long position; diff --git a/libjava/classpath/java/sql/Connection.java b/libjava/classpath/java/sql/Connection.java index f3752762597..b1e7034b5a3 100644 --- a/libjava/classpath/java/sql/Connection.java +++ b/libjava/classpath/java/sql/Connection.java @@ -46,6 +46,7 @@ import java.util.Map; * @author Aaron M. Renn (arenn@urbanophile.com) */ public interface Connection + extends AutoCloseable { /** * This transaction isolation level indicates that transactions are not diff --git a/libjava/classpath/java/sql/ResultSet.java b/libjava/classpath/java/sql/ResultSet.java index 3b49a6a0d6c..c487bed6b94 100644 --- a/libjava/classpath/java/sql/ResultSet.java +++ b/libjava/classpath/java/sql/ResultSet.java @@ -60,6 +60,7 @@ import java.util.Map; * @author Aaron M. Renn (arenn@urbanophile.com) */ public interface ResultSet + extends AutoCloseable { /** * The rows will be processed in order from first to last. diff --git a/libjava/classpath/java/sql/Statement.java b/libjava/classpath/java/sql/Statement.java index 1b57fb3ce3c..5f35e7b187d 100644 --- a/libjava/classpath/java/sql/Statement.java +++ b/libjava/classpath/java/sql/Statement.java @@ -44,6 +44,7 @@ package java.sql; * @author Aaron M. Renn (arenn@urbanophile.com) */ public interface Statement + extends AutoCloseable { int CLOSE_CURRENT_RESULT = 1; int KEEP_CURRENT_RESULT = 2; diff --git a/libjava/classpath/java/text/AttributedString.java b/libjava/classpath/java/text/AttributedString.java index 7ffb3d4c073..4293d7dd253 100644 --- a/libjava/classpath/java/text/AttributedString.java +++ b/libjava/classpath/java/text/AttributedString.java @@ -1,5 +1,5 @@ /* AttributedString.java -- Models text with attributes - Copyright (C) 1998, 1999, 2004, 2005, 2006, Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2004, 2005, 2006, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -48,6 +48,8 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import static java.text.AttributedCharacterIterator.Attribute; + /** * This class models a <code>String</code> with attributes over various * subranges of the string. It allows applications to access this @@ -68,7 +70,7 @@ public class AttributedString { /** A Map of the attributes */ - Map attribs; + Map<? extends Attribute, ?> attribs; /** The beginning index of the attributes */ int beginIndex; @@ -83,7 +85,8 @@ public class AttributedString * @param beginIndex the start index. * @param endIndex the end index. */ - AttributeRange(Map attribs, int beginIndex, int endIndex) + AttributeRange(Map<? extends Attribute, ?> attribs, + int beginIndex, int endIndex) { this.attribs = attribs; this.beginIndex = beginIndex; @@ -122,7 +125,7 @@ public class AttributedString * @param attributes The attribute list. */ public AttributedString(String str, - Map<? extends AttributedCharacterIterator.Attribute, ?> attributes) + Map<? extends Attribute, ?> attributes) { this(str); @@ -178,7 +181,7 @@ public class AttributedString * <code>null</code> to include all attributes. */ public AttributedString(AttributedCharacterIterator aci, int begin, int end, - AttributedCharacterIterator.Attribute[] attributes) + Attribute[] attributes) { // Validate some arguments if ((begin < 0) || (end < begin) || end > aci.getEndIndex()) @@ -187,29 +190,28 @@ public class AttributedString CPStringBuilder sb = new CPStringBuilder(""); // Get the valid attribute list - Set allAttribs = aci.getAllAttributeKeys(); + Set<Attribute> allAttribs = aci.getAllAttributeKeys(); if (attributes != null) allAttribs.retainAll(Arrays.asList(attributes)); // Loop through and extract the attributes char c = aci.setIndex(begin); - ArrayList accum = new ArrayList(); + ArrayList<AttributeRange> accum = new ArrayList<AttributeRange>(); do { sb.append(c); - Iterator iter = allAttribs.iterator(); + Iterator<Attribute> iter = allAttribs.iterator(); while(iter.hasNext()) { Object obj = iter.next(); // What should we do if this is not true? - if (!(obj instanceof AttributedCharacterIterator.Attribute)) + if (!(obj instanceof Attribute)) continue; - AttributedCharacterIterator.Attribute attrib = - (AttributedCharacterIterator.Attribute)obj; + Attribute attrib = (Attribute)obj; // Make sure the attribute is defined. Object attribObj = aci.getAttribute(attrib); @@ -237,7 +239,7 @@ public class AttributedString } // Create a map object. Yes this will only contain one attribute - Map newMap = new Hashtable(); + Map<Attribute,Object> newMap = new Hashtable<Attribute,Object>(); newMap.put(attrib, attribObj); // Add it to the attribute list. @@ -249,7 +251,7 @@ public class AttributedString while( aci.getIndex() < end ); attribs = new AttributeRange[accum.size()]; - attribs = (AttributeRange[]) accum.toArray(attribs); + attribs = accum.toArray(attribs); sci = new StringCharacterIterator(sb.toString()); } @@ -260,8 +262,7 @@ public class AttributedString * @param attrib The attribute to add. * @param value The value of the attribute. */ - public void addAttribute(AttributedCharacterIterator.Attribute attrib, - Object value) + public void addAttribute(Attribute attrib, Object value) { addAttribute(attrib, value, 0, sci.getEndIndex()); } @@ -278,14 +279,13 @@ public class AttributedString * @exception IllegalArgumentException If attribute is <code>null</code> or * the subrange is not valid. */ - public void addAttribute(AttributedCharacterIterator.Attribute attrib, - Object value, int begin, int end) + public void addAttribute(Attribute attrib, Object value, int begin, int end) { if (attrib == null) throw new IllegalArgumentException("null attribute"); if (end <= begin) throw new IllegalArgumentException("Requires end > begin"); - HashMap hm = new HashMap(); + HashMap<Attribute,Object> hm = new HashMap<Attribute,Object>(); hm.put(attrib, value); addAttributes(hm, begin, end); @@ -303,7 +303,7 @@ public class AttributedString * <code>null</code>. * @throws IllegalArgumentException if the subrange is not valid. */ - public void addAttributes(Map<? extends AttributedCharacterIterator.Attribute, ?> attributes, + public void addAttributes(Map<? extends Attribute, ?> attributes, int beginIndex, int endIndex) { if (attributes == null) @@ -343,8 +343,7 @@ public class AttributedString * * @return An <code>AttributedCharacterIterator</code> for this string. */ - public AttributedCharacterIterator getIterator( - AttributedCharacterIterator.Attribute[] attributes) + public AttributedCharacterIterator getIterator(Attribute[] attributes) { return(getIterator(attributes, 0, sci.getEndIndex())); } @@ -363,8 +362,7 @@ public class AttributedString * * @return An <code>AttributedCharacterIterator</code> for this string. */ - public AttributedCharacterIterator getIterator( - AttributedCharacterIterator.Attribute[] attributes, + public AttributedCharacterIterator getIterator(Attribute[] attributes, int beginIndex, int endIndex) { if ((beginIndex < 0) || (endIndex > sci.getEndIndex()) || diff --git a/libjava/classpath/java/text/AttributedStringIterator.java b/libjava/classpath/java/text/AttributedStringIterator.java index 429bd7063db..6d402cbca5d 100644 --- a/libjava/classpath/java/text/AttributedStringIterator.java +++ b/libjava/classpath/java/text/AttributedStringIterator.java @@ -1,5 +1,5 @@ /* AttributedStringIterator.java -- Class to iterate over AttributedString - Copyright (C) 1998, 1999, 2004, 2005, 2006, Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2004, 2005, 2006, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,6 +44,8 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import static java.text.AttributedCharacterIterator.Attribute; + /** * This class implements the AttributedCharacterIterator interface. It * is used by AttributedString.getIterator(). @@ -67,7 +69,7 @@ class AttributedStringIterator implements AttributedCharacterIterator * The list of attributes that the user is interested in. We may, * at our option, not return any other attributes. */ - private AttributedCharacterIterator.Attribute[] restricts; + private Attribute[] restricts; /*************************************************************************/ @@ -155,9 +157,9 @@ class AttributedStringIterator implements AttributedCharacterIterator * Returns a list of all the attribute keys that are defined anywhere * on this string. */ - public Set getAllAttributeKeys() + public Set<Attribute> getAllAttributeKeys() { - HashSet s = new HashSet(); + HashSet<Attribute> s = new HashSet<Attribute>(); if (attribs == null) return(s); @@ -167,8 +169,7 @@ class AttributedStringIterator implements AttributedCharacterIterator || attribs[i].endIndex <= getBeginIndex()) continue; - Set key_set = attribs[i].attribs.keySet(); - Iterator iter = key_set.iterator(); + Iterator<? extends Attribute> iter = attribs[i].attribs.keySet().iterator(); while (iter.hasNext()) { s.add(iter.next()); @@ -190,14 +191,14 @@ class AttributedStringIterator implements AttributedCharacterIterator return getRunLimit(getAllAttributeKeys()); } - public int getRunLimit(AttributedCharacterIterator.Attribute attrib) + public int getRunLimit(Attribute attrib) { - HashSet s = new HashSet(); + HashSet<Attribute> s = new HashSet<Attribute>(); s.add(attrib); return(getRunLimit(s)); } - public synchronized int getRunLimit(Set attributeSet) + public synchronized int getRunLimit(Set<? extends Attribute> attributeSet) { if (attributeSet == null) return ci.getEndIndex(); @@ -207,13 +208,13 @@ class AttributedStringIterator implements AttributedCharacterIterator int limit = current; if (current == end) return end; - Map runValues = getAttributes(); + Map<Attribute,Object> runValues = getAttributes(); while (limit < end) { - Iterator iterator = attributeSet.iterator(); + Iterator<? extends Attribute> iterator = attributeSet.iterator(); while (iterator.hasNext()) { - Attribute attributeKey = (Attribute) iterator.next(); + Attribute attributeKey = iterator.next(); Object v1 = runValues.get(attributeKey); Object v2 = getAttribute(attributeKey, limit + 1); boolean changed = false; @@ -262,11 +263,11 @@ class AttributedStringIterator implements AttributedCharacterIterator * * return The index of the first character in the run. */ - public int getRunStart(AttributedCharacterIterator.Attribute attrib) + public int getRunStart(Attribute attrib) { if (attrib == null) return ci.getBeginIndex(); - HashSet s = new HashSet(); + HashSet<Attribute> s = new HashSet<Attribute>(); s.add(attrib); return(getRunStart(s)); } @@ -279,7 +280,7 @@ class AttributedStringIterator implements AttributedCharacterIterator * * return The index of the first character in the run. */ - public int getRunStart(Set attributeSet) + public int getRunStart(Set<? extends Attribute> attributeSet) { if (attributeSet == null) return ci.getBeginIndex(); @@ -289,14 +290,14 @@ class AttributedStringIterator implements AttributedCharacterIterator int start = current; if (start == begin) return begin; - Map runValues = getAttributes(); + Map<Attribute, Object> runValues = getAttributes(); int prev = start - 1; while (start > begin) { - Iterator iterator = attributeSet.iterator(); + Iterator<? extends Attribute> iterator = attributeSet.iterator(); while (iterator.hasNext()) { - Attribute attributeKey = (Attribute) iterator.next(); + Attribute attributeKey = iterator.next(); Object v1 = runValues.get(attributeKey); Object v2 = getAttribute(attributeKey, prev); boolean changed = false; @@ -340,7 +341,7 @@ class AttributedStringIterator implements AttributedCharacterIterator { if (pos >= attribs[i].beginIndex && pos < attribs[i].endIndex) { - Set keys = attribs[i].attribs.keySet(); + Set<? extends Attribute> keys = attribs[i].attribs.keySet(); if (keys.contains(key)) { return attribs[i].attribs.get(key); @@ -370,9 +371,9 @@ class AttributedStringIterator implements AttributedCharacterIterator * Return a list of all the attributes and values defined for this * character */ - public Map getAttributes() + public Map<Attribute,Object> getAttributes() { - HashMap m = new HashMap(); + HashMap<Attribute,Object> m = new HashMap<Attribute,Object>(); if (attribs == null) return(m); diff --git a/libjava/classpath/java/text/Bidi.java b/libjava/classpath/java/text/Bidi.java index 6a7bd075069..236247d5ea0 100644 --- a/libjava/classpath/java/text/Bidi.java +++ b/libjava/classpath/java/text/Bidi.java @@ -1,5 +1,5 @@ /* Bidi.java -- Bidirectional Algorithm implementation - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -109,7 +109,7 @@ public final class Bidi // A list of indices where a formatting code was found. These // are indicies into the original text -- not into the text after // the codes have been removed. - private ArrayList formatterIndices; + private ArrayList<Integer> formatterIndices; // Indices of the starts of runs in the text. private int[] runs; @@ -161,13 +161,13 @@ public final class Bidi if (val instanceof NumericShaper) shaper = (NumericShaper) val; - char[] text = new char[iter.getEndIndex() - iter.getBeginIndex()]; - this.embeddings = new byte[this.text.length]; - this.embeddingOffset = 0; - this.length = text.length; - for (int i = 0; i < this.text.length; ++i) + text = new char[iter.getEndIndex() - iter.getBeginIndex()]; + embeddings = new byte[text.length]; + embeddingOffset = 0; + length = text.length; + for (int i = 0; i < text.length; ++i) { - this.text[i] = iter.current(); + text[i] = iter.current(); val = iter.getAttribute(TextAttribute.BIDI_EMBEDDING); if (val instanceof Integer) @@ -178,13 +178,13 @@ public final class Bidi bval = 0; else bval = (byte) ival; - this.embeddings[i] = bval; + embeddings[i] = bval; } } // Invoke the numeric shaper, if specified. if (shaper != null) - shaper.shape(this.text, 0, this.length); + shaper.shape(text, 0, length); runBidi(); } @@ -404,7 +404,7 @@ public final class Bidi { // Mark this character for removal. if (formatterIndices == null) - formatterIndices = new ArrayList(); + formatterIndices = new ArrayList<Integer>(); formatterIndices.add(Integer.valueOf(i)); } else if (directionalOverride != -1) @@ -427,7 +427,7 @@ public final class Bidi if (i == size) nextFmt = length; else - nextFmt = ((Integer) formatterIndices.get(i)).intValue(); + nextFmt = formatterIndices.get(i).intValue(); // Non-formatter codes are from 'input' to 'nextFmt'. int len = nextFmt - input; System.arraycopy(levels, input, levels, output, len); @@ -716,7 +716,7 @@ public final class Bidi // Process from the end as we are copying the array over itself here. for (int index = formatterIndices.size() - 1; index >= 0; --index) { - int nextFmt = ((Integer) formatterIndices.get(index)).intValue(); + int nextFmt = formatterIndices.get(index).intValue(); // nextFmt points to a location in the original array. So, // nextFmt+1 is the target of our copying. output is the location diff --git a/libjava/classpath/java/text/BreakIterator.java b/libjava/classpath/java/text/BreakIterator.java index 628cb723513..6fed88f82d9 100644 --- a/libjava/classpath/java/text/BreakIterator.java +++ b/libjava/classpath/java/text/BreakIterator.java @@ -1,5 +1,5 @@ /* BreakIterator.java -- Breaks text into elements - Copyright (C) 1998, 1999, 2001, 2004, 2005, 2007 + Copyright (C) 1998, 1999, 2001, 2004, 2005, 2007, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -160,7 +160,7 @@ public abstract class BreakIterator implements Cloneable } try { - Class k = Class.forName(className); + Class<?> k = Class.forName(className); return (BreakIterator) k.newInstance(); } catch (ClassNotFoundException x1) diff --git a/libjava/classpath/java/text/ChoiceFormat.java b/libjava/classpath/java/text/ChoiceFormat.java index 4842f491d9c..c6a508cb89a 100644 --- a/libjava/classpath/java/text/ChoiceFormat.java +++ b/libjava/classpath/java/text/ChoiceFormat.java @@ -1,5 +1,5 @@ /* ChoiceFormat.java -- Format over a range of numbers - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -98,8 +98,8 @@ public class ChoiceFormat extends NumberFormat // This isn't explicitly documented. But for instance we accept // '#' as a literal hash in a format string. int index = 0, max = newPattern.length(); - Vector stringVec = new Vector (); - Vector limitVec = new Vector (); + Vector<String> stringVec = new Vector<String> (); + Vector<Double> limitVec = new Vector<Double> (); final CPStringBuilder buf = new CPStringBuilder (); while (true) @@ -159,7 +159,7 @@ public class ChoiceFormat extends NumberFormat choiceLimits = new double[limitVec.size()]; for (int i = 0; i < choiceLimits.length; ++i) { - Double d = (Double) limitVec.elementAt(i); + Double d = limitVec.elementAt(i); choiceLimits[i] = d.doubleValue(); } } diff --git a/libjava/classpath/java/text/CollationElementIterator.java b/libjava/classpath/java/text/CollationElementIterator.java index 0ca23d07402..42452e9dcdb 100644 --- a/libjava/classpath/java/text/CollationElementIterator.java +++ b/libjava/classpath/java/text/CollationElementIterator.java @@ -1,5 +1,5 @@ /* CollationElementIterator.java -- Walks through collation elements - Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004 Free Software Foundation + Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2012 Free Software Foundation This file is part of GNU Classpath. @@ -91,12 +91,12 @@ public final class CollationElementIterator * Array containing the collation decomposition of the * text given to the constructor. */ - private RuleBasedCollator.CollationElement[] text_decomposition; + private RuleBasedCollator.CollationElement[] textDecomposition; /** * Array containing the index of the specified block. */ - private int[] text_indexes; + private int[] textIndexes; /** * This method initializes a new instance of <code>CollationElementIterator</code> @@ -130,12 +130,12 @@ public final class CollationElementIterator RuleBasedCollator.CollationElement nextBlock() { - if (index >= text_decomposition.length) + if (index >= textDecomposition.length) return null; - RuleBasedCollator.CollationElement e = text_decomposition[index]; + RuleBasedCollator.CollationElement e = textDecomposition[index]; - textIndex = text_indexes[index+1]; + textIndex = textIndexes[index+1]; index++; @@ -148,9 +148,9 @@ public final class CollationElementIterator return null; index--; - RuleBasedCollator.CollationElement e = text_decomposition[index]; + RuleBasedCollator.CollationElement e = textDecomposition[index]; - textIndex = text_indexes[index+1]; + textIndex = textIndexes[index+1]; return e; } @@ -268,23 +268,23 @@ public final class CollationElementIterator String work_text = text.intern(); - ArrayList a_element = new ArrayList(); - ArrayList a_idx = new ArrayList(); + ArrayList<RuleBasedCollator.CollationElement> aElement = new ArrayList<RuleBasedCollator.CollationElement>(); + ArrayList<Integer> aIdx = new ArrayList<Integer>(); // Build element collection ordered as they come in "text". while (idx < work_text.length()) { - String key, key_old; + String key, keyOld; Object object = null; int p = 1; // IMPROVE: use a TreeMap with a prefix-ordering rule. - key_old = key = null; + keyOld = key = null; do { if (object != null) - key_old = key; + keyOld = key; key = work_text.substring (idx, idx+p); object = collator.prefix_tree.get (key); if (object != null && idx < alreadyExpanded) @@ -294,7 +294,7 @@ public final class CollationElementIterator prefix.expansion.startsWith(work_text.substring(0, idx))) { object = null; - key = key_old; + key = keyOld; } } p++; @@ -302,7 +302,7 @@ public final class CollationElementIterator while (idx+p <= work_text.length()); if (object == null) - key = key_old; + key = keyOld; RuleBasedCollator.CollationElement prefix = (RuleBasedCollator.CollationElement) collator.prefix_tree.get (key); @@ -322,8 +322,8 @@ public final class CollationElementIterator RuleBasedCollator.CollationElement e = collator.getDefaultAccentedElement (work_text.charAt (idx)); - a_element.add (e); - a_idx.add (new Integer(idx_idx)); + aElement.add (e); + aIdx.add (Integer.valueOf(idx_idx)); idx++; alreadyExpanded--; if (alreadyExpanded == 0) @@ -342,15 +342,15 @@ public final class CollationElementIterator /* This is a normal character. */ RuleBasedCollator.CollationElement e = collator.getDefaultElement (work_text.charAt (idx)); - Integer i_ref = new Integer(idx_idx); + Integer iRef = Integer.valueOf(idx_idx); /* Don't forget to mark it as a special sequence so the * string can be ordered. */ - a_element.add (RuleBasedCollator.SPECIAL_UNKNOWN_SEQ); - a_idx.add (i_ref); - a_element.add (e); - a_idx.add (i_ref); + aElement.add (RuleBasedCollator.SPECIAL_UNKNOWN_SEQ); + aIdx.add (iRef); + aElement.add (e); + aIdx.add (iRef); idx_idx++; idx++; } @@ -367,8 +367,8 @@ public final class CollationElementIterator work_text = prefix.expansion + work_text.substring (idx+prefix.key.length()); idx = 0; - a_element.add (prefix); - a_idx.add (new Integer(idx_idx)); + aElement.add (prefix); + aIdx.add (Integer.valueOf(idx_idx)); if (alreadyExpanded == 0) idxToMove = prefix.key.length(); alreadyExpanded += prefix.expansion.length()-prefix.key.length(); @@ -378,8 +378,8 @@ public final class CollationElementIterator /* Third case: the simplest. We have got the prefix and it * has not to be expanded. */ - a_element.add (prefix); - a_idx.add (new Integer(idx_idx)); + aElement.add (prefix); + aIdx.add (Integer.valueOf(idx_idx)); idx += prefix.key.length(); /* If the sequence is in an expansion, we must decrease the * counter. @@ -398,14 +398,13 @@ public final class CollationElementIterator } } - text_decomposition = (RuleBasedCollator.CollationElement[]) - a_element.toArray(new RuleBasedCollator.CollationElement[a_element.size()]); - text_indexes = new int[a_idx.size()+1]; - for (int i = 0; i < a_idx.size(); i++) + textDecomposition = aElement.toArray(new RuleBasedCollator.CollationElement[aElement.size()]); + textIndexes = new int[aIdx.size()+1]; + for (int i = 0; i < aIdx.size(); i++) { - text_indexes[i] = ((Integer)a_idx.get(i)).intValue(); + textIndexes[i] = aIdx.get(i).intValue(); } - text_indexes[a_idx.size()] = text.length(); + textIndexes[aIdx.size()] = text.length(); } /** @@ -460,19 +459,19 @@ public final class CollationElementIterator if (offset > (text.getEndIndex() - 1)) throw new IllegalArgumentException("Offset too large: " + offset); - for (index = 0; index < text_decomposition.length; index++) + for (index = 0; index < textDecomposition.length; index++) { - if (offset <= text_indexes[index]) + if (offset <= textIndexes[index]) break; } /* - * As text_indexes[0] == 0, we should not have to take care whether index is + * As textIndexes[0] == 0, we should not have to take care whether index is * greater than 0. It is always. */ - if (text_indexes[index] == offset) + if (textIndexes[index] == offset) textIndex = offset; else - textIndex = text_indexes[index-1]; + textIndex = textIndexes[index-1]; } /** diff --git a/libjava/classpath/java/text/DateFormatSymbols.java b/libjava/classpath/java/text/DateFormatSymbols.java index 53e7ba07c8c..9d0ace65a3e 100644 --- a/libjava/classpath/java/text/DateFormatSymbols.java +++ b/libjava/classpath/java/text/DateFormatSymbols.java @@ -56,6 +56,11 @@ import java.util.ResourceBundle; import java.util.ServiceLoader; import java.util.TimeZone; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentHashMap; + +import java.util.regex.Pattern; + import java.util.spi.TimeZoneNameProvider; /** @@ -71,14 +76,6 @@ import java.util.spi.TimeZoneNameProvider; */ public class DateFormatSymbols implements java.io.Serializable, Cloneable { - String[] ampms; - String[] eras; - private String localPatternChars; - String[] months; - String[] shortMonths; - String[] shortWeekdays; - String[] weekdays; - /** * The set of properties for obtaining the metazone data. */ @@ -100,6 +97,173 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable } } + private static final Pattern ZONE_SEP = Pattern.compile("\u00a9"); + + private static final Pattern FIELD_SEP = Pattern.compile("\u00ae"); + + /** + * Class for storing DateFormatSymbols data parsed from the property files. + */ + private static class DFSData + { + private String[] ampms; + private String[] eras; + private String localPatternChars; + private String[] months; + private String[] shortMonths; + private String[] weekdays; + private String[] shortWeekdays; + private String[] dateFormats; + private String[] timeFormats; + private String[][] runtimeZoneStrings; + + /** + * Construct a new instance with the parsed data. + * + * @param ampms strings for "am" and "pm". + * @param eras strings for calendar eras. + * @param localPatternChars localised pattern characters. + * @param months strings for the months of the year. + * @param shortMonths short strings for the months of the year. + * @param weekdays strings for the days of the week. + * @param shortWeekdays short strings for the days of the week. + * @param dateFormats localised date formats. + * @param timeFormats localised time formats. + * @param runtimeZoneStrings localised time zone names. + */ + public DFSData(String[] ampms, String[] eras, String localPatternChars, + String[] months, String[] shortMonths, String[] weekdays, + String[] shortWeekdays, String[] dateFormats, + String[] timeFormats, String[][] runtimeZoneStrings) + { + this.ampms = ampms; + this.eras = eras; + this.localPatternChars = localPatternChars; + this.months = months; + this.shortMonths = shortMonths; + this.weekdays = weekdays; + this.shortWeekdays = shortWeekdays; + this.dateFormats = dateFormats; + this.timeFormats = timeFormats; + this.runtimeZoneStrings = runtimeZoneStrings; + } + + /** + * Accessor for the AM/PM data. + * + * @return the AM/PM strings. + */ + public String[] getAMPMs() + { + return ampms.clone(); + } + + /** + * Accessor for the era data. + * + * @return the era strings. + */ + public String[] getEras() + { + return eras.clone(); + } + + /** + * Accessor for the local pattern characters. + * + * @return the local pattern characters. + */ + public String getLocalPatternChars() + { + return localPatternChars; + } + + /** + * Accessor for the months of the year (long form). + * + * @return the months of the year (long form). + */ + public String[] getMonths() + { + return months.clone(); + } + + /** + * Accessor for the months of the year (short form). + * + * @return the months of the year (short form). + */ + public String[] getShortMonths() + { + return shortMonths.clone(); + } + + /** + * Accessor for the days of the week (long form). + * + * @return the days of the week (long form). + */ + public String[] getWeekdays() + { + return weekdays.clone(); + } + + /** + * Accessor for the days of the week (short form). + * + * @return the days of the week (short form). + */ + public String[] getShortWeekdays() + { + return shortWeekdays.clone(); + } + + /** + * Accessor for the date formats. + * + * @return the date formats. + */ + public String[] getDateFormats() + { + return dateFormats.clone(); + } + + /** + * Accessor for the time formats. + * + * @return the time formats. + */ + public String[] getTimeFormats() + { + return timeFormats.clone(); + } + + /** + * Accessor for the zone strings. + * + * @return the zone strings. + */ + public String[][] getZoneStrings() + { + // Perform a deep clone so subarrays aren't modifiable + String[][] clone = runtimeZoneStrings.clone(); + for (int a = 0; a < clone.length; ++a) + clone[a] = runtimeZoneStrings[a].clone(); + return clone; + } + + } + + private static final ConcurrentMap<Locale, DFSData> dataCache = new ConcurrentHashMap<Locale, DFSData>(); + + String[] ampms; + String[] eras; + private String localPatternChars; + String[] months; + String[] shortMonths; + String[] shortWeekdays; + String[] weekdays; + /** * The timezone strings supplied by the runtime. */ @@ -161,7 +325,7 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable for (int a = 0; a < bundles.size(); ++a) { String localeData = bundles.get(a).getString(name); - String[] array = localeData.split("\u00ae", size); + String[] array = FIELD_SEP.split(localeData, size); for (int b = 0; b < data.length; ++b) { if (array.length > b && array[b] != null && data[b].isEmpty() && !array[b].isEmpty()) @@ -180,21 +344,20 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable return data; } - private String[][] getZoneStrings(ResourceBundle res, Locale locale) + private static String[][] getZoneStrings(List<ResourceBundle> bundles, Locale locale) { List<String[]> allZones = new ArrayList<String[]>(); try { Map<String,String[]> systemZones = new HashMap<String,String[]>(); - while (true) + for (ResourceBundle bundle : bundles) { - int index = 0; String country = locale.getCountry(); - String data = res.getString("zoneStrings"); - String[] zones = data.split("\u00a9"); + String data = bundle.getString("zoneStrings"); + String[] zones = ZONE_SEP.split(data); for (int a = 0; a < zones.length; ++a) { - String[] strings = zones[a].split("\u00ae"); + String[] strings = FIELD_SEP.split(zones[a]); String type = properties.getProperty(strings[0] + "." + country); if (type == null) type = properties.getProperty(strings[0] + ".DEFAULT"); @@ -217,12 +380,6 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable } systemZones.put(strings[0], strings); } - if (res.getLocale() == Locale.ROOT) - break; - else - res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - LocaleHelper.getFallbackLocale(res.getLocale()), - ClassLoader.getSystemClassLoader()); } /* Final sanity check for missing values */ for (String[] zstrings : systemZones.values()) @@ -288,17 +445,95 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable return allZones.toArray(new String[allZones.size()][]); } - private String[] formatsForKey(ResourceBundle res, String key) + /** + * Retrieve the date or time formats for a specific key e.g. + * asking for "DateFormat" will return an array containing the + * full, long, medium and short date formats localised for + * the locales in the specified bundle. + * + * @param bundles the stack of bundles to check, most-specific first. + * @param key the type of format to retrieve. + * @param an array of localised strings for each format prefix. + */ + private static String[] formatsForKey(List<ResourceBundle> bundles, String key) { String[] values = new String[formatPrefixes.length]; for (int i = 0; i < formatPrefixes.length; i++) - values[i] = res.getString(formatPrefixes[i] + key); + values[i] = getString(bundles, formatPrefixes[i] + key); return values; } /** + * Simple wrapper around extracting a {@code String} from a + * {@code ResourceBundle}. Keep searching less-specific locales + * until a non-null non-empty value is found. + * + * @param bundles the stack of bundles to check, most-specific first. + * @param key the key of the value to retrieve. + * @return the first non-null non-empty String found or the last + * retrieved if one isn't found. + */ + private static String getString(List<ResourceBundle> bundles, String key) + { + String val = null; + for (ResourceBundle bundle : bundles) + { + val = bundle.getString(key); + if (val != null && !val.isEmpty()) + return val; + } + return val; + } + + /** + * Retrieves the locale data from the property files and constructs a + * {@code DFSData} instance for it. + * + * @param the locale for which data should be retrieved. + * @return the parsed data. + * @throws MissingResourceException if the resources for the specified + * locale could not be found or loaded. + */ + private static DFSData retrieveData(Locale locale) + throws MissingResourceException + { + DFSData data = dataCache.get(locale); + if (data == null) + { + ClassLoader ldr = ClassLoader.getSystemClassLoader(); + List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); + ResourceBundle res + = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale, ldr); + bundles.add(res); + Locale resLocale = res.getLocale(); + while (resLocale != Locale.ROOT) + { + res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", + LocaleHelper.getFallbackLocale(resLocale), ldr); + bundles.add(res); + resLocale = res.getLocale(); + } + String[] lMonths = getStringArray(bundles, "months", 13); + String[] lWeekdays = getStringArray(bundles, "weekdays", 8); + data = new DFSData(getStringArray(bundles, "ampms", 2), + getStringArray(bundles, "eras", 2), + getString(bundles, "localPatternChars"), + lMonths, getStringArray(bundles, "shortMonths", 13, lMonths), + lWeekdays, getStringArray(bundles, "shortWeekdays", 8, lWeekdays), + formatsForKey(bundles, "DateFormat"), + formatsForKey(bundles, "TimeFormat"), + getZoneStrings(bundles, locale)); + DFSData cachedData = dataCache.putIfAbsent(locale, data); + // Use the earlier version if another thread beat us to it. + if (cachedData != null) + data = cachedData; + } + return data; + } + + /** * This method initializes a new instance of <code>DateFormatSymbols</code> * by loading the date format information for the specified locale. * This constructor only obtains instances using the runtime's resources; @@ -314,29 +549,17 @@ public class DateFormatSymbols implements java.io.Serializable, Cloneable public DateFormatSymbols (Locale locale) throws MissingResourceException { - ClassLoader ldr = ClassLoader.getSystemClassLoader(); - List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); - ResourceBundle res - = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", locale, ldr); - bundles.add(res); - Locale resLocale = res.getLocale(); - while (resLocale != Locale.ROOT) - { - res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", - LocaleHelper.getFallbackLocale(resLocale), ldr); - bundles.add(res); - resLocale = res.getLocale(); - } - ampms = getStringArray(bundles, "ampms", 2); - eras = getStringArray(bundles, "eras", 2); - localPatternChars = res.getString("localPatternChars"); - months = getStringArray(bundles, "months", 13); - shortMonths = getStringArray(bundles, "shortMonths", 13, months); - weekdays = getStringArray(bundles, "weekdays", 8); - shortWeekdays = getStringArray(bundles, "shortWeekdays", 8, weekdays); - dateFormats = formatsForKey(res, "DateFormat"); - timeFormats = formatsForKey(res, "TimeFormat"); - runtimeZoneStrings = getZoneStrings(res, locale); + DFSData data = retrieveData(locale); + ampms = data.getAMPMs(); + eras = data.getEras(); + localPatternChars = data.getLocalPatternChars(); + months = data.getMonths(); + shortMonths = data.getShortMonths(); + weekdays = data.getWeekdays(); + shortWeekdays = data.getShortWeekdays(); + dateFormats = data.getDateFormats(); + timeFormats = data.getTimeFormats(); + runtimeZoneStrings = data.getZoneStrings(); } /** diff --git a/libjava/classpath/java/text/DecimalFormat.java b/libjava/classpath/java/text/DecimalFormat.java index 9f02bb8d4cb..77af0d396c4 100644 --- a/libjava/classpath/java/text/DecimalFormat.java +++ b/libjava/classpath/java/text/DecimalFormat.java @@ -1,5 +1,5 @@ /* DecimalFormat.java -- Formats and parses numbers - Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -177,7 +177,7 @@ public class DecimalFormat extends NumberFormat private boolean hasFractionalPattern; /** Stores a list of attributes for use by formatToCharacterIterator. */ - private ArrayList attributes = new ArrayList(); + private ArrayList<FieldPosition> attributes = new ArrayList<FieldPosition>(); /** * Constructs a <code>DecimalFormat</code> which uses the default @@ -438,7 +438,7 @@ public class DecimalFormat extends NumberFormat // add NumberFormat field attributes to the AttributedString for (int i = 0; i < attributes.size(); i++) { - FieldPosition pos = (FieldPosition) attributes.get(i); + FieldPosition pos = attributes.get(i); Format.Field attribute = pos.getFieldAttribute(); as.addAttribute(attribute, attribute, pos.getBeginIndex(), diff --git a/libjava/classpath/java/text/MessageFormat.java b/libjava/classpath/java/text/MessageFormat.java index ba5805aa0b9..0e04b2b447a 100644 --- a/libjava/classpath/java/text/MessageFormat.java +++ b/libjava/classpath/java/text/MessageFormat.java @@ -1,5 +1,5 @@ /* MessageFormat.java - Localized message formatting. - Copyright (C) 1999, 2001, 2002, 2004, 2005 Free Software Foundation, Inc. + Copyright (C) 1999, 2001, 2002, 2004, 2005, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -164,7 +164,6 @@ public class MessageFormat extends Format public static final MessageFormat.Field ARGUMENT = new MessageFormat.Field("argument"); // For deserialization - @SuppressWarnings("unused") private Field() { super(""); diff --git a/libjava/classpath/java/text/NumberFormat.java b/libjava/classpath/java/text/NumberFormat.java index fef986bc38e..555ee373957 100644 --- a/libjava/classpath/java/text/NumberFormat.java +++ b/libjava/classpath/java/text/NumberFormat.java @@ -1,5 +1,5 @@ /* NumberFormat.java -- Formats and parses numbers - Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007 + Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -177,7 +177,6 @@ public abstract class NumberFormat extends Format implements Cloneable * This constructor is only used by the deserializer. Without it, * it would fail to construct a valid object. */ - @SuppressWarnings("unused") private Field() { super(""); diff --git a/libjava/classpath/java/util/Collections.java b/libjava/classpath/java/util/Collections.java index 828c6ecea12..b970dd8f60a 100644 --- a/libjava/classpath/java/util/Collections.java +++ b/libjava/classpath/java/util/Collections.java @@ -120,10 +120,10 @@ public class Collections * @return an empty parameterized set. * @since 1.5 */ + @SuppressWarnings("unchecked") public static final <T> Set<T> emptySet() { - /* FIXME: Could this be optimized? */ - return new EmptySet<T>(); + return (Set<T>) EMPTY_SET; } /** @@ -161,6 +161,7 @@ public class Collections * @return A non-iterating iterator. */ // This is really cheating! I think it's perfectly valid, though. + @SuppressWarnings("unchecked") public Iterator<T> iterator() { return (Iterator<T>) EMPTY_LIST.iterator(); @@ -196,7 +197,7 @@ public class Collections */ public boolean equals(Object o) { - return o instanceof Set && ((Set) o).isEmpty(); + return o instanceof Set<?> && ((Set<?>) o).isEmpty(); } /** @@ -288,10 +289,10 @@ public class Collections * @return an empty parameterized list. * @since 1.5 */ + @SuppressWarnings("unchecked") public static final <T> List<T> emptyList() { - /* FIXME: Could this be optimized? */ - return new EmptyList<T>(); + return (List<T>) EMPTY_LIST; } /** @@ -369,7 +370,7 @@ public class Collections */ public boolean equals(Object o) { - return o instanceof List && ((List) o).isEmpty(); + return o instanceof List<?> && ((List<?>) o).isEmpty(); } /** @@ -480,10 +481,10 @@ public class Collections * @return an empty parameterized map. * @since 1.5 */ + @SuppressWarnings("unchecked") public static final <K,V> Map<K,V> emptyMap() { - /* FIXME: Could this be optimized? */ - return new EmptyMap<K,V>(); + return (Map<K,V>) EMPTY_MAP; } /** @@ -511,9 +512,10 @@ public class Collections * There are no entries. * @return The empty set. */ + @SuppressWarnings("unchecked") public Set<Map.Entry<K, V>> entrySet() { - return EMPTY_SET; + return (Set<Map.Entry<K, V>>) EMPTY_SET; } // The remaining methods are optional, but provide a performance @@ -546,7 +548,7 @@ public class Collections */ public boolean equals(Object o) { - return o instanceof Map && ((Map) o).isEmpty(); + return o instanceof Map<?,?> && ((Map<?,?>) o).isEmpty(); } /** @@ -572,9 +574,10 @@ public class Collections * No entries. * @return The empty set. */ + @SuppressWarnings("unchecked") public Set<K> keySet() { - return EMPTY_SET; + return (Set<K>) EMPTY_SET; } /** @@ -601,9 +604,10 @@ public class Collections * Collection, will work. Besides, that's what the JDK uses! * @return The empty set. */ + @SuppressWarnings("unchecked") public Collection<V> values() { - return EMPTY_SET; + return (Collection<V>) EMPTY_SET; } /** @@ -1854,7 +1858,7 @@ public class Collections public List<T> subList(int from, int to) { if (from == to && (to == 0 || to == 1)) - return EMPTY_LIST; + return emptyList(); if (from == 0 && to == 1) return this; if (from > to) @@ -2480,7 +2484,7 @@ public class Collections * @throws ArrayStoreException if the type of any element of the * collection is not a subtype of the element type of a. */ - public <T> T[] toArray(T[] a) + public <E> E[] toArray(E[] a) { synchronized (mutex) { diff --git a/libjava/classpath/java/util/Formatter.java b/libjava/classpath/java/util/Formatter.java index 62f68456239..466fab535ae 100644 --- a/libjava/classpath/java/util/Formatter.java +++ b/libjava/classpath/java/util/Formatter.java @@ -678,6 +678,12 @@ public final class Formatter conversion); noPrecision(precision); + if (arg == null) + { + genericFormat("null", flags, width, precision); + return; + } + int theChar; if (arg instanceof Character) theChar = ((Character) arg).charValue(); @@ -748,6 +754,12 @@ public final class Formatter int radix, char conversion) { assert radix == 8 || radix == 10 || radix == 16; + + if (arg == null) + { + return new CPStringBuilder("null"); + } + noPrecision(precision); // Some error checking. @@ -1353,9 +1365,12 @@ public final class Formatter argumentIndex = previousArgumentIndex; // Argument indices start at 1 but array indices at 0. --argumentIndex; - if (argumentIndex < 0 || argumentIndex >= args.length) - throw new MissingFormatArgumentException(format.substring(start, index)); - argument = args[argumentIndex]; + if (args != null) + { + if (argumentIndex < 0 || argumentIndex >= args.length) + throw new MissingFormatArgumentException(format.substring(start, index)); + argument = args[argumentIndex]; + } } switch (conversion) diff --git a/libjava/classpath/java/util/TimeZone.java b/libjava/classpath/java/util/TimeZone.java index 86a62918ed5..a8b2b51cf8c 100644 --- a/libjava/classpath/java/util/TimeZone.java +++ b/libjava/classpath/java/util/TimeZone.java @@ -1,5 +1,5 @@ /* java.util.TimeZone - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -102,10 +102,10 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable /* Look up default timezone */ if (defaultZone0 == null) { - defaultZone0 = (TimeZone) AccessController.doPrivileged - (new PrivilegedAction() + defaultZone0 = AccessController.doPrivileged + (new PrivilegedAction<TimeZone>() { - public Object run() + public TimeZone run() { TimeZone zone = null; @@ -146,21 +146,21 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable /** * JDK 1.1.x compatibility aliases. */ - private static HashMap aliases0; + private static HashMap<String,String> aliases0; /** * HashMap for timezones by ID. */ - private static HashMap timezones0; + private static HashMap<String,TimeZone> timezones0; /* initialize this static field lazily to overhead if * it is not needed: */ // Package-private to avoid a trampoline. - static HashMap timezones() + static HashMap<String,TimeZone> timezones() { if (timezones0 == null) { - HashMap timezones = new HashMap(); + HashMap<String,TimeZone> timezones = new HashMap<String,TimeZone>(); timezones0 = timezones; zoneinfo_dir = SystemProperties.getProperty("gnu.java.util.zoneinfo.dir"); @@ -169,7 +169,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable if (zoneinfo_dir != null) { - aliases0 = new HashMap(); + aliases0 = new HashMap<String,String>(); // These deprecated aliases for JDK 1.1.x compatibility // should take precedence over data files read from @@ -1469,7 +1469,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable { synchronized (TimeZone.class) { - tz = (TimeZone) timezones().get(ID); + tz = timezones().get(ID); if (tz != null) { if (!tz.getID().equals(ID)) @@ -1497,7 +1497,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable // aliases0 is never changing after first timezones(), so should // be safe without synchronization. - String zonename = (String) aliases0.get(ID); + String zonename = aliases0.get(ID); if (zonename == null) zonename = ID; @@ -1605,17 +1605,17 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable { synchronized (TimeZone.class) { - HashMap h = timezones(); + HashMap<String,TimeZone> h = timezones(); int count = 0; if (zoneinfo_dir == null) { - Iterator iter = h.entrySet().iterator(); + Iterator<Map.Entry<String,TimeZone>> iter = h.entrySet().iterator(); while (iter.hasNext()) { // Don't iterate the values, since we want to count // doubled values (aliases) - Map.Entry entry = (Map.Entry) iter.next(); - if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset) + Map.Entry<String,TimeZone> entry = iter.next(); + if (entry.getValue().getRawOffset() == rawOffset) count++; } @@ -1624,8 +1624,8 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable iter = h.entrySet().iterator(); while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset) + Map.Entry<String,TimeZone> entry = iter.next(); + if (entry.getValue().getRawOffset() == rawOffset) ids[count++] = (String) entry.getKey(); } return ids; @@ -1651,7 +1651,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable return ids; } - private static int getAvailableIDs(File d, String prefix, ArrayList list) + private static int getAvailableIDs(File d, String prefix, ArrayList<String[]> list) { String[] files = d.list(); int count = files.length; @@ -1691,9 +1691,9 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable { synchronized (TimeZone.class) { - HashMap h = timezones(); + HashMap<String,TimeZone> h = timezones(); if (zoneinfo_dir == null) - return (String[]) h.keySet().toArray(new String[h.size()]); + return h.keySet().toArray(new String[h.size()]); if (availableIDs != null) { @@ -1704,7 +1704,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable } File d = new File(zoneinfo_dir); - ArrayList list = new ArrayList(30); + ArrayList<String[]> list = new ArrayList<String[]>(30); int count = getAvailableIDs(d, "", list) + aliases0.size(); availableIDs = new String[count]; String[] ids = new String[count]; @@ -1712,7 +1712,7 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable count = 0; for (int i = 0; i < list.size(); i++) { - String[] s = (String[]) list.get(i); + String[] s = list.get(i); for (int j = 0; j < s.length; j++) if (s[j] != null) { @@ -1721,12 +1721,12 @@ public abstract class TimeZone implements java.io.Serializable, Cloneable } } - Iterator iter = aliases0.entrySet().iterator(); + Iterator<Map.Entry<String,String>> iter = aliases0.entrySet().iterator(); while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - availableIDs[count] = (String) entry.getKey(); - ids[count++] = (String) entry.getKey(); + Map.Entry<String,String> entry = iter.next(); + availableIDs[count] = entry.getKey(); + ids[count++] = entry.getKey(); } return ids; diff --git a/libjava/classpath/java/util/regex/Matcher.java b/libjava/classpath/java/util/regex/Matcher.java index 8d033d5e316..95a35535935 100644 --- a/libjava/classpath/java/util/regex/Matcher.java +++ b/libjava/classpath/java/util/regex/Matcher.java @@ -103,6 +103,28 @@ public final class Matcher implements MatchResult } /** + * Changes the pattern used by the {@link Matcher} to + * the one specified. Existing match information is lost, + * but the input and the matcher's position within it is + * retained. + * + * @param newPattern the new pattern to use. + * @return this matcher. + * @throws IllegalArgumentException if {@code newPattern} is + * {@code null}. + * @since 1.5 + */ + public Matcher usePattern(Pattern newPattern) + { + if (newPattern == null) + throw new IllegalArgumentException("The new pattern was null."); + pattern = newPattern; + match = null; + + return this; + } + + /** * @param sb The target string buffer * @param replacement The replacement string * @@ -620,7 +642,7 @@ public final class Matcher implements MatchResult * * @param s the string to literalize. * @return the literalized string. - * @since 1.5 + * @since 1.5 */ public static String quoteReplacement(String s) { |