blob: 6e5a18914aa1e227d3df5032d77a650071500de9 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>EventClassComparator.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Shiro :: Event</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.event.support</a> &gt; <span class="el_source">EventClassComparator.java</span></div><h1>EventClassComparator.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.event.support;
import java.util.Comparator;
/**
* Compares two event classes based on their position in a class hierarchy. Classes higher up in a hierarchy are
* 'greater than' (ordered later) than classes lower in a hierarchy (ordered earlier). Classes in unrelated
* hierarchies have the same order priority.
* &lt;p/&gt;
* Event bus implementations use this comparator to determine which event listener method to invoke when polymorphic
* listener methods are defined:
* &lt;p/&gt;
* If two event classes exist A and B, where A is the parent class of B (and B is a subclass of A) and an event
* subscriber listens to both events:
* &lt;pre&gt;
* &amp;#64;Subscribe
* public void onEvent(A a) { ... }
*
* &amp;#64;Subscribe
* public void onEvent(B b) { ... }
* &lt;/pre&gt;
*
* The {@code onEvent(B b)} method will be invoked on the subscriber and the
* {@code onEvent(A a)} method will &lt;em&gt;not&lt;/em&gt; be invoked. This is to prevent multiple dispatching of a single event
* to the same consumer.
* &lt;p/&gt;
* The EventClassComparator is used to order listener method priority based on their event argument class - methods
* handling event subclasses have higher precedence than superclasses.
*
* @since 1.3
*/
<span class="fc" id="L50">public class EventClassComparator implements Comparator&lt;Class&gt; {</span>
@SuppressWarnings(&quot;unchecked&quot;)
public int compare(Class a, Class b) {
<span class="fc bfc" id="L54" title="All 2 branches covered."> if (a == null) {</span>
<span class="fc bfc" id="L55" title="All 2 branches covered."> if (b == null) {</span>
<span class="fc" id="L56"> return 0;</span>
} else {
<span class="fc" id="L58"> return -1;</span>
}
<span class="fc bfc" id="L60" title="All 2 branches covered."> } else if (b == null) {</span>
<span class="fc" id="L61"> return 1;</span>
<span class="pc bpc" id="L62" title="1 of 4 branches missed."> } else if (a == b || a.equals(b)) {</span>
<span class="fc" id="L63"> return 0;</span>
} else {
<span class="fc bfc" id="L65" title="All 2 branches covered."> if (a.isAssignableFrom(b)) {</span>
<span class="fc" id="L66"> return 1;</span>
<span class="fc bfc" id="L67" title="All 2 branches covered."> } else if (b.isAssignableFrom(a)) {</span>
<span class="fc" id="L68"> return -1;</span>
} else {
<span class="fc" id="L70"> return 0;</span>
}
}
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html>