my code stock.com

Snippet options

Download: Download snippet as messenger.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

public class Group extends Contact{
    private String groupname;
    private Contact[] contactos;
    
    public Group(String grupo){
        super(grupo);
        contactos = new Contact[50];
        
    }
    
    public boolean isMember(int id){
        for (int i = 0; i < contactos.length;i++){
            if (contactos[i] != null){
                if (contactos[i].id == id){
                    return true;
                }
            }
        }
        return false;
    }
    public boolean add(Contact con){
        if (isMember(con.id)){
            return false;
        }else{
            for (int i = 0; i < contactos.length; i++){
                if (contactos[i] == null){
                    contactos[i] = con;
                    return true;
                }
            }
        }
        Contact[] aux = new Contact[contactos.length+1];
        System.arraycopy(contactos,0, aux,0,contactos.length);
        aux[aux.length-1] = con;
        contactos = aux;
        return true;
    }
    
    public boolean remove(int con){
        int idn = 0;
        for (int i = 0; i < contactos.length; i++){
            if (contactos[i].id == con){
                idn = i;
                break;
            }
        }
        
        if (contactos[idn] instanceof Group == false){
            if (isMember(con)){
                for (int i = 0; i < contactos.length; i++){
                    if (contactos[i].id == con){
                        contactos[i] = null;
                        return true;
                    }
                }
                return true;
            }else{
                return false;
            }
        }else{
            return true;
        }
    }
    
    public Contact[] getContacts(){
        Contact[] aux;
        int count = 0;
        for (int i = 0; i < contactos.length; i++){
            if (contactos[i] == null){
                count++;
            }
        }
        int tamaño = 50 - count;
        aux = new Contact[tamaño];
        for (int i = 0; i < tamaño; i++){
            for (int j = 0 ; j < contactos.length; j++){
                if (contactos[j] != null){
                    aux[i] = contactos[j];
                }
            }
        }
        return aux;
    }
    
    
    public void sendSMS(String mensaje) {}
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.