org.kuali.common.util.CollectionUtils Maven / Gradle / Ivy
/**
* Copyright 2010-2012 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 java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.StringUtils;
public class CollectionUtils {
public static final List toEmptyList(T o) {
if (o == null) {
return Collections. emptyList();
} else {
return Collections.singletonList(o);
}
}
public static final List toEmpty(List list) {
if (list == null) {
return Collections. emptyList();
} else {
return list;
}
}
public static final List toNullIfEmpty(List list) {
if (isEmpty(list)) {
return null;
} else {
return list;
}
}
public static final Collection toNullIfEmpty(Collection c) {
if (isEmpty(c)) {
return null;
} else {
return c;
}
}
public static final List getPreFilledList(int size, T value) {
if (value == null || size < 1) {
return Collections. emptyList();
} else {
List list = new ArrayList(size);
for (int i = 0; i < size; i++) {
list.add(value);
}
return list;
}
}
public static final Object[] toArray(List