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

org.atemsource.atem.utility.common.EntityOperationSelector Maven / Gradle / Ivy

package org.atemsource.atem.utility.common;

import java.util.HashMap;
import java.util.Map;

import org.atemsource.atem.api.type.Type;

public class EntityOperationSelector {

	private E defaultOperation;
	private Map, E> operations;
	private Map, EntityOperationReference> operationRefs;

	

	public void setDefaultOperation(E defaultOperation) {
		this.defaultOperation = defaultOperation;
	}

	public E select(Type actualType) {
		E selected;
		if (operations != null) {
			selected = operations.get(actualType);
			if (selected != null) {
				return selected;
			}
		}
		if (operationRefs != null) {
			EntityOperationReference selectedRef = operationRefs.get(actualType);
			if (selectedRef != null) {
				return selectedRef.getOperation();
			}
		}
		return defaultOperation;
	}

	public void put(Type type, E operation) {
		if (operations == null) {
			operations = new HashMap, E>();
		}
		operations.put(type, operation);
	}

	public void put(Type type, EntityOperationReference ref) {
		if (operationRefs == null) {
			operationRefs = new HashMap, EntityOperationReference>();
		}
		operationRefs.put(type, ref);
	}

	public String toString(String indent) {
		return defaultOperation.toString(indent);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy