home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / jfc.bin / Segment.java < prev    next >
Text File  |  1998-02-26  |  2KB  |  85 lines

  1. /*
  2.  * @(#)Segment.java    1.6 97/12/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.text;
  21.  
  22. /**
  23.  * A segment of a character array representing a fragment
  24.  * of text.  It should be treated as immutable even though
  25.  * the array is directly accessable.  This gives fast access
  26.  * to fragments of text without the overhead of copying
  27.  * around characters.  This is effectively an unprotected
  28.  * String.
  29.  */
  30. public class Segment {
  31.  
  32.     /**
  33.      * This is the array containing the text of
  34.      * interest.  This array should never be modified;
  35.      * it is available only for efficiency.
  36.      */
  37.     public char[] array;
  38.  
  39.     /**
  40.      * This is the offset into the array that
  41.      * the desired text begins.
  42.      */
  43.     public int offset;
  44.  
  45.     /**
  46.      * This is the number of array elements that
  47.      * make up the text of interest.
  48.      */
  49.     public int count;
  50.  
  51.     /**
  52.      * Creates a new segment.
  53.      */
  54.     public Segment() {
  55.     array = null;
  56.     offset = 0;
  57.     count = 0;
  58.     }
  59.  
  60.     /**
  61.      * Creates a new segment referring to an existing array.
  62.      *
  63.      * @param array the array to refer to
  64.      * @param offset the offset into the array
  65.      * @param count the number of characters
  66.      */
  67.     public Segment(char[] array, int offset, int count) {
  68.     this.array = array;
  69.     this.offset = offset;
  70.     this.count = count;
  71.     }
  72.  
  73.     /**
  74.      * Converts a segment into a String.
  75.      *
  76.      * @return the string
  77.      */
  78.     public String toString() {
  79.     return new String(array, offset, count);
  80.     }
  81.  
  82. }
  83.  
  84.  
  85.