File Source: ChannelClientInfo.java

         /* 
    P/P   *  Method: com.dmdirc.parser.irc.ChannelClientInfo__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.parser.irc;
    24  
    25  import java.util.HashMap;
    26  import java.util.Map;
    27  
    28  /**
    29   * Contains information about a client on a channel.
    30   * 
    31   * @author Shane Mc Cormack
    32   * @author Chris Smith
    33   * @see IRCParser
    34   */
    35  public class ChannelClientInfo {
    36  	/** Reference to ClientInfo object this represents. */
    37  	private final ClientInfo cClient;
    38  	/** Integer representation of the channel modes assocated with this user. */
    39  	private long nModes;
    40  	/** Reference to the parser object that owns this channelclient, Used for modes. */
    41  	private final IRCParser myParser;
    42  	/** Reference to the channel object that owns this channelclient. */
    43  	private final ChannelInfo myChannel;
    44  	/** A Map to allow applications to attach misc data to this object */
    45  	private Map myMap;
    46  	
    47  	/**
    48  	 * Create a ChannelClient instance of a CLient.
    49  	 *
    50  	 * @param tParser Refernce to parser that owns this channelclient (used for modes)
    51  	 * @param client Client that this channelclient represents
    52  	 * @param channel Channel that owns this channelclient
    53  	 */	
        	 /* 
    P/P 	  *  Method: void com.dmdirc.parser.irc.ChannelClientInfo(IRCParser, ClientInfo, ChannelInfo)
        	  * 
        	  *  Preconditions:
        	  *    channel != null
        	  *    channel.sName != null
        	  *    client != null
        	  *    client.myChannelClientInfos != null
        	  *    client.myParser != null
        	  *    init'ed(client.myParser.stringConverter)
        	  *    (soft) client.myParser.stringConverter.lowercase != null
        	  *    (soft) init'ed(client.myParser.stringConverter.lowercase[...])
        	  * 
        	  *  Postconditions:
        	  *    client.myParser.stringConverter == One-of{old client.myParser.stringConverter, &new IRCStringConverter(getIRCStringConverter#1)}
        	  *    client.myParser.stringConverter != null
        	  *    this.cClient == client
        	  *    this.cClient != null
        	  *    this.myChannel == channel
        	  *    this.myChannel != null
        	  *    this.myMap == &new HashMap(ChannelClientInfo#1)
        	  *    this.myParser == tParser
        	  *    init'ed(this.myParser)
        	  *    new HashMap(ChannelClientInfo#1) num objects == 1
        	  *    ...
        	  */
    54  	public ChannelClientInfo(final IRCParser tParser, final ClientInfo client, final ChannelInfo channel) {
    55  		myMap = new HashMap<Object, Object>();
    56  		myParser = tParser;
    57  		cClient = client;
    58  		myChannel = channel;
    59  		cClient.addChannelClientInfo(this);
    60  	}
    61  	
    62  	/**
    63  	 * Set the Map object attatched to this object.
    64  	 *
    65  	 * @param newMap New Map to attatch.
    66  	 * @see #getMap
    67  	 */
    68  	public void setMap(final Map newMap) {
        		 /* 
    P/P 		  *  Method: void setMap(Map)
        		  * 
        		  *  Postconditions:
        		  *    this.myMap == newMap
        		  *    init'ed(this.myMap)
        		  */
    69  		myMap = newMap;
    70  	}
    71  	
    72  	/**
    73  	 * Get the Map object attatched to this object.
    74  	 *
    75  	 * @return Map to attatched to this.
    76  	 * @see #setMap
    77  	 */
    78  	public Map getMap() {
        		 /* 
    P/P 		  *  Method: Map getMap()
        		  * 
        		  *  Preconditions:
        		  *    init'ed(this.myMap)
        		  * 
        		  *  Postconditions:
        		  *    return_value == this.myMap
        		  *    init'ed(return_value)
        		  */
    79  		return myMap;
    80  	}
    81  	
    82  	/**
    83  	 * Get the client object represented by this channelclient.
    84  	 *
    85  	 * @return Client object represented by this channelclient
    86  	 */
        	 /* 
    P/P 	  *  Method: ClientInfo getClient()
        	  * 
        	  *  Postconditions:
        	  *    return_value == this.cClient
        	  *    init'ed(return_value)
        	  */
    87  	public ClientInfo getClient() { return cClient; }
    88  	/**
    89  	 * Get the Channel object that owns this ChannelClient.
    90  	 *
    91  	 * @return Channel object that owns this ChannelClient
    92  	 */
        	 /* 
    P/P 	  *  Method: ChannelInfo getChannel()
        	  * 
        	  *  Postconditions:
        	  *    return_value == this.myChannel
        	  *    init'ed(return_value)
        	  */
    93  	public ChannelInfo getChannel() { return myChannel; }
    94  	/**
    95  	 * Get the nickname of the client object represented by this channelclient.
    96  	 *
    97  	 * @return Nickname of the Client object represented by this channelclient
    98  	 */	
        	 /* 
    P/P 	  *  Method: String getNickname()
        	  * 
        	  *  Preconditions:
        	  *    this.cClient != null
        	  *    init'ed(this.cClient.sNickname)
        	  * 
        	  *  Postconditions:
        	  *    return_value == this.cClient.sNickname
        	  *    init'ed(return_value)
        	  */
    99  	public String getNickname() { return cClient.getNickname(); }	
   100  	
   101  	/**
   102  	 * Set the modes this client has (Prefix modes).
   103  	 *
   104  	 * @param nNewMode integer representing the modes this client has.
   105  	 */
        	 /* 
    P/P 	  *  Method: void setChanMode(long)
        	  * 
        	  *  Postconditions:
        	  *    this.nModes == nNewMode
        	  *    init'ed(this.nModes)
        	  */
   106  	public void setChanMode(final long nNewMode) { nModes = nNewMode; }
   107  	/**
   108  	 * Get the modes this client has (Prefix modes).
   109  	 *
   110  	 * @return integer representing the modes this client has.
   111  	 */
        	 /* 
    P/P 	  *  Method: long getChanMode()
        	  * 
        	  *  Preconditions:
        	  *    init'ed(this.nModes)
        	  * 
        	  *  Postconditions:
        	  *    return_value == this.nModes
        	  *    init'ed(return_value)
        	  */
   112  	public long getChanMode() { return nModes; }
   113  	
   114  	/**
   115  	 * Get the modes this client has (Prefix modes) as a string.
   116  	 * Returns all known modes that the client has.
   117  	 * getChanModeStr(false).charAt(0) can be used to get the highest mode (o)
   118  	 * getChanModeStr(true).charAt(0) can be used to get the highest prefix (@)
   119  	 *
   120  	 * @param bPrefix if this is true, prefixes will be returned (@+) not modes (ov)
   121  	 * @return String representing the modes this client has.
   122  	 */
   123  	public String getChanModeStr(final boolean bPrefix) {
        		 /* 
    P/P 		  *  Method: String getChanModeStr(bool)
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    init'ed(this.myParser.nNextKeyPrefix)
        		  *    init'ed(this.nModes)
        		  *    (soft) this.myParser.hPrefixMap != null
        		  *    (soft) this.myParser.hPrefixModes != null
        		  * 
        		  *  Presumptions:
        		  *    java.util.Iterator:next(...)@130 != null
        		  *    java.util.Map:get(...)@131 != null
        		  *    java.util.Map:get(...)@133 != null
        		  *    java.util.Map:keySet(...)@130 != null
        		  * 
        		  *  Postconditions:
        		  *    java.lang.StringBuilder:toString(...)._tainted == 0
        		  *    return_value == &amp;java.lang.StringBuilder:toString(...)
        		  * 
        		  *  Test Vectors:
        		  *    bPrefix: {0}, {1}
        		  *    java.util.Iterator:hasNext(...)@130: {0}, {1}
        		  */
   124  		StringBuilder sModes = new StringBuilder();
   125  		long nTemp = 0;
   126  		final long nCurrentModes = this.getChanMode();
   127  
   128  		for (long i = myParser.nNextKeyPrefix; i > 0; i = i / 2) {
   129  			if ((nCurrentModes & i) == i) {
   130  				for (char cTemp : myParser.hPrefixModes.keySet()) {
   131  					nTemp = myParser.hPrefixModes.get(cTemp);
   132  					if (nTemp == i) {
   133  						if (bPrefix) { cTemp = myParser.hPrefixMap.get(cTemp); }
   134  						sModes = sModes.append(cTemp);
   135  						break;
   136  					}
   137  				}
   138  			}
   139  		}
   140  		
   141  		return sModes.toString();
   142  	}
   143  
   144  	/**
   145  	 * Get the value of the most important mode this client has (Prefix modes).
   146  	 * A higher value, is a more important mode, 0 = no modes.
   147  	 *
   148  	 * @return integer representing the value of the most important mode.
   149  	 */
   150  	public long getImportantModeValue() {
        		 /* 
    P/P 		  *  Method: long getImportantModeValue()
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    init'ed(this.myParser.nNextKeyPrefix)
        		  *    (soft) init'ed(this.nModes)
        		  * 
        		  *  Postconditions:
        		  *    return_value >= 0
        		  */
   151  		for (long i = myParser.nNextKeyPrefix; i > 0; i = i / 2) {
   152  			if ((nModes & i) == i) { return i; }
   153  		}
   154  		return 0;
   155  	}
   156  	
   157  	/**
   158  	 * Get the most important mode this client has (o, v etc), or an empty
   159       * string if the client has no modes.
   160  	 *
   161  	 * @return String representing the most important mode.
   162  	 */
   163  	public String getImportantMode() {
        		 /* 
    P/P 		  *  Method: String getImportantMode()
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    init'ed(this.myParser.nNextKeyPrefix)
        		  *    init'ed(this.nModes)
        		  *    (soft) this.myParser.hPrefixMap != null
        		  *    (soft) this.myParser.hPrefixModes != null
        		  * 
        		  *  Postconditions:
        		  *    java.lang.StringBuilder:toString(...)._tainted == 0
        		  *    return_value == One-of{&amp;java.lang.StringBuilder:toString(...)}
        		  *    return_value in Addr_Set{&amp;java.lang.StringBuilder:toString(...),&amp;java.lang.StringBuilder:toString(...)}
        		  * 
        		  *  Test Vectors:
        		  *    java.lang.String:isEmpty(...)@165: {1}, {0}
        		  */
   164  		String sModes = this.getChanModeStr(false);
   165  		if (!sModes.isEmpty()) { sModes = "" + sModes.charAt(0); }
   166  		return sModes;
   167  	}
   168  	
   169  	/**
   170  	 * Get the most important prefix this client has (@, + etc), or an empty
   171       * string if the client has no modes.
   172  	 *
   173  	 * @return String representing the most important mode.
   174  	 */
   175  	public String getImportantModePrefix() {
        		 /* 
    P/P 		  *  Method: String getImportantModePrefix()
        		  * 
        		  *  Preconditions:
        		  *    this.myParser != null
        		  *    init'ed(this.myParser.nNextKeyPrefix)
        		  *    init'ed(this.nModes)
        		  *    (soft) this.myParser.hPrefixMap != null
        		  *    (soft) this.myParser.hPrefixModes != null
        		  * 
        		  *  Postconditions:
        		  *    java.lang.StringBuilder:toString(...)._tainted == 0
        		  *    return_value == One-of{&amp;java.lang.StringBuilder:toString(...)}
        		  *    return_value in Addr_Set{&amp;java.lang.StringBuilder:toString(...),&amp;java.lang.StringBuilder:toString(...)}
        		  * 
        		  *  Test Vectors:
        		  *    java.lang.String:isEmpty(...)@177: {1}, {0}
        		  */
   176  		String sModes = this.getChanModeStr(true);
   177  		if (!sModes.isEmpty()) { sModes = "" + sModes.charAt(0); }
   178  		return sModes;
   179  	}
   180  	
   181  
   182  	/**
   183  	 * Get the String Value of ChannelClientInfo (ie @Nickname).
   184  	 *
   185  	 * @return String Value of user (inc prefix) (ie @Nickname)
   186  	 */
   187  	@Override
   188  	public String toString() { 
        		 /* 
    P/P 		  *  Method: String toString()
        		  * 
        		  *  Preconditions:
        		  *    this.cClient != null
        		  *    init'ed(this.cClient.sNickname)
        		  *    this.myParser != null
        		  *    init'ed(this.myParser.nNextKeyPrefix)
        		  *    init'ed(this.nModes)
        		  *    (soft) this.myParser.hPrefixMap != null
        		  *    (soft) this.myParser.hPrefixModes != null
        		  * 
        		  *  Postconditions:
        		  *    java.lang.StringBuilder:toString(...)._tainted == this.cClient.sNickname._tainted
        		  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
        		  *    return_value == &amp;java.lang.StringBuilder:toString(...)
        		  */
   189  		return this.getImportantModePrefix() + this.getNickname();
   190  	}	
   191  	
   192  	/**
   193  	 * Attempt to kick this user from the channel.
   194  	 *
   195  	 * @param sReason Why are they being kicked? "" for no reason
   196  	 */
   197  	public void kick(final String sReason) {
        		 /* 
    P/P 		  *  Method: void kick(String)
        		  * 
        		  *  Preconditions:
        		  *    sReason != null
        		  *    this.cClient != null
        		  *    init'ed(this.cClient.sNickname)
        		  *    this.myParser != null
        		  *    init'ed(this.myParser.out)
        		  *    (soft) init'ed(this.myParser.stringConverter)
        		  *    (soft) this.myParser.cMyself != null
        		  *    (soft) init'ed(this.myParser.currentSocketState)
        		  *    (soft) this.myParser.hChanModesOther != null
        		  *    (soft) this.myParser.hChannelList != null
        		  *    ...
        		  * 
        		  *  Postconditions:
        		  *    init'ed(java.lang.String:substring(...)._tainted)
        		  *    possibly_updated(this.myParser.cMyself.myAwayReason)
        		  *    this.myParser.stringConverter == One-of{old this.myParser.stringConverter, &amp;new IRCStringConverter(getIRCStringConverter#1)}
        		  *    init'ed(this.myParser.stringConverter)
        		  *    new IRCStringConverter(getIRCStringConverter#1) num objects <= 1
        		  *    new char[](IRCStringConverter#1) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
        		  *    new char[](IRCStringConverter#2) num objects == new IRCStringConverter(getIRCStringConverter#1) num objects
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).limit)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).lowercase)
        		  *    init'ed(new IRCStringConverter(getIRCStringConverter#1).uppercase)
        		  *    ...
        		  */
   198  		myParser.sendString("KICK " + myChannel + " " + this.getNickname() + (sReason.isEmpty() ? sReason : " :" + sReason));
   199  	}
   200  	
   201  	/**
   202  	 * Get the "Complete" String Value of ChannelClientInfo (ie @+Nickname).
   203  	 *
   204  	 * @return String Value of user (inc prefix) (ie @+Nickname)
   205  	 */
        	 /* 
    P/P 	  *  Method: String toFullString()
        	  * 
        	  *  Preconditions:
        	  *    this.cClient != null
        	  *    init'ed(this.cClient.sNickname)
        	  *    this.myParser != null
        	  *    init'ed(this.myParser.nNextKeyPrefix)
        	  *    init'ed(this.nModes)
        	  *    (soft) this.myParser.hPrefixMap != null
        	  *    (soft) this.myParser.hPrefixModes != null
        	  * 
        	  *  Postconditions:
        	  *    java.lang.StringBuilder:toString(...)._tainted == this.cClient.sNickname._tainted
        	  *    init'ed(java.lang.StringBuilder:toString(...)._tainted)
        	  *    return_value == &amp;java.lang.StringBuilder:toString(...)
        	  */
   206  	public String toFullString() { return this.getChanModeStr(true) + this.getNickname(); }	
   207  
   208  }
   209  








SofCheck Inspector Build Version : 2.17854
ChannelClientInfo.java 2009-Jun-25 01:54:24
ChannelClientInfo.class 2009-Sep-02 17:04:12