/* * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For questions, comments etc, * use the website at http://jeti.jabberstudio.org * or mail/IM me at jeti@jabber.org * */ package nu.fw.jeti.backend.roster; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import nu.fw.jeti.jabber.JIDStatus; /** *
Copyright: Copyright (c) 2001
* @author E.S. de Boer */ public class PrimaryJIDStatus implements Comparable //implements JIDStatus {//contains secondary jidstatussen (resource + same nick) private JIDStatus primaryJIDStatus; private List jidStatussen; private String nick; private boolean online=false; public PrimaryJIDStatus(String nick,JIDStatus primaryJIDStatus) { this.nick = nick; this.primaryJIDStatus = primaryJIDStatus; } // public boolean isEmpty() // { // return isEmpty; // } public boolean hasMultiple() { return jidStatussen != null; } public boolean isAJIDstatusOffline() { if(!primaryJIDStatus.isOnline()) return true; if(jidStatussen == null) return false; for(Iterator i = jidStatussen.iterator();i.hasNext();) { if(!((JIDStatus)i.next()).isOnline()) return true; } return false; } public boolean multipleJIDstatusOnline() { if(!primaryJIDStatus.isOnline()) return false; if(jidStatussen == null) return false; for(Iterator i = jidStatussen.iterator();i.hasNext();) { if(((JIDStatus)i.next()).isOnline()) return true; } return false; } public void addJIDStatus(JIDStatus jidStatus) { // if(primaryJIDStatus == null) // { // primaryJIDStatus = jidStatus; // //return true; // } // else // { if(jidStatussen == null) jidStatussen = new ArrayList(8); jidStatussen.add(jidStatus); Collections.sort(jidStatussen); //return false; //} } public boolean removeJIDStatus(JIDStatus jidStatus) {//returns true if primaryJIDStatus is now empty if(primaryJIDStatus == jidStatus) { if(jidStatussen == null) { //primaryJIDStatus = null; return true; } else if(jidStatussen.size() == 1) { primaryJIDStatus = (JIDStatus)jidStatussen.get(0); jidStatussen =null; } else {//jidstatussen sorted so first will be new primary primaryJIDStatus = (JIDStatus)jidStatussen.remove(0); } return false; } jidStatussen.remove(jidStatus); if (jidStatussen.size() == 0) jidStatussen = null; return false; } public void updatePresence(SecondaryJIDStatus jidStatus) { if(jidStatussen != null) Collections.sort(jidStatussen); if(jidStatus == primaryJIDStatus) {//check of secondery jids better then primary if(jidStatussen == null) return; //jidstatussen sorted so only first checked checkVolgorde((JIDStatus) getJIDStatus(0)); /* for(Iterator i = jidStatussen.iterator();i.hasNext();) { JIDStatus2 temp = (JIDStatus2)i.next(); checkVolgorde(jidGroup, temp, backend); } */ } else checkVolgorde(jidStatus); } public void updateOnline() { online = primaryJIDStatus.isOnline(); } private void checkVolgorde(JIDStatus jidStatus) { if(primaryJIDStatus.compareTo(jidStatus) > 0) { int index = jidStatussen.indexOf(jidStatus); jidStatussen.set(index,primaryJIDStatus); primaryJIDStatus = jidStatus; Collections.sort(jidStatussen);//sort new list } } public JIDStatus getJIDPrimaryStatus() { // if(primaryJIDStatus == null) // {//jidstatus is removed from group before from gui so use a dummy until removed from gui // //System.out.println("Primary jids null"); // return new NormalJIDStatus(new JID("test","test") ,nick); // } return primaryJIDStatus; } public Object getJIDStatus(int index) { return jidStatussen.get(index); } public int indexOfJIDStatus(Object jidStatus) { return jidStatussen.indexOf(jidStatus); } public int size() { if(jidStatussen == null) return 0; return jidStatussen.size(); } public Iterator getOtherJidStatussen() { return new ArrayList(jidStatussen).iterator(); } public String toString() { //return nick;// return primaryJIDStatus.toString(); } public int compareTo(Object o) {//compare jid //if(nickname==null) return -1; return nick.compareTo(((PrimaryJIDStatus)o).nick); } //-------------------JIStatus implementation--------------------\\ // public JID getJID(){return primaryJIDStatus.getJID();} // // public JID getCompleteJID(){return primaryJIDStatus.getCompleteJID();} // public boolean isOnline() { return online; } // // public int getShow() // { // return primaryJIDStatus.getShow(); // } // // public String getStatus() // { // return primaryJIDStatus.getStatus(); // } // public String getNick() { return nick; } // // public String getType() // { // return primaryJIDStatus.getType(); // } // // public String getSubscription(){return primaryJIDStatus.getSubscription();} // // public String getWaiting() // { // return primaryJIDStatus.getWaiting(); // } // // public StringArray getGroupsCopy(){return primaryJIDStatus.getGroupsCopy();} // // public int groupCount(){return primaryJIDStatus.groupCount();} // // public boolean isGroupPresent(String group){return primaryJIDStatus.isGroupPresent(group);} } /* * Overrides for emacs * Local variables: * tab-width: 4 * End: */