< prev index next >

src/java.desktop/share/classes/java/awt/geom/Path2D.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -274,10 +274,22 @@
                 append(pi, false);
             }
         }
 
         @Override
+        public final Path2D trimToSize() {
+            // trim arrays:
+            if (numTypes < pointTypes.length) {
+                this.pointTypes = Arrays.copyOf(pointTypes, numTypes);
+            }
+            if (numCoords < floatCoords.length) {
+                this.floatCoords = Arrays.copyOf(floatCoords, numCoords);
+            }
+            return this;
+        }
+
+        @Override
         float[] cloneCoordsFloat(AffineTransform at) {
             // trim arrays:
             float ret[];
             if (at == null) {
                 ret = Arrays.copyOf(floatCoords, numCoords);

@@ -1143,10 +1155,22 @@
                 append(pi, false);
             }
         }
 
         @Override
+        public final Path2D trimToSize() {
+            // trim arrays:
+            if (numTypes < pointTypes.length) {
+                this.pointTypes = Arrays.copyOf(pointTypes, numTypes);
+            }
+            if (numCoords < doubleCoords.length) {
+                this.doubleCoords = Arrays.copyOf(doubleCoords, numCoords);
+            }
+            return this;
+        }
+
+        @Override
         float[] cloneCoordsFloat(AffineTransform at) {
             // trim arrays:
             float ret[] = new float[numCoords];
             if (at == null) {
                 for (int i = 0; i < numCoords; i++) {

@@ -2468,10 +2492,19 @@
         // but one of our subclasses (GeneralPath) needs to
         // offer "public Object clone()" for backwards
         // compatibility so we cannot restrict it further.
         // REMIND: Can we do both somehow?
 
+    /**
+     * Trims the capacity of this Path2D instance to its current
+     * size. An application can use this operation to minimize the
+     * storage of a path.
+     * @return this Path2D instance
+     * @Since 10
+     */
+    public abstract Path2D trimToSize();
+
     /*
      * Support fields and methods for serializing the subclasses.
      */
     private static final byte SERIAL_STORAGE_FLT_ARRAY = 0x30;
     private static final byte SERIAL_STORAGE_DBL_ARRAY = 0x31;
< prev index next >