From: <pat...@us...> - 2009-07-20 18:44:53
|
Revision: 891 http://cishell.svn.sourceforge.net/cishell/?rev=891&view=rev Author: pataphil Date: 2009-07-20 18:44:49 +0000 (Mon, 20 Jul 2009) Log Message: ----------- * "Merged" TableUtilities with changes made to edu.iu.scipolicy.utilities before Utilities were moved to CIShell. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-07-17 22:02:42 UTC (rev 890) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/TableUtilities.java 2009-07-20 18:44:49 UTC (rev 891) @@ -66,6 +66,59 @@ } } + public static String formNonConflictingNewColumnName( + Schema schema, String[] suggestedColumnNames) + throws ColumnNotFoundException { + List workingColumnNames = getAllColumnNames(schema); + + boolean suggestedNameFound = false; + for(int suggestedNameIndex = 0; suggestedNameIndex < suggestedColumnNames.length; suggestedNameIndex++) { + for(int i = 0; i < workingColumnNames.size(); i++) { + if(workingColumnNames.get(i).toString().equalsIgnoreCase(suggestedColumnNames[suggestedNameIndex])) { + suggestedNameFound = true; + break; + } + } + /* + * To ensure that whenever a suggested name is found in the original column schema, create a name. + * */ + if(suggestedNameFound) { + break; + } + } + + /* + * If none of the suggested names are conflicting then return the first suggested name. + * */ + if(!suggestedNameFound) { + return suggestedColumnNames[0]; + } + + /* + * This part of code will be executed only if the suggested names are already present in the + * column schema. + * */ + boolean newColumnNameFound = false; + int columnNameSuffix = 2; + while(true) { + /* + * The pattern for new names will be taken from the first suggested column name. + * */ + String newColumnName = + suggestedColumnNames[0].concat("_" + columnNameSuffix); + for(int i = 0; i < workingColumnNames.size(); i++) { + if(workingColumnNames.get(i).toString().equalsIgnoreCase(newColumnName)) { + newColumnNameFound = true; + break; + } + } + if(!newColumnNameFound) { + return newColumnName; + } + columnNameSuffix++; + } + } + public static String[] filterSchemaColumnNamesByClasses (Schema schema, Class[] objectClasses) throws ColumnNotFoundException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |