2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.lucene.analysis.compound.hyphenation;
20 import java.io.Serializable;
23 * This class implements a simple char vector with access to the underlying
26 * This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
28 public class CharVector implements Cloneable, Serializable {
31 * Capacity increment size
33 private static final int DEFAULT_BLOCK_SIZE = 2048;
35 private int blockSize;
38 * The encapsulated array
43 * Points to next free item
48 this(DEFAULT_BLOCK_SIZE);
51 public CharVector(int capacity) {
55 blockSize = DEFAULT_BLOCK_SIZE;
57 array = new char[blockSize];
61 public CharVector(char[] a) {
62 blockSize = DEFAULT_BLOCK_SIZE;
67 public CharVector(char[] a, int capacity) {
71 blockSize = DEFAULT_BLOCK_SIZE;
78 * Reset Vector but don't resize or clear elements
85 public Object clone() {
86 CharVector cv = new CharVector(array.clone(), blockSize);
91 public char[] getArray() {
96 * return number of items in array
103 * returns current capacity of array
105 public int capacity() {
109 public void put(int index, char val) {
113 public char get(int index) {
117 public int alloc(int size) {
119 int len = array.length;
120 if (n + size >= len) {
121 char[] aux = new char[len + blockSize];
122 System.arraycopy(array, 0, aux, 0, len);
129 public void trimToSize() {
130 if (n < array.length) {
131 char[] aux = new char[n];
132 System.arraycopy(array, 0, aux, 0, n);