Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2010-2014 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.opensource.org/licenses/ecl2.php
*
* 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.util;
import static com.google.common.collect.Lists.newArrayList;
import static org.apache.commons.lang3.StringUtils.isBlank;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.kuali.common.util.nullify.NullUtils;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
public class CollectionUtils {
private enum BlanksFilter implements Predicate {
INSTANCE;
@Override
public boolean apply(String input) {
return isBlank(input);
}
}
public static boolean hasBlanks(Collection collection) {
return !getBlanks(collection).isEmpty();
}
public static Collection getBlanks(Collection collection) {
return newArrayList(Iterables.filter(collection, BlanksFilter.INSTANCE));
}
/**
* Returns a new unmodifiable list containing the elements from list
*
* @deprecated See ListUtils.newArrayList() instead
*/
@Deprecated
public static List unmodifiableCopy(List list) {
return Collections.unmodifiableList(new ArrayList(list));
}
/**
* Get an unmodifiable list from the single element. Return emptyList() if element is null.
*
* @deprecated Use CollectionUtils.singletonList() instead
*/
@Deprecated
public static List unmodifiableList(T element) {
List list = toEmptyList(element);
return Collections.unmodifiableList(list);
}
/**
* Get an unmodifiable list from elements
*
* @deprecated Use ImmutableList.copyOf(elements) instead
*/
@Deprecated
@SafeVarargs
public static List unmodifiableList(T... elements) {
return Collections.unmodifiableList(Arrays.asList(elements));
}
/**
* If the CSV is whitespace, the empty string, null, "null", or "none", return an empty list.
*/
public static List getNoneSensitiveListFromCSV(String csv) {
if (StringUtils.isBlank(csv) || NullUtils.isNullOrNone(csv)) {
return Collections. emptyList();
} else {
return CollectionUtils.getTrimmedListFromCSV(csv);
}
}
/**
* Remove any Strings from the list that do not match the filter and then sort the ones that remain
*
* @return The list of strings that were filtered out.
* @deprecated
*/
@Deprecated
public static List filterAndSort(List strings, StringFilter filter) {
List excluded = filter(strings, filter);
Collections.sort(strings);
return excluded;
}
/**
* Remove any Strings from the list that do not match the filter and then sort the ones that remain
*
* @return The list of strings that were filtered out.
*/
public static List filterAndSortStrings(List strings, org.kuali.common.util.filter.StringFilter filter) {
List excluded = filterStrings(strings, filter);
Collections.sort(strings);
return excluded;
}
/**
* Remove any Strings from the collection that do not match the filter
*/
public static List filterStrings(Collection strings, org.kuali.common.util.filter.StringFilter filter) {
List excluded = new ArrayList();
Iterator itr = strings.iterator();
while (itr.hasNext()) {
String string = itr.next();
if (!filter.include(string)) {
excluded.add(string);
itr.remove();
}
}
return excluded;
}
/**
* Remove any Strings from the collection that do not match the filter
*
* @deprecated
*/
@Deprecated
public static List filter(Collection strings, StringFilter filter) {
List excluded = new ArrayList();
Iterator itr = strings.iterator();
while (itr.hasNext()) {
String string = itr.next();
if (!filter.include(string)) {
excluded.add(string);
itr.remove();
}
}
return excluded;
}
/**
* Null safe method for converting an array of objects into a list. Never returns null.
*/
public static List