< prev index next >

src/java.desktop/share/classes/javax/swing/SizeSequence.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105  * and <code>removeEntries</code> methods, both
 106  * of which are implemented by converting the internal array to
 107  * a set of integer sizes, copying it into the new array, and then
 108  * reforming the hybrid representation in place.
 109  *
 110  * @author Philip Milne
 111  * @since 1.3
 112  */
 113 
 114 /*
 115  *   Each method is implemented by taking the minimum and
 116  *   maximum of the range of integers that need to be operated
 117  *   upon. All the algorithms work by dividing this range
 118  *   into two smaller ranges and recursing. The recursion
 119  *   is terminated when the upper and lower bounds are equal.
 120  */
 121 
 122 public class SizeSequence {
 123 
 124     private static int[] emptyArray = new int[0];
 125     private int a[];
 126 
 127     /**
 128      * Creates a new <code>SizeSequence</code> object
 129      * that contains no entries.  To add entries, you
 130      * can use <code>insertEntries</code> or <code>setSizes</code>.
 131      *
 132      * @see #insertEntries
 133      * @see #setSizes(int[])
 134      */
 135     public SizeSequence() {
 136         a = emptyArray;
 137     }
 138 
 139     /**
 140      * Creates a new <code>SizeSequence</code> object
 141      * that contains the specified number of entries,
 142      * all initialized to have size 0.
 143      *
 144      * @param numEntries  the number of sizes to track
 145      * @exception NegativeArraySizeException if


 343     }
 344 
 345     /**
 346      * Adds a contiguous group of entries to this <code>SizeSequence</code>.
 347      * Note that the values of <code>start</code> and
 348      * <code>length</code> must satisfy the following
 349      * conditions:  <code>(0 &lt;= start &lt; getSizes().length)
 350      * AND (length &gt;= 0)</code>.  If these conditions are
 351      * not met, the behavior is unspecified and an exception
 352      * may be thrown.
 353      *
 354      * @param start   the index to be assigned to the first entry
 355      *                in the group
 356      * @param length  the number of entries in the group
 357      * @param value   the size to be assigned to each new entry
 358      * @exception ArrayIndexOutOfBoundsException if the parameters
 359      *   are outside of the range:
 360      *   (<code>0 &lt;= start &lt; (getSizes().length)) AND (length &gt;= 0)</code>
 361      */
 362     public void insertEntries(int start, int length, int value) {
 363         int sizes[] = getSizes();
 364         int end = start + length;
 365         int n = a.length + length;
 366         a = new int[n];
 367         for (int i = 0; i < start; i++) {
 368             a[i] = sizes[i] ;
 369         }
 370         for (int i = start; i < end; i++) {
 371             a[i] = value ;
 372         }
 373         for (int i = end; i < n; i++) {
 374             a[i] = sizes[i-length] ;
 375         }
 376         setSizes(a);
 377     }
 378 
 379     /**
 380      * Removes a contiguous group of entries
 381      * from this <code>SizeSequence</code>.
 382      * Note that the values of <code>start</code> and
 383      * <code>length</code> must satisfy the following
 384      * conditions:  <code>(0 &lt;= start &lt; getSizes().length)
 385      * AND (length &gt;= 0)</code>.  If these conditions are
 386      * not met, the behavior is unspecified and an exception
 387      * may be thrown.
 388      *
 389      * @param start   the index of the first entry to be removed
 390      * @param length  the number of entries to be removed
 391      */
 392     public void removeEntries(int start, int length) {
 393         int sizes[] = getSizes();
 394         int end = start + length;
 395         int n = a.length - length;
 396         a = new int[n];
 397         for (int i = 0; i < start; i++) {
 398             a[i] = sizes[i] ;
 399         }
 400         for (int i = start; i < n; i++) {
 401             a[i] = sizes[i+length] ;
 402         }
 403         setSizes(a);
 404     }
 405 }
   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105  * and <code>removeEntries</code> methods, both
 106  * of which are implemented by converting the internal array to
 107  * a set of integer sizes, copying it into the new array, and then
 108  * reforming the hybrid representation in place.
 109  *
 110  * @author Philip Milne
 111  * @since 1.3
 112  */
 113 
 114 /*
 115  *   Each method is implemented by taking the minimum and
 116  *   maximum of the range of integers that need to be operated
 117  *   upon. All the algorithms work by dividing this range
 118  *   into two smaller ranges and recursing. The recursion
 119  *   is terminated when the upper and lower bounds are equal.
 120  */
 121 
 122 public class SizeSequence {
 123 
 124     private static int[] emptyArray = new int[0];
 125     private int[] a;
 126 
 127     /**
 128      * Creates a new <code>SizeSequence</code> object
 129      * that contains no entries.  To add entries, you
 130      * can use <code>insertEntries</code> or <code>setSizes</code>.
 131      *
 132      * @see #insertEntries
 133      * @see #setSizes(int[])
 134      */
 135     public SizeSequence() {
 136         a = emptyArray;
 137     }
 138 
 139     /**
 140      * Creates a new <code>SizeSequence</code> object
 141      * that contains the specified number of entries,
 142      * all initialized to have size 0.
 143      *
 144      * @param numEntries  the number of sizes to track
 145      * @exception NegativeArraySizeException if


 343     }
 344 
 345     /**
 346      * Adds a contiguous group of entries to this <code>SizeSequence</code>.
 347      * Note that the values of <code>start</code> and
 348      * <code>length</code> must satisfy the following
 349      * conditions:  <code>(0 &lt;= start &lt; getSizes().length)
 350      * AND (length &gt;= 0)</code>.  If these conditions are
 351      * not met, the behavior is unspecified and an exception
 352      * may be thrown.
 353      *
 354      * @param start   the index to be assigned to the first entry
 355      *                in the group
 356      * @param length  the number of entries in the group
 357      * @param value   the size to be assigned to each new entry
 358      * @exception ArrayIndexOutOfBoundsException if the parameters
 359      *   are outside of the range:
 360      *   (<code>0 &lt;= start &lt; (getSizes().length)) AND (length &gt;= 0)</code>
 361      */
 362     public void insertEntries(int start, int length, int value) {
 363         int[] sizes = getSizes();
 364         int end = start + length;
 365         int n = a.length + length;
 366         a = new int[n];
 367         for (int i = 0; i < start; i++) {
 368             a[i] = sizes[i] ;
 369         }
 370         for (int i = start; i < end; i++) {
 371             a[i] = value ;
 372         }
 373         for (int i = end; i < n; i++) {
 374             a[i] = sizes[i-length] ;
 375         }
 376         setSizes(a);
 377     }
 378 
 379     /**
 380      * Removes a contiguous group of entries
 381      * from this <code>SizeSequence</code>.
 382      * Note that the values of <code>start</code> and
 383      * <code>length</code> must satisfy the following
 384      * conditions:  <code>(0 &lt;= start &lt; getSizes().length)
 385      * AND (length &gt;= 0)</code>.  If these conditions are
 386      * not met, the behavior is unspecified and an exception
 387      * may be thrown.
 388      *
 389      * @param start   the index of the first entry to be removed
 390      * @param length  the number of entries to be removed
 391      */
 392     public void removeEntries(int start, int length) {
 393         int[] sizes = getSizes();
 394         int end = start + length;
 395         int n = a.length - length;
 396         a = new int[n];
 397         for (int i = 0; i < start; i++) {
 398             a[i] = sizes[i] ;
 399         }
 400         for (int i = start; i < n; i++) {
 401             a[i] = sizes[i+length] ;
 402         }
 403         setSizes(a);
 404     }
 405 }
< prev index next >