/*
* LingPipe v. 3.9
* Copyright (C) 2003-2010 Alias-i
*
* This program is licensed under the Alias-i Royalty Free License
* Version 1 WITHOUT ANY WARRANTY, without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Alias-i
* Royalty Free License Version 1 for more details.
*
* You should have received a copy of the Alias-i Royalty Free License
* Version 1 along with this program; if not, visit
* http://alias-i.com/lingpipe/licenses/lingpipe-license-1.txt or contact
* Alias-i, Inc. at 181 North 11th Street, Suite 401, Brooklyn, NY 11211,
* +1 (718) 290-9170.
*/
//package com.aliasi.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Static utility methods for processing arrays.
*
* @author Bob Carpenter
* @version 4.0.0
* @since LingPipe1.0
*/
public class Arrays {
/**
* Return the result of adding the specified character to the
* specified sorted character array. The original array will
* be returned if the character is in the array, otherwise a
* new array will be constructed and returned.
*
* Warning: No check is done that the incoming character
* array is in order.
*
* @param c Character to add.
* @param cs Array of characters in sorted order.
* @return The result of adding the character to the array in the
* correct order, returning a larger array if necessary.
*/
public static char[] add(char c, char[] cs) {
if (java.util.Arrays.binarySearch(cs,c) >= 0)
return cs;
char[] result = new char[cs.length+1];
int i = 0;
while (i < cs.length && c > cs[i]) {
result[i] = cs[i];
++i;
}
result[i] = c;
++i;
while (i < result.length) {
result[i] = cs[i-1];
++i;
}
return result;
}
}