com.ibm.commons.util.TStringVector Maven / Gradle / Ivy
The newest version!
/*
* © Copyright IBM Corp. 2012-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.ibm.commons.util;
import java.util.ArrayList;
/**
* This class is a vector of string.
* @ibm-non-published
*/
public class TStringVector extends ArrayList {
/**
*
*/
public TStringVector( int initialCapacity ) {
super(initialCapacity);
}
/**
*
*/
public TStringVector(boolean caseInsensitive) {
this.caseInsensitive = caseInsensitive;
}
/**
*
*/
public TStringVector() {
}
/**
*
*/
// public void setSize(int newSize, boolean initialize) {
// if( initialize ) {
// if( newSize>size ) {
// ensureCapacity(newSize);
// for(int i=size ; i=0;
}
/**
* Get the index of a specific string.
* The string are compared by value and not by the object pointer.
* @param item the string to look for
* @return the index of that string (-1 if it does'nt esist)
*/
public final int indexOf( Object item ) {
return indexOf( item, 0 );
}
/**
* Get the index of a specific string begining at a specific index.
* The string are compared by value and not by the object pointer.
* @param item the string to look for
* @param index the index where to start the search
* @return the index of that string (-1 if it does'nt esist)
*/
public final int indexOf( Object item, int index ) {
int size = size();
String s = (String)item;
if( caseInsensitive ) {
for( int i=index; i=0 ) {
super.remove(idx);
}
}
public final void removeElement( String item ) {
remove(item);
}
/**
*
*/
public final void removeAt( int index ) {
super.remove(index);
}
public final void removeElementAt( int index ) {
super.remove(index);
}
/**
*
*/
public final void removeItems( int index, int length ) {
if( length>=0 && index>=0 && index+length<=size() ) {
removeRange(index,index+length);
}
}
/**
*
*/
public final synchronized void sort() {
QuickSort qSort = new QuickSort.JavaList( this ) {
public int compare(Object o1, Object o2) {
return caseInsensitive ? o1.toString().compareToIgnoreCase(o2.toString())
: o1.toString().compareTo(o2.toString());
}
};
qSort.sort();
}
public final synchronized void sortIgnoreCase() {
QuickSort qSort = new QuickSort.JavaList( this ) {
public int compare(Object o1, Object o2) {
return o1.toString().compareToIgnoreCase(o2.toString());
}
};
qSort.sort();
}
/**
*
*/
public String getAsString() {
int size = size();
if(size>0) {
StringBuffer buffer = new StringBuffer();
for( int i=0; i0 ) {
buffer.append( ", " ); //$NON-NLS-1$
}
buffer.append( '\"' );
String s = getString(i);
for( int j=0; j': buffer.append( ">" ); break; //$NON-NLS-1$
default: buffer.append( c ); break;
}
}
buffer.append( '\"' );
}
return buffer.toString();
}
return null;
}
public String toString() {
return getAsString();
}
public Object[] toArray() {
return super.toArray( new String[size()] );
}
public String[] getElementArray() {
return (String[])toArray();
}
/*
*
*/
private boolean caseInsensitive;
}