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

com.softicar.platform.common.container.map.instance.ClassInstanceListMap 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.container.map.instance;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * This class maps classes to a {@link List} of instances of that class.
 *
 * @author Oliver Richers
 */
public class ClassInstanceListMap {

	private final Map, List> map;

	public ClassInstanceListMap() {

		this.map = new HashMap<>();
	}

	@SuppressWarnings("unchecked")
	public  void add(T instance) {

		var list = (List) map.computeIfAbsent(instance.getClass(), dummy -> new ArrayList<>());
		list.add(instance);
	}

	@SuppressWarnings("unchecked")
	public  List getInstances(Class classOfInstances) {

		return (List) map.getOrDefault(classOfInstances, Collections.emptyList());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy