下面列出了java.util.Vector#insertElementAt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Collection getCourseNbrs(int idx) {
Vector ret = new Vector();
boolean contains = false;
if (getSubjectArea(idx)>=0) {
for (Iterator i= new CourseOfferingDAO().
getSession().
createQuery("select co.uniqueId, co.courseNbr, co.title from CourseOffering co "+
"where co.subjectArea.uniqueId = :subjectAreaId "+
"and co.instructionalOffering.notOffered = false "+
"order by co.courseNbr ").
setFetchSize(200).
setCacheable(true).
setLong("subjectAreaId", getSubjectArea(idx)).iterate();i.hasNext();) {
Object[] o = (Object[])i.next();
ret.add(new IdValue((Long)o[0],((String)o[1] + " - " + (String)o[2])));
if (o[0].equals(getCourseNbr(idx))) contains = true;
}
}
if (!contains) setCourseNbr(idx, -1L);
if (ret.size()==1) setCourseNbr(idx, ((IdValue)ret.firstElement()).getId());
else ret.insertElementAt(new IdValue(-1L,"-"), 0);
return ret;
}
/**
* This method fixes bug #3275: "SearchEngineFriendlyURLFilter may sometimes match a request to the wrong alias" This method will also ignore duplicates, and strip off unwanted whitespace
*
* @param mappings
* @param aliasToAdd
*/
private static void addAlias(Vector<String> mappings, String aliasToAdd) {
int size = mappings.size();
int i = 0;
aliasToAdd = aliasToAdd.trim();
for (; i < size; i++) {
String storedAlias = mappings.elementAt(i);
if (aliasToAdd.length() > storedAlias.length()) {
mappings.insertElementAt(aliasToAdd, i);
return;
} else if (aliasToAdd.equals(storedAlias))
// The aliases are the same so do nothing
return;
}
// The alias wasn't inserted so place it at the end
if (i == size)
mappings.addElement(aliasToAdd);
}
private Vector getOrderedDescriptions(String repositoryID,
com.sun.org.omg.SendingContext.CodeBase sender) {
Vector descs = new Vector();
if (sender == null) {
return descs;
}
FullValueDescription aFVD = sender.meta(repositoryID);
while (aFVD != null) {
descs.insertElementAt(aFVD, 0);
if ((aFVD.base_value != null) && !kEmptyStr.equals(aFVD.base_value)) {
aFVD = sender.meta(aFVD.base_value);
}
else return descs;
}
return descs;
}
private Vector getOrderedDescriptions(String repositoryID,
com.sun.org.omg.SendingContext.CodeBase sender) {
Vector descs = new Vector();
if (sender == null) {
return descs;
}
FullValueDescription aFVD = sender.meta(repositoryID);
while (aFVD != null) {
descs.insertElementAt(aFVD, 0);
if ((aFVD.base_value != null) && !kEmptyStr.equals(aFVD.base_value)) {
aFVD = sender.meta(aFVD.base_value);
}
else return descs;
}
return descs;
}
private Vector testLastAndPrevious(BreakIterator bi, String text) {
int p = bi.last();
int lastP = p;
Vector<String> result = new Vector<String>();
if (p != text.length())
errln("last() returned " + p + " instead of " + text.length());
while (p != BreakIterator.DONE) {
p = bi.previous();
if (p != BreakIterator.DONE) {
if (p >= lastP)
errln("previous() failed to move backward: previous() on position "
+ lastP + " yielded " + p);
result.insertElementAt(text.substring(p, lastP), 0);
}
else {
if (lastP != 0)
errln("previous() returned DONE prematurely: offset was "
+ lastP + " instead of 0");
}
lastP = p;
}
return result;
}
private Vector testLastAndPrevious(BreakIterator bi, String text) {
int p = bi.last();
int lastP = p;
Vector<String> result = new Vector<String>();
if (p != text.length())
errln("last() returned " + p + " instead of " + text.length());
while (p != BreakIterator.DONE) {
p = bi.previous();
if (p != BreakIterator.DONE) {
if (p >= lastP)
errln("previous() failed to move backward: previous() on position "
+ lastP + " yielded " + p);
result.insertElementAt(text.substring(p, lastP), 0);
}
else {
if (lastP != 0)
errln("previous() returned DONE prematurely: offset was "
+ lastP + " instead of 0");
}
lastP = p;
}
return result;
}
private Vector getOrderedDescriptions(String repositoryID,
com.sun.org.omg.SendingContext.CodeBase sender) {
Vector descs = new Vector();
if (sender == null) {
return descs;
}
FullValueDescription aFVD = sender.meta(repositoryID);
while (aFVD != null) {
descs.insertElementAt(aFVD, 0);
if ((aFVD.base_value != null) && !kEmptyStr.equals(aFVD.base_value)) {
aFVD = sender.meta(aFVD.base_value);
}
else return descs;
}
return descs;
}
private static final void prefillLists(LuaTable t,Vector v) {
for ( int i = 1; i <= 32; ++i ) {
LuaString test = LuaValue.valueOf("Test Value! "+i);
t.insert(0, test);
v.insertElementAt(test, v.size());
}
}
public Vector sortKeyListAlpha()
{
Vector v = new Vector();
for(int count = 0; count < keyList.size(); count++)
{
String s = (String)keyList.elementAt(count);
int i = 0;
for (i = 0; i < v.size(); i++)
{
int c = s.compareTo((String) v.elementAt(i));
if (c < 0)
{
v.insertElementAt(s, i);
break;
}
else
if (c == 0)
break;
}
if (i >= v.size())
v.addElement(s);
}
keyList = v;
return v;
}
public Collection getClassNumbers(int idx) {
Vector ret = new Vector();
boolean contains = false;
SchedulingSubpart subpart = (getItype(idx)>0?new SchedulingSubpartDAO().get(getItype(idx)):null);
CourseOffering co = (getItype(idx)>0?new CourseOfferingDAO().get(getCourseNbr(idx)):null);
if (subpart!=null) {
TreeSet classes = new TreeSet(new ClassComparator(ClassComparator.COMPARE_BY_HIERARCHY));
classes.addAll(new Class_DAO().
getSession().
createQuery("select distinct c from Class_ c "+
"where c.schedulingSubpart.uniqueId=:schedulingSubpartId").
setFetchSize(200).
setCacheable(true).
setLong("schedulingSubpartId", getItype(idx)).
list());
for (Iterator i=classes.iterator();i.hasNext();) {
Class_ c = (Class_)i.next();
if (c.getUniqueId().equals(getClassNumber(idx))) contains = true;
String extId = c.getClassSuffix(co);
ret.add(new IdValue(c.getUniqueId(), c.getSectionNumberString() +
(extId == null || extId.isEmpty() || extId.equalsIgnoreCase(c.getSectionNumberString()) ? "" : " - " + extId)));
}
}
if (ret.isEmpty()) ret.add(new IdValue(-1L,"N/A"));
if (!contains) setClassNumber(idx, -1L);
if (ret.size()==1) setClassNumber(idx, ((IdValue)ret.firstElement()).getId());
else ret.insertElementAt(new IdValue(-1L,"-"), 0);
return ret;
}
public void testInsertBeginningOfList() {
LuaTable t = new_Table();
Vector v = new Vector();
for ( int i = 1; i <= 32; ++i ) {
LuaString test = LuaValue.valueOf("Test Value! "+i);
t.insert(1, test);
v.insertElementAt(test, 0);
compareLists(t,v);
}
}
/**
* Return the IDL module nesting of the given Type.
* For IDLEntity CompoundTypes (or their arrays) apply any user specified
* -idlModule translation or, if none applicable, strip any package
* prefix.
* Add boxedIDL or boxedRMI modules if required.
* @param t Given Type
* @return Array containing the original module nesting.
*/
protected String[] getIDLModuleNames(Type t) {
String[] modNames = t.getIDLModuleNames(); //default module name array
CompoundType ct;
if ( t.isCompound() ) {
ct = (CompoundType)t;
if ( !ct.isIDLEntity ) return modNames; //normal (non-IDLEntity) case
if ( "org.omg.CORBA.portable.IDLEntity"
.equals( t.getQualifiedName() ) )
return modNames;
}
else if ( t.isArray() ) {
Type et = t.getElementType();
if ( et.isCompound() ) {
ct = (CompoundType)et;
if ( !ct.isIDLEntity ) return modNames; //normal (non-IDLEntity) case
if ( "org.omg.CORBA.portable.IDLEntity"
.equals( t.getQualifiedName() ) )
return modNames;
}
else return modNames;
}
else return modNames; //no preprocessing needed for primitives
//it's an IDLEntity or an array of...
Vector mVec = new Vector();
if ( !translateJavaPackage( ct,mVec ) ) //apply -idlModule translation
stripJavaPackage( ct,mVec ); //..or strip prefixes (not both)
if ( ct.isBoxed() ) { //add boxedIDL if required
mVec.insertElementAt( "org",0 );
mVec.insertElementAt( "omg",1 );
mVec.insertElementAt( "boxedIDL",2 );
}
if ( t.isArray() ) { //add boxedRMI if required
mVec.insertElementAt( "org",0 );
mVec.insertElementAt( "omg",1 );
mVec.insertElementAt( "boxedRMI",2 );
}
String[] outArr = new String[mVec.size()];
mVec.copyInto( outArr );
return outArr;
}
@Override
public void run() {
if (myClasses.length == 1) {
//TODO: cdr this place should produce at least warning
// selected(myClasses[0]);
selected((T[])ArrayUtil.toObjectArray(myClasses[0].getClass(), myClasses[0]));
}
else if (myClasses.length > 0) {
PsiElementListCellRenderer<T> renderer = createRenderer();
Arrays.sort(myClasses, renderer.getComparator());
if (ApplicationManager.getApplication().isUnitTestMode()) {
selected(myClasses);
return;
}
Vector<Object> model = new Vector<Object>(Arrays.asList(myClasses));
model.insertElementAt(CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"), 0);
myList = new JBList(model);
myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myList.setCellRenderer(renderer);
final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
renderer.installSpeedSearch(builder);
final Runnable callback = new Runnable() {
@Override
public void run() {
int idx = myList.getSelectedIndex();
if (idx < 0) return;
if (idx > 0) {
selected((T[])ArrayUtil.toObjectArray(myClasses[idx-1].getClass(), myClasses[idx-1]));
}
else {
selected(myClasses);
}
}
};
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
builder.
setTitle(myTitle).
setItemChoosenCallback(callback).
createPopup().
showInBestPositionFor(myEditor);
}
});
}
}
/**
* Apply user specified -idlModule translation to package names of given
* IDLEntity ct. Example:
* -idlModule foo.bar real::mod::nesting
* @param ct CompoundType containing given IDLEntity.
* @param vec Returned Vector of translated IDL module names.
* @return boolean true if any translation was done.
*/
protected boolean translateJavaPackage(
CompoundType ct,
Vector vec ) {
vec.removeAllElements();
boolean ret = false;
String fc = null;
if ( ! ct.isIDLEntity() ) return ret;
String pName = ct.getPackageName(); //start from Java package names
if ( pName == null ) return ret;
StringTokenizer pt = new StringTokenizer( pName,"." );
while ( pt.hasMoreTokens() ) vec.addElement( pt.nextToken() );
if ( imHash.size() > 0 ) { //any -idlModule translation to apply?
Enumeration k = imHash.keys();
nextModule:
while ( k.hasMoreElements() ) { //loop thro user-defined -idlModules
String from = (String)k.nextElement(); //from String..
StringTokenizer ft = new StringTokenizer( from,"." );
int vecLen = vec.size();
int ifr;
for ( ifr = 0; ifr < vecLen && ft.hasMoreTokens(); ifr++ )
if ( ! vec.elementAt(ifr).equals( ft.nextToken() ) )
continue nextModule; //..no match
if ( ft.hasMoreTokens() ) { //matched so far..
fc = ft.nextToken(); //a 'from' token remains
if ( ! ct.getName().equals( fc ) || //matches class name?
ft.hasMoreTokens() )
continue nextModule; //..no match
}
ret = true; //found a match
for ( int i4 = 0; i4 < ifr; i4++ )
vec.removeElementAt( 0 ); //remove 'from' package
String to = (String)imHash.get( from ); //..to String
StringTokenizer tt = new StringTokenizer( to,IDL_NAME_SEPARATOR );
int itoco = tt.countTokens();
int ito = 0;
if ( fc != null ) itoco--; //user may have given IDL type
for ( ito = 0; ito < itoco; ito++ )
vec.insertElementAt( tt.nextToken(),ito ); //insert 'to' modules
if ( fc != null ) {
String tc = tt.nextToken();
if ( ! ct.getName().equals( tc ) ) //not the IDL type, so..
vec.insertElementAt( tc,ito ); //insert final 'to' module
}
}
}
return ret;
}
/**
* Performs a deep add of the contents of the specified <code>ArgArray</code>.
* Existing ArgArrays are not replaced but are instead 'augmented' with
* values from <code>newStuff</code>. Scalar values are replaced. When
* adding a <code>Vector</code> at places where a <code>Vector</code>
* already exists, the behaviour is controlled by the <code>vectorMode</code>
* argument to allow one of error, replace, insert, or append.
*
* @param newStuff - the <code>ArgArray</code> contents to add.
* @param vectorMode - One of MODE_REPLACE, VECTOR_MODE_INSERT,
* VECTOR_MODE_APPEND, VECTOR_MODE_ERROR to control how vectors are added to
* existing vectors.
*/
public void deepAdd ( ArgArray newStuff , int vectorMode ) {
for ( Enumeration e = newStuff.contents.keys( ) ; e.hasMoreElements( ) ; ) {
String key = ( String ) e.nextElement( );
Object val = newStuff.contents.get( key );
if ( val instanceof ArgArray ) {
if ( !containsKey( key ) ) {
put( key , new ArgArray( ) );
}
ArgArray inner = getArgArray( key );
inner.deepAdd( ( ArgArray ) val );
} else if ( val instanceof Vector ) {
Vector newVal = deepCloneVector( ( Vector ) val );
if ( !containsKey( key ) || vectorMode == MODE_REPLACE ) {
put( key , newVal );
} else {
Vector oldVector = getVector( key );
switch ( vectorMode ) {
case VECTOR_MODE_INSERT :
for ( int i = newVal.size( ) ; i > 0 ; i-- ) {
oldVector.insertElementAt( newVal.elementAt( i - 1 ) , 0 );
}
break;
case VECTOR_MODE_APPEND :
for ( int i = 0 ; i < newVal.size( ) ; i++ ) {
oldVector.addElement( newVal.elementAt( i ) );
}
break;
case VECTOR_MODE_ERROR :
throw ( new RuntimeException( "Vector element already exists for " + key ) );
default :
throw ( new RuntimeException( "Unrecognized mode in ArgArray.deepAdd for key=" + key ) );
}
}
} else {
put( key , val );
}
}
}
/**
* Takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or
* some such, converting it into an ordered set of name attributes. lookUp
* should provide a table of lookups, indexed by lowercase only strings and
* yielding a DERObjectIdentifier, other than that OID. and numeric oids
* will be processed automatically. The passed in converter is used to convert the
* string values to the right of each equals sign to their ASN.1 counterparts.
* <br>
* @param reverse true if we should start scanning from the end, false otherwise.
* @param lookUp table of names and oids.
* @param dirName the string dirName
* @param converter the converter to convert string values into their ASN.1 equivalents
*/
public X509Name(
boolean reverse,
Hashtable lookUp,
String dirName,
X509NameEntryConverter converter)
{
this.converter = converter;
X509NameTokenizer nTok = new X509NameTokenizer(dirName);
while (nTok.hasMoreTokens())
{
String token = nTok.nextToken();
int index = token.indexOf('=');
if (index == -1)
{
throw new IllegalArgumentException("badly formated directory string");
}
String name = token.substring(0, index);
String value = token.substring(index + 1);
DERObjectIdentifier oid = decodeOID(name, lookUp);
if (value.indexOf('+') > 0)
{
X509NameTokenizer vTok = new X509NameTokenizer(value, '+');
this.ordering.addElement(oid);
this.values.addElement(vTok.nextToken());
this.added.addElement(FALSE);
while (vTok.hasMoreTokens())
{
String sv = vTok.nextToken();
int ndx = sv.indexOf('=');
String nm = sv.substring(0, ndx);
String vl = sv.substring(ndx + 1);
this.ordering.addElement(decodeOID(nm, lookUp));
this.values.addElement(vl);
this.added.addElement(TRUE);
}
}
else
{
this.ordering.addElement(oid);
this.values.addElement(value);
this.added.addElement(FALSE);
}
}
if (reverse)
{
Vector o = new Vector();
Vector v = new Vector();
Vector a = new Vector();
int count = 1;
for (int i = 0; i < this.ordering.size(); i++)
{
if (((Boolean)this.added.elementAt(i)).booleanValue())
{
o.insertElementAt(this.ordering.elementAt(i), count);
v.insertElementAt(this.values.elementAt(i), count);
a.insertElementAt(this.added.elementAt(i), count);
count++;
}
else
{
o.insertElementAt(this.ordering.elementAt(i), 0);
v.insertElementAt(this.values.elementAt(i), 0);
a.insertElementAt(this.added.elementAt(i), 0);
count = 1;
}
}
this.ordering = o;
this.values = v;
this.added = a;
}
}
/**
* Gets the path of sites back to the root of the tree.
* @param s
* @param ourParent
* @return
*/
private List<Site> getPwd(Site s, String ourParent)
{
if (ourParent == null) return null;
log.debug("Getting Current Working Directory for {} {}", s.getId(), s.getTitle());
int depth = 0;
Vector<Site> pwd = new Vector<Site>();
Set<String> added = new HashSet<String>();
// Add us to the list at the top (will become the end)
pwd.add(s);
added.add(s.getId());
// Make sure we don't go on forever
while (ourParent != null && depth < 8)
{
depth++;
Site site = null;
try
{
site = SiteService.getSiteVisit(ourParent);
}
catch (Exception e)
{
break;
}
// We have no patience with loops
if (added.contains(site.getId())) break;
log.debug("Adding Parent {} {}", site.getId(), site.getTitle());
pwd.insertElementAt(site, 0); // Push down stack
added.add(site.getId());
ResourceProperties rp = site.getProperties();
ourParent = rp.getProperty(PROP_PARENT_ID);
}
// PWD is only defined for > 1 site
if (pwd.size() < 2) return null;
return pwd;
}
/**
* Adds a pattern to a pattern group
*/
private void addPattern(int kernelType, LocationPathPattern pattern) {
// Make sure the array of pattern groups is long enough
final int oldLength = _patternGroups.length;
if (kernelType >= oldLength) {
Vector[] newGroups = new Vector[kernelType * 2];
System.arraycopy(_patternGroups, 0, newGroups, 0, oldLength);
_patternGroups = newGroups;
}
// Find the vector to put this pattern into
Vector patterns;
if (kernelType == DOM.NO_TYPE) {
if (pattern.getAxis() == Axis.ATTRIBUTE) {
patterns = (_attribNodeGroup == null) ?
(_attribNodeGroup = new Vector(2)) : _attribNodeGroup;
}
else {
patterns = (_childNodeGroup == null) ?
(_childNodeGroup = new Vector(2)) : _childNodeGroup;
}
}
else {
patterns = (_patternGroups[kernelType] == null) ?
(_patternGroups[kernelType] = new Vector(2)) :
_patternGroups[kernelType];
}
if (patterns.size() == 0) {
patterns.addElement(pattern);
}
else {
boolean inserted = false;
for (int i = 0; i < patterns.size(); i++) {
final LocationPathPattern lppToCompare =
(LocationPathPattern)patterns.elementAt(i);
if (pattern.noSmallerThan(lppToCompare)) {
inserted = true;
patterns.insertElementAt(pattern, i);
break;
}
}
if (inserted == false) {
patterns.addElement(pattern);
}
}
}
/**
* Adds a pattern to a pattern group
*/
private void addPattern(int kernelType, LocationPathPattern pattern) {
// Make sure the array of pattern groups is long enough
final int oldLength = _patternGroups.length;
if (kernelType >= oldLength) {
Vector[] newGroups = new Vector[kernelType * 2];
System.arraycopy(_patternGroups, 0, newGroups, 0, oldLength);
_patternGroups = newGroups;
}
// Find the vector to put this pattern into
Vector patterns;
if (kernelType == DOM.NO_TYPE) {
if (pattern.getAxis() == Axis.ATTRIBUTE) {
patterns = (_attribNodeGroup == null) ?
(_attribNodeGroup = new Vector(2)) : _attribNodeGroup;
}
else {
patterns = (_childNodeGroup == null) ?
(_childNodeGroup = new Vector(2)) : _childNodeGroup;
}
}
else {
patterns = (_patternGroups[kernelType] == null) ?
(_patternGroups[kernelType] = new Vector(2)) :
_patternGroups[kernelType];
}
if (patterns.size() == 0) {
patterns.addElement(pattern);
}
else {
boolean inserted = false;
for (int i = 0; i < patterns.size(); i++) {
final LocationPathPattern lppToCompare =
(LocationPathPattern)patterns.elementAt(i);
if (pattern.noSmallerThan(lppToCompare)) {
inserted = true;
patterns.insertElementAt(pattern, i);
break;
}
}
if (inserted == false) {
patterns.addElement(pattern);
}
}
}
/**
* Adds a pattern to a pattern group
*/
private void addPattern(int kernelType, LocationPathPattern pattern) {
// Make sure the array of pattern groups is long enough
final int oldLength = _patternGroups.length;
if (kernelType >= oldLength) {
Vector[] newGroups = new Vector[kernelType * 2];
System.arraycopy(_patternGroups, 0, newGroups, 0, oldLength);
_patternGroups = newGroups;
}
// Find the vector to put this pattern into
Vector patterns;
if (kernelType == DOM.NO_TYPE) {
if (pattern.getAxis() == Axis.ATTRIBUTE) {
patterns = (_attribNodeGroup == null) ?
(_attribNodeGroup = new Vector(2)) : _attribNodeGroup;
}
else {
patterns = (_childNodeGroup == null) ?
(_childNodeGroup = new Vector(2)) : _childNodeGroup;
}
}
else {
patterns = (_patternGroups[kernelType] == null) ?
(_patternGroups[kernelType] = new Vector(2)) :
_patternGroups[kernelType];
}
if (patterns.size() == 0) {
patterns.addElement(pattern);
}
else {
boolean inserted = false;
for (int i = 0; i < patterns.size(); i++) {
final LocationPathPattern lppToCompare =
(LocationPathPattern)patterns.elementAt(i);
if (pattern.noSmallerThan(lppToCompare)) {
inserted = true;
patterns.insertElementAt(pattern, i);
break;
}
}
if (inserted == false) {
patterns.addElement(pattern);
}
}
}