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

org.dihedron.patterns.bus.PrioritisedTask Maven / Gradle / Ivy

Go to download

Base set of functionalities, including simple utility classes and more complex patterns.

The newest version!
/**
 * Copyright (c) 2012-2014, Andrea Funto'. All rights reserved. See LICENSE for details.
 */ 
package org.dihedron.patterns.bus;

import org.dihedron.core.License;


/**
 * The common base task for internal bus tasks.
 * 
 * @author Andrea Funto'
 */
@License
class PrioritisedTask extends Task implements Comparable> {

	/**
	 * Constructor.
	 *
	 * @param destination
	 *   the destination to which the message must be delivered.
	 * @param message
	 *   the message to dispatch.
	 */
	PrioritisedTask(Destination destination, M message) {
		super(destination, message);
	}
	
	/**
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(PrioritisedTask other) {
		if(message instanceof Prioritised && other.message instanceof Prioritised) {
			int p1 = ((Prioritised)message).getPriority();
			int p2 = ((Prioritised)other.message).getPriority();
			return p1 < p2 ? -1 : p1 == p2 ? 0 : -1;
		}
		return 0;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy