1 /*
2  * Copyright 2002-2015 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 module hunt.stomp.handler.MessageCondition;
18 
19 
20 import hunt.stomp.Message;
21 
22 /**
23  * Contract for mapping conditions to messages.
24  *
25  * <p>Message conditions can be combined (e.g. type + method-level conditions),
26  * matched to a specific Message, as well as compared to each other in the
27  * context of a Message to determine which one matches a request more closely.
28  *
29  * @author Rossen Stoyanchev
30  * @since 4.0
31  * @param (T) the kind of condition that this condition can be combined with or compared to
32  */
33 interface MessageCondition(T) {
34 
35 	/**
36 	 * Define the rules for combining this condition with another.
37 	 * For example combining type- and method-level conditions.
38 	 * @param other the condition to combine with
39 	 * @return the resulting message condition
40 	 */
41 	T combine(T other);
42 
43 	/**
44 	 * Check if this condition matches the given Message and returns a
45 	 * potentially new condition with content tailored to the current message.
46 	 * For example a condition with destination patterns might return a new
47 	 * condition with sorted, matching patterns only.
48 	 * @return a condition instance in case of a match; or {@code null} if there is no match.
49 	 */
50 	
51 	T getMatchingCondition(MessageBase message);
52 
53 	/**
54 	 * Compare this condition to another in the context of a specific message.
55 	 * It is assumed both instances have been obtained via
56 	 * {@link #getMatchingCondition(Message)} to ensure they have content
57 	 * relevant to current message only.
58 	 */
59 	int compareTo(T other, MessageBase message);
60 
61 }