Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011 The Kuali Foundation Licensed under the Educational Community 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.osedu.org/licenses/ECL-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 org.kuali.common.impex.model.util;
 
 import java.util.List;
 import java.util.Map;
 
 
 public class ModelUtils {
 
 	public static List<StringgetPrimaryKeyColumnNames(Table t) {
 		List<Stringnames = new ArrayList<String>();
 		for (Column col : CollectionUtils.toEmptyList(t.getColumns())) {
 			if (col.isPrimaryKey()) {
 				names.add(col.getName());
 			}
 		}
 
 		return names;
 	}
 
 	public static String getCsvPrimaryKeyColumnNames(Table t) {
 
 		if (names.isEmpty()) {
 			return "";
 		} else {
 			return CollectionUtils.getCSV(names);
 		}
 	}
 
 	public static Map<StringColumngetColumnNameMap(Table t) {
 		Map<StringColumnresult = new HashMap<StringColumn>();
 
 		for (Column c : t.getColumns()) {
 			result.put(c.getName(), c);
 		}
 
 		return result;
 	}
 
 	public static String getCsvColumnNames(List<Columncolumns) {
 		List<Stringnames = new ArrayList<String>(columns.size());
 		for (Column col : CollectionUtils.toEmptyList(columns)) {
 			names.add(col.getName());
 		}
 
 		return CollectionUtils.getCSV(names);
 	}
 
 	public static <T extends NamedElementMap<String, T> buildNameMap(List<T> namedElements) {
 		Map<String, T> results = new HashMap<String, T>(namedElements.size());
 
 		for (T n : namedElements) {
 			results.put(n.getName(), n);
 		}
 
 		return results;
 	}

Alter the List passed in by removing any elements that don't belong and then sorting the ones that remain by name
 
 	public static <T extends NamedElementvoid filterAndSortElements(List<T> elementsStringFilter filter) {
 
 		// Remove elements that don't belong
 		filterElements(elementsfilter);
 
 		// Sort the elements by name
 		Collections.sort(elements, NamedElementComparator.getInstance());
 	}

Remove elements from the list that should not be there
 
 	public static <T extends NamedElementvoid filterElements(List<T> elementsStringFilter filter) {
		// Make sure we are configured correctly
		Assert.notNull(elements"elements is null");
		// Iterate over the elements, removing elements that shouldn't be there
		Iterator<T> itr = elements.iterator();
		while (itr.hasNext()) {
			NamedElement element = itr.next();
			String name = element.getName();
			if (isExcluded(namefilter)) {
				itr.remove();
			}
		}
	}

Return true only if we've been provided a filter and s is excluded by that filter
	public static boolean isExcluded(String sStringFilter filter) {
		return filter != null && filter.exclude(s);
	}
New to GrepCode? Check out our FAQ X