All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.core.item.BasicItemUtils Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy