1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-16 21:45:22 +02:00

[174776] applying Kevin's and Dave D's patch

This commit is contained in:
David McKnight 2007-05-31 00:32:20 +00:00
parent 72ff786459
commit 3f1720b18f

View file

@ -11,7 +11,9 @@
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
* *
* Contributors: * Contributors:
* {Name} (company) - description of contribution. * David Dykstal (IBM) - generalized Vector argumnents to Collections
* Kevin Doyle (IBM) - 174776: perform required sorting of Collection arguments
* David Dykstal (IBM) - 174776: disallowed sorting of input arguments, used copies
********************************************************************************/ ********************************************************************************/
package org.eclipse.rse.ui.validators; package org.eclipse.rse.ui.validators;
@ -40,6 +42,8 @@ public class ValidatorUniqueString
public static final boolean CASE_SENSITIVE = true; public static final boolean CASE_SENSITIVE = true;
public static final boolean CASE_INSENSITIVE = false; public static final boolean CASE_INSENSITIVE = false;
public static final char QUOTE = '\"'; public static final char QUOTE = '\"';
private static final String[] EMPTY_LIST = new String[0];
protected ISystemValidator syntaxValidator; protected ISystemValidator syntaxValidator;
protected boolean caseSensitive; protected boolean caseSensitive;
protected boolean useUpperCase; protected boolean useUpperCase;
@ -132,6 +136,7 @@ public class ValidatorUniqueString
{ {
existingList = new String[newList.size()]; existingList = new String[newList.size()];
newList.toArray(existingList); newList.toArray(existingList);
init(existingList, caseSensitive);
} }
} }
/** /**
@ -156,27 +161,26 @@ public class ValidatorUniqueString
/** /**
* Initialize sorted array. * Initialize sorted array.
*/ */
private void init(String existingList[], boolean caseSensitive) private void init(String names[], boolean caseSensitive) {
{ if (names == null) {
this.existingList = existingList; existingList = EMPTY_LIST;
if (existingList == null) } else {
return; existingList = new String[names.length];
if (!caseSensitive) // speed up comparison by converting to all lowercase System.arraycopy(names, 0, existingList, 0, names.length);
{ // TODO (dwd 20070530) this should be using ICU4J to fold case.
String newList[] = new String[existingList.length]; if (!caseSensitive) { // speed up comparison by converting to all lowercase
for (int idx=0; idx<existingList.length; idx++) for (int idx = 0; idx < existingList.length; idx++) {
{ String string = existingList[idx];
String string = existingList[idx]; boolean quoted = (string.indexOf(QUOTE) != -1);
boolean quoted = (string.indexOf(QUOTE) != -1); if (!quoted) {
if (!quoted) existingList[idx] = string.toLowerCase();
newList[idx] = string.toLowerCase(); } else {
else existingList[idx] = quotedToLowerCase(string);
newList[idx] = quotedToLowerCase(string); }
} }
existingList = newList; }
Arrays.sort(existingList); // Arrays is a utility class in java.util. New in JDK 1.2
} }
Arrays.sort(existingList); // Arrays is a utility class in java.util. New in JDK 1.2
this.existingList = existingList;
} }
/** /**