//# 0 errors, 129 messages
//#
/*
    //#MediaSourceComparator.java:1:1: class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#MediaSourceComparator.java:1:1: method: com.dmdirc.addons.nowplaying.MediaSourceComparator.com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.dmdirc.addons.nowplaying;

import java.io.Serializable;
import java.util.Comparator;
import java.util.List;

/**
 * Sorts media sources according to an ordered list of their names.
 *
 * @author chris
 */
public class MediaSourceComparator implements Comparator<MediaSource>, Serializable {
    //#MediaSourceComparator.java:34: method: int com.dmdirc.addons.nowplaying.MediaSourceComparator.compare(Object, Object)
    //#MediaSourceComparator.java:34: Warning: suspicious precondition
    //#    The precondition for x0.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int compare(Object, Object)
    //#    suspicious precondition index: [5]
    //#    Attribs:  Soft
    //#MediaSourceComparator.java:34: Warning: suspicious precondition
    //#    The precondition for x1.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int compare(Object, Object)
    //#    suspicious precondition index: [7]
    //#    Attribs:  Soft
    //#input(int compare(Object, Object)): __Descendant_Table[com/dmdirc/addons/nowplaying/MediaSourceComparator]
    //#input(int compare(Object, Object)): __Descendant_Table[others]
    //#input(int compare(Object, Object)): __Dispatch_Table.compare(Lcom/dmdirc/addons/nowplaying/MediaSource;Lcom/dmdirc/addons/nowplaying/MediaSource;)I
    //#input(int compare(Object, Object)): com/dmdirc/addons/mediasource_dcop/AmarokSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(Object, Object)): com/dmdirc/addons/mediasource_dcop/KaffeineSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(Object, Object)): com/dmdirc/addons/mediasource_dcop/NoatunSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(Object, Object)): com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(Object, Object)): com/dmdirc/addons/mediasource_windows/DllSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/AmarokSource]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/KaffeineSource]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/NoatunSource]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_windows/DllSource]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/nowplaying/MediaSource]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[others]
    //#input(int compare(Object, Object)): com/dmdirc/addons/nowplaying/MediaSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(Object, Object)): this
    //#input(int compare(Object, Object)): this.__Tag
    //#input(int compare(Object, Object)): this.order
    //#input(int compare(Object, Object)): x0
    //#input(int compare(Object, Object)): x0.__Tag
    //#input(int compare(Object, Object)): x1
    //#input(int compare(Object, Object)): x1.__Tag
    //#output(int compare(Object, Object)): return_value
    //#pre[2] (int compare(Object, Object)): this.__Tag == com/dmdirc/addons/nowplaying/MediaSourceComparator
    //#pre[3] (int compare(Object, Object)): this.order != null
    //#pre[4] (int compare(Object, Object)): x0 != null
    //#pre[6] (int compare(Object, Object)): x1 != null
    //#pre[5] (int compare(Object, Object)): (soft) x0.__Tag in {com/dmdirc/addons/mediasource_dcop/AmarokSource, com/dmdirc/addons/mediasource_dcop/KaffeineSource, com/dmdirc/addons/mediasource_dcop/NoatunSource, com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin, com/dmdirc/addons/mediasource_windows/DllSource, com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource, com/dmdirc/addons/nowplaying/MediaSource}
    //#pre[7] (int compare(Object, Object)): (soft) x1.__Tag in {com/dmdirc/addons/mediasource_dcop/AmarokSource, com/dmdirc/addons/mediasource_dcop/KaffeineSource, com/dmdirc/addons/mediasource_dcop/NoatunSource, com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin, com/dmdirc/addons/mediasource_windows/DllSource, com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource, com/dmdirc/addons/nowplaying/MediaSource}
    //#post(int compare(Object, Object)): return_value == 0
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:getAppName
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:java.util.List:contains
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:java.util.List:add
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:java.util.List:indexOf
    //#MediaSourceComparator.java:34: end of method: int com.dmdirc.addons.nowplaying.MediaSourceComparator.compare(Object, Object)
    
    /**
     * A version number for this class. It should be changed whenever the class
     * structure is changed (or anything else that would prevent serialized
     * objects being unserialized with the new class).
     */
    private static final long serialVersionUID = 1;
    
    /** The order that the sources should be checked. */
    private final List<String> order;
    
    /**
     * Creates a new instance of MediaSourceComparator.
     * NB: The order list may be altered during comparisons.
     *
     * @param order An ordered list of media source names
     */
    public MediaSourceComparator(final List<String> order) {
    //#MediaSourceComparator.java:52: method: void com.dmdirc.addons.nowplaying.MediaSourceComparator.com.dmdirc.addons.nowplaying.MediaSourceComparator(List)
    //#input(void com.dmdirc.addons.nowplaying.MediaSourceComparator(List)): order
    //#input(void com.dmdirc.addons.nowplaying.MediaSourceComparator(List)): this
    //#output(void com.dmdirc.addons.nowplaying.MediaSourceComparator(List)): this.order
    //#post(void com.dmdirc.addons.nowplaying.MediaSourceComparator(List)): this.order == order
    //#post(void com.dmdirc.addons.nowplaying.MediaSourceComparator(List)): init'ed(this.order)
        this.order = order;
    }
    //#MediaSourceComparator.java:54: end of method: void com.dmdirc.addons.nowplaying.MediaSourceComparator.com.dmdirc.addons.nowplaying.MediaSourceComparator(List)

    /** {@inheritDoc} */
    @Override
    public int compare(final MediaSource o1, final MediaSource o2) {
        return getPosition(o1) - getPosition(o2);
    //#MediaSourceComparator.java:59: method: int com.dmdirc.addons.nowplaying.MediaSourceComparator.compare(MediaSource, MediaSource)
    //#MediaSourceComparator.java:59: Warning: suspicious precondition
    //#    The precondition for o1.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int compare(MediaSource, MediaSource)
    //#    suspicious precondition index: [2]
    //#MediaSourceComparator.java:59: Warning: suspicious precondition
    //#    The precondition for o2.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int compare(MediaSource, MediaSource)
    //#    suspicious precondition index: [4]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/mediasource_dcop/AmarokSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/mediasource_dcop/KaffeineSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/mediasource_dcop/NoatunSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/mediasource_windows/DllSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/AmarokSource]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/KaffeineSource]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/NoatunSource]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_windows/DllSource]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/nowplaying/MediaSource]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[others]
    //#input(int compare(MediaSource, MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int compare(MediaSource, MediaSource)): o1
    //#input(int compare(MediaSource, MediaSource)): o1.__Tag
    //#input(int compare(MediaSource, MediaSource)): o2
    //#input(int compare(MediaSource, MediaSource)): o2.__Tag
    //#input(int compare(MediaSource, MediaSource)): this
    //#input(int compare(MediaSource, MediaSource)): this.order
    //#output(int compare(MediaSource, MediaSource)): return_value
    //#pre[1] (int compare(MediaSource, MediaSource)): o1 != null
    //#pre[2] (int compare(MediaSource, MediaSource)): o1.__Tag in {com/dmdirc/addons/mediasource_dcop/AmarokSource, com/dmdirc/addons/mediasource_dcop/KaffeineSource, com/dmdirc/addons/mediasource_dcop/NoatunSource, com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin, com/dmdirc/addons/mediasource_windows/DllSource, com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource, com/dmdirc/addons/nowplaying/MediaSource}
    //#pre[3] (int compare(MediaSource, MediaSource)): o2 != null
    //#pre[4] (int compare(MediaSource, MediaSource)): o2.__Tag in {com/dmdirc/addons/mediasource_dcop/AmarokSource, com/dmdirc/addons/mediasource_dcop/KaffeineSource, com/dmdirc/addons/mediasource_dcop/NoatunSource, com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin, com/dmdirc/addons/mediasource_windows/DllSource, com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource, com/dmdirc/addons/nowplaying/MediaSource}
    //#pre[6] (int compare(MediaSource, MediaSource)): this.order != null
    //#presumption(int compare(MediaSource, MediaSource)): java.util.List:indexOf(...)@73 - java.util.List:indexOf(...)@73 in {-4_294_967_295..2_147_483_648}
    //#presumption(int compare(MediaSource, MediaSource)): java.util.List:indexOf(...)@73 - java.util.List:indexOf(...)@73 in {-4_294_967_295..2_147_483_648}
    //#post(int compare(MediaSource, MediaSource)): init'ed(return_value)
    //#unanalyzed(int compare(MediaSource, MediaSource)): Effects-of-calling:getAppName
    //#unanalyzed(int compare(MediaSource, MediaSource)): Effects-of-calling:java.util.List:contains
    //#unanalyzed(int compare(MediaSource, MediaSource)): Effects-of-calling:java.util.List:add
    //#unanalyzed(int compare(MediaSource, MediaSource)): Effects-of-calling:java.util.List:indexOf
    //#MediaSourceComparator.java:59: end of method: int com.dmdirc.addons.nowplaying.MediaSourceComparator.compare(MediaSource, MediaSource)
    }
    
    /**
     * Retrieves the position of the source within the order list.
     * If the source is not present it is appended to the list.
     *
     * @param source The media source to be tested
     */
    private int getPosition(final MediaSource source) {
        if (!order.contains(source.getAppName())) {
    //#MediaSourceComparator.java:69: method: int com.dmdirc.addons.nowplaying.MediaSourceComparator.getPosition(MediaSource)
    //#MediaSourceComparator.java:69: Warning: call too complex - analysis skipped
    //#    call on String getAppName()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int getPosition(MediaSource)
    //#    unanalyzed callee: String getAppName()
    //#MediaSourceComparator.java:69: Warning: suspicious precondition
    //#    The precondition for source.__Tag is not a contiguous range of values
    //#    severity: SUPPRESSED
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int getPosition(MediaSource)
    //#    suspicious precondition index: [2]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/mediasource_dcop/AmarokSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/mediasource_dcop/KaffeineSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/mediasource_dcop/NoatunSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/mediasource_windows/DllSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/AmarokSource]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/KaffeineSource]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_dcop/NoatunSource]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/mediasource_windows/DllSource]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[com/dmdirc/addons/nowplaying/MediaSource]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Descendant_Table[others]
    //#input(int getPosition(MediaSource)): com/dmdirc/addons/nowplaying/MediaSource.__Dispatch_Table.getAppName()Ljava/lang/String;
    //#input(int getPosition(MediaSource)): source
    //#input(int getPosition(MediaSource)): source.__Tag
    //#input(int getPosition(MediaSource)): this
    //#input(int getPosition(MediaSource)): this.order
    //#output(int getPosition(MediaSource)): return_value
    //#pre[1] (int getPosition(MediaSource)): source != null
    //#pre[2] (int getPosition(MediaSource)): source.__Tag in {com/dmdirc/addons/mediasource_dcop/AmarokSource, com/dmdirc/addons/mediasource_dcop/KaffeineSource, com/dmdirc/addons/mediasource_dcop/NoatunSource, com/dmdirc/addons/mediasource_vlc/VlcMediaSourcePlugin, com/dmdirc/addons/mediasource_windows/DllSource, com/dmdirc/addons/nowplaying/ConfigPanel$DummyMediaSource, com/dmdirc/addons/nowplaying/MediaSource}
    //#pre[4] (int getPosition(MediaSource)): this.order != null
    //#post(int getPosition(MediaSource)): init'ed(return_value)
    //#test_vector(int getPosition(MediaSource)): java.util.List:contains(...)@69: {1}, {0}
            order.add(source.getAppName());
    //#MediaSourceComparator.java:70: Warning: call too complex - analysis skipped
    //#    call on String getAppName()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int getPosition(MediaSource)
    //#    unanalyzed callee: String getAppName()
        }
        
        return order.indexOf(source.getAppName());
    //#MediaSourceComparator.java:73: Warning: call too complex - analysis skipped
    //#    call on String getAppName()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.nowplaying.MediaSourceComparator
    //#    method: int getPosition(MediaSource)
    //#    unanalyzed callee: String getAppName()
    //#MediaSourceComparator.java:73: end of method: int com.dmdirc.addons.nowplaying.MediaSourceComparator.getPosition(MediaSource)
    }
    
}
    //#output(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Descendant_Table[com/dmdirc/addons/nowplaying/MediaSourceComparator]
    //#output(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Dispatch_Table.compare(Lcom/dmdirc/addons/nowplaying/MediaSource;Lcom/dmdirc/addons/nowplaying/MediaSource;)I
    //#output(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Dispatch_Table.compare(Ljava/lang/Object;Ljava/lang/Object;)I
    //#output(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Dispatch_Table.getPosition(Lcom/dmdirc/addons/nowplaying/MediaSource;)I
    //#post(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Descendant_Table[com/dmdirc/addons/nowplaying/MediaSourceComparator] == &__Dispatch_Table
    //#post(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Dispatch_Table.compare(Lcom/dmdirc/addons/nowplaying/MediaSource;Lcom/dmdirc/addons/nowplaying/MediaSource;)I == &compare
    //#post(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Dispatch_Table.compare(Ljava/lang/Object;Ljava/lang/Object;)I == &compare
    //#post(com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init): __Dispatch_Table.getPosition(Lcom/dmdirc/addons/nowplaying/MediaSource;)I == &getPosition
    //#MediaSourceComparator.java:: end of method: com.dmdirc.addons.nowplaying.MediaSourceComparator.com.dmdirc.addons.nowplaying.MediaSourceComparator__static_init
    //#MediaSourceComparator.java:: end of class: com.dmdirc.addons.nowplaying.MediaSourceComparator
