//# 0 errors, 54 messages
//#
/*
    //#NicklistComparator.java:1:1: class: com.dmdirc.addons.ui_swing.components.NicklistComparator
    //#NicklistComparator.java:1:1: method: com.dmdirc.addons.ui_swing.components.NicklistComparator.com.dmdirc.addons.ui_swing.components.NicklistComparator__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.ui_swing.components;

import com.dmdirc.parser.irc.ChannelClientInfo;

import java.io.Serializable;
import java.util.Comparator;
/**
 * Compares nicklist entries to each other, for sorting purposes.
 */
public final class NicklistComparator implements Comparator<ChannelClientInfo>,
    //#NicklistComparator.java:32: method: int com.dmdirc.addons.ui_swing.components.NicklistComparator.compare(Object, Object)
    //#input(int compare(Object, Object)): this
    //#input(int compare(Object, Object)): this.sortByCase
    //#input(int compare(Object, Object)): this.sortByMode
    //#input(int compare(Object, Object)): x0
    //#input(int compare(Object, Object)): x1
    //#output(int compare(Object, Object)): return_value
    //#pre[4] (int compare(Object, Object)): x0 != null
    //#pre[5] (int compare(Object, Object)): x1 != null
    //#post(int compare(Object, Object)): init'ed(return_value)
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:com.dmdirc.parser.irc.ChannelClientInfo:getNickname
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:com.dmdirc.parser.irc.ChannelClientInfo:getImportantModeValue
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:java.lang.String:compareTo
    //#unanalyzed(int compare(Object, Object)): Effects-of-calling:java.lang.String:compareToIgnoreCase
    //#NicklistComparator.java:32: end of method: int com.dmdirc.addons.ui_swing.components.NicklistComparator.compare(Object, Object)
        Serializable {
    /**
     * 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;
    
    /**
     * whether to sort the nicklist by modes.
     */
    private final boolean sortByMode;
    
    /**
     * whether to sort the nicklist by case.
     */
    private final boolean sortByCase;
    
    /**
     * Creates a new instance of NicklistComparator.
     * @param newSortByMode sorts by channel mode of the user
     * @param newSortByCase sorts by nickname case
     */
    public NicklistComparator(final boolean newSortByMode,
            final boolean newSortByCase) {
    //#NicklistComparator.java:57: method: void com.dmdirc.addons.ui_swing.components.NicklistComparator.com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)
    //#input(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): newSortByCase
    //#input(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): newSortByMode
    //#input(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): this
    //#output(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): this.sortByCase
    //#output(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): this.sortByMode
    //#post(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): this.sortByCase == newSortByCase
    //#post(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): init'ed(this.sortByCase)
    //#post(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): this.sortByMode == newSortByMode
    //#post(void com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)): init'ed(this.sortByMode)
        this.sortByMode = newSortByMode;
        this.sortByCase = newSortByCase;
    }
    //#NicklistComparator.java:60: end of method: void com.dmdirc.addons.ui_swing.components.NicklistComparator.com.dmdirc.addons.ui_swing.components.NicklistComparator(bool, bool)
    
    /**
     * Compares two ChannelClient objects based on the settings the comparator
     * was initialised with.
     * @param client1 the first client to be compared
     * @param client2 the second client to be compared
     * @return a negative integer, zero, or a positive integer as the first
     * argument is less than, equal to, or greater than the second.
     */
    public int compare(final ChannelClientInfo client1,
            final ChannelClientInfo client2) {
        final String nickname1 = client1.getNickname();
    //#NicklistComparator.java:72: method: int com.dmdirc.addons.ui_swing.components.NicklistComparator.compare(ChannelClientInfo, ChannelClientInfo)
    //#NicklistComparator.java:72: Warning: method not available - call not analyzed
    //#    call on String com.dmdirc.parser.irc.ChannelClientInfo:getNickname()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.components.NicklistComparator
    //#    method: int compare(ChannelClientInfo, ChannelClientInfo)
    //#    unanalyzed callee: String com.dmdirc.parser.irc.ChannelClientInfo:getNickname()
    //#input(int compare(ChannelClientInfo, ChannelClientInfo)): client1
    //#input(int compare(ChannelClientInfo, ChannelClientInfo)): client2
    //#input(int compare(ChannelClientInfo, ChannelClientInfo)): this
    //#input(int compare(ChannelClientInfo, ChannelClientInfo)): this.sortByCase
    //#input(int compare(ChannelClientInfo, ChannelClientInfo)): this.sortByMode
    //#output(int compare(ChannelClientInfo, ChannelClientInfo)): return_value
    //#pre[1] (int compare(ChannelClientInfo, ChannelClientInfo)): client1 != null
    //#pre[2] (int compare(ChannelClientInfo, ChannelClientInfo)): client2 != null
    //#presumption(int compare(ChannelClientInfo, ChannelClientInfo)): com.dmdirc.parser.irc.ChannelClientInfo:getNickname(...)@72 != null
    //#post(int compare(ChannelClientInfo, ChannelClientInfo)): init'ed(return_value)
    //#test_vector(int compare(ChannelClientInfo, ChannelClientInfo)): this.sortByCase: {0}, {1}
    //#test_vector(int compare(ChannelClientInfo, ChannelClientInfo)): this.sortByMode: {0}, {1}
        final String nickname2 = client2.getNickname();
    //#NicklistComparator.java:73: Warning: method not available - call not analyzed
    //#    call on String com.dmdirc.parser.irc.ChannelClientInfo:getNickname()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.components.NicklistComparator
    //#    method: int compare(ChannelClientInfo, ChannelClientInfo)
    //#    unanalyzed callee: String com.dmdirc.parser.irc.ChannelClientInfo:getNickname()
        
        if (sortByMode) {
            if (client1.getImportantModeValue()
    //#NicklistComparator.java:76: Warning: method not available - call not analyzed
    //#    call on long com.dmdirc.parser.irc.ChannelClientInfo:getImportantModeValue()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.components.NicklistComparator
    //#    method: int compare(ChannelClientInfo, ChannelClientInfo)
    //#    unanalyzed callee: long com.dmdirc.parser.irc.ChannelClientInfo:getImportantModeValue()
            > client2.getImportantModeValue()) {
                return -1;
            } else if (client1.getImportantModeValue()
    //#NicklistComparator.java:79: Warning: method not available - call not analyzed
    //#    call on long com.dmdirc.parser.irc.ChannelClientInfo:getImportantModeValue()
    //#    severity: INFORMATIONAL
    //#    class: com.dmdirc.addons.ui_swing.components.NicklistComparator
    //#    method: int compare(ChannelClientInfo, ChannelClientInfo)
    //#    unanalyzed callee: long com.dmdirc.parser.irc.ChannelClientInfo:getImportantModeValue()
            < client2.getImportantModeValue()) {
                return 1;
            }
        }
        
        if (sortByCase) {
            return nickname1.compareTo(nickname2);
        } else {
            return nickname1.compareToIgnoreCase(nickname2);
    //#NicklistComparator.java:88: end of method: int com.dmdirc.addons.ui_swing.components.NicklistComparator.compare(ChannelClientInfo, ChannelClientInfo)
        }
    }
}
    //#output(com.dmdirc.addons.ui_swing.components.NicklistComparator__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/components/NicklistComparator]
    //#output(com.dmdirc.addons.ui_swing.components.NicklistComparator__static_init): __Dispatch_Table.compare(Lcom/dmdirc/parser/irc/ChannelClientInfo;Lcom/dmdirc/parser/irc/ChannelClientInfo;)I
    //#output(com.dmdirc.addons.ui_swing.components.NicklistComparator__static_init): __Dispatch_Table.compare(Ljava/lang/Object;Ljava/lang/Object;)I
    //#post(com.dmdirc.addons.ui_swing.components.NicklistComparator__static_init): __Descendant_Table[com/dmdirc/addons/ui_swing/components/NicklistComparator] == &__Dispatch_Table
    //#post(com.dmdirc.addons.ui_swing.components.NicklistComparator__static_init): __Dispatch_Table.compare(Lcom/dmdirc/parser/irc/ChannelClientInfo;Lcom/dmdirc/parser/irc/ChannelClientInfo;)I == &compare
    //#post(com.dmdirc.addons.ui_swing.components.NicklistComparator__static_init): __Dispatch_Table.compare(Ljava/lang/Object;Ljava/lang/Object;)I == &compare
    //#NicklistComparator.java:: end of method: com.dmdirc.addons.ui_swing.components.NicklistComparator.com.dmdirc.addons.ui_swing.components.NicklistComparator__static_init
    //#NicklistComparator.java:: end of class: com.dmdirc.addons.ui_swing.components.NicklistComparator
