View.java 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package navigators.smart.reconfiguration;

import java.io.Serializable;
import java.util.Arrays;
10 11 12
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
13 14 15 16 17 18 19

/**
 *
 * @author eduardo
 */
public class View implements Serializable {

20 21 22 23
	private int id;
 	private int f;
 	private int[] processes;
 	private Map<Integer,InetSocketAddress> addresses;
24

25 26 27 28
 	public View(int id, int[] processes, int f, InetSocketAddress[] addresses){
 		this.id = id;
 		this.processes = processes;
 		this.addresses = new HashMap<Integer, InetSocketAddress>();
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
 		for(int i = 0; i < this.processes.length;i++)
 			this.addresses.put(processes[i],addresses[i]);
 		Arrays.sort(this.processes);
 		this.f = f;
 	}

 	public boolean isMember(int id){
 		for(int i = 0; i < this.processes.length;i++){
 			if(this.processes[i] == id){
 				return true;
 			}
 		}
 		return false;
 	}


 	public int getPos(int id){
 		for(int i = 0; i < this.processes.length;i++){
 			if(this.processes[i] == id){
 				return i;
 			}
 		}
 		return -1;
 	}

 	public int getId() {
 		return id;
 	}

 	public int getF() {
 		return f;
 	}

 	public int getN(){
 		return this.processes.length;
 	}

 	public int[] getProcesses() {
 		return processes;
 	}

 	@Override
 	public String toString(){
 		String ret = "ID:"+id+"; F:"+f+"; Processes:";
 		for(int i = 0; i < processes.length;i++){
 			ret = ret+processes[i]+"("+addresses.get(processes[i])+"),";
 		}

 		return ret;
 	}
 	public InetSocketAddress getAddress(int id) {
 		return addresses.get(id);
 	}
83 84
    
}