com.softicar.platform.common.core.item.BasicItemUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.item;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* Utility methods for basic items.
*
* @author Oliver Richers
* @author Alexander Schmidt
*/
public class BasicItemUtils {
/**
* Returns the ID of the given item or null.
*
* @param item
* the basic item to use
* @return the ID of the basic item, or null if the given item is null
*/
public static Integer getIdOrNull(IBasicItem item) {
return item != null? item.getId() : null;
}
public static Set getIdSetFromBasicItems(Collection items) {
Map result = getIdMapFromBasicItems(items);
return result != null? result.keySet() : null;
}
public static Map getIdMapFromBasicItems(Collection items) {
if (items != null) {
return items//
.stream()
.filter(item -> item != null && item.getId() != null)
.collect(Collectors.toMap(IBasicItem::getId, item -> item));
} else {
return null;
}
}
public static Set getLongIdSetFromBasicItems(Collection items) {
Map result = getLongIdMapFromBasicItems(items);
return result != null? result.keySet() : null;
}
public static Map getLongIdMapFromBasicItems(Collection items) {
if (items != null) {
return items//
.stream()
.filter(item -> item != null && item.getId() != null)
.collect(Collectors.toMap(item -> item.getId().longValue(), item -> item));
} else {
return null;
}
}
}