-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d81748
commit 9f4953f
Showing
14 changed files
with
336 additions
and
13 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package lab2; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Hashtable; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
|
||
public class GroupsRpg { | ||
public Hashtable<String, Hashtable <String, Integer>> groups = new Hashtable<String, Hashtable <String, Integer>> (); | ||
|
||
public GroupsRpg(){} | ||
public GroupsRpg(Object groups){ | ||
ArrayList<Object> groupList = (ArrayList<Object>) groups; | ||
for(Object group : groupList){ | ||
String groupName = null; | ||
ArrayList<String> groupMem = new ArrayList<String>(); | ||
Map<String, Object> groupInfo = (Map<String, Object>) group; | ||
for (Map.Entry<String, Object> entry : groupInfo.entrySet()){ | ||
Object value = entry.getValue(); | ||
String key = entry.getKey(); | ||
if("name".equals(key)){ | ||
groupName = (String) value; | ||
} | ||
else if("members".equals(key)){ | ||
groupMem = (ArrayList<String>) value; | ||
} | ||
else{ | ||
System.out.println("ERROR IN GROUP FILE"); | ||
} | ||
|
||
Hashtable <String, Integer> Rpg = new Hashtable<String, Integer>(); | ||
for(String tmp : groupMem){ | ||
Rpg.put(tmp, 0); | ||
} | ||
|
||
this.groups.put(groupName, Rpg); | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
public GroupsRpg deepCopy(){ | ||
GroupsRpg copy = new GroupsRpg(); | ||
for(String key : this.groups.keySet()){ | ||
copy.groups.put(key, new Hashtable<String, Integer> (this.groups.get(key))); | ||
} | ||
return copy; | ||
} | ||
|
||
|
||
public Hashtable <String, Integer> getGroupByName(String groupName){ | ||
return this.groups.get(groupName); | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
String toString = "{\n"; | ||
for (Entry<String, Hashtable<String, Integer>> entry : this.groups.entrySet()) { | ||
Hashtable<String, Integer> tmp = entry.getValue(); | ||
toString += entry.getKey() + ":"; | ||
Object [] arrMem = tmp.keySet().toArray(); | ||
Arrays.sort(arrMem); | ||
for(int i = 0; i < arrMem.length; i++){ | ||
toString += "[" + arrMem[i] + ": " + entry.getValue().get(arrMem[i]) + "] "; | ||
} | ||
//toString += tmp.keySet().toString(); | ||
toString += "\n"; | ||
} | ||
toString += "}\n"; | ||
return toString; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package lab2; | ||
|
||
import java.io.Serializable; | ||
import java.util.Hashtable; | ||
|
||
public class MulticastMessage extends Message implements Serializable{ | ||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = 403804568197137128L; | ||
protected Clock timeStamp; | ||
private boolean concurrent; | ||
private String groupName; | ||
protected Hashtable <String, Integer> acknowledgement = null; | ||
|
||
|
||
public MulticastMessage(){}; | ||
public MulticastMessage(String dest, String kind, Object data, Clock timeStamp){ | ||
super(dest, kind, data); | ||
this.timeStamp = timeStamp; | ||
this.concurrent = false; | ||
this.groupName = null; | ||
} | ||
|
||
public MulticastMessage(Message originalMessage, String gName, Clock timeStamp, Hashtable <String, Integer> Rpg){ | ||
this.source = originalMessage.source; | ||
this.dest = originalMessage.dest; | ||
this.kind = originalMessage.kind; | ||
this.seqNum = originalMessage.seqNum; | ||
this.duplicate = originalMessage.duplicate; | ||
this.data = originalMessage.data; | ||
this.timeStamp = timeStamp; | ||
this.groupName = gName; | ||
this.concurrent = false; | ||
for(String tmpKey : Rpg.keySet()){ | ||
this.acknowledgement.put(tmpKey, Rpg.get(tmpKey)); | ||
} | ||
} | ||
|
||
public MulticastMessage(TimeStampedMessage originalMessage, Hashtable <String, Integer> Rpg) { | ||
this.source = originalMessage.source; | ||
this.dest = originalMessage.dest; | ||
this.kind = originalMessage.kind; | ||
this.seqNum = originalMessage.seqNum; | ||
this.duplicate = originalMessage.duplicate; // * Important | ||
this.data = originalMessage.data; // clone? | ||
this.concurrent = false; | ||
this.timeStamp = originalMessage.timeStamp; | ||
for(String tmpKey : Rpg.keySet()){ | ||
this.acknowledgement.put(tmpKey, Rpg.get(tmpKey)); | ||
} | ||
} | ||
|
||
public MulticastMessage(MulticastMessage originalMessage) { | ||
this.source = originalMessage.source; | ||
this.dest = originalMessage.dest; | ||
this.kind = originalMessage.kind; | ||
this.seqNum = originalMessage.seqNum; | ||
this.groupName = originalMessage.groupName; | ||
this.duplicate = originalMessage.duplicate; // * Important | ||
this.data = originalMessage.data; // clone? | ||
this.concurrent = true; | ||
this.timeStamp = originalMessage.timeStamp; | ||
this.acknowledgement = originalMessage.acknowledgement; | ||
} | ||
|
||
public void setConcurrent(){ | ||
this.concurrent = true; | ||
} | ||
|
||
public boolean getConcurrent(){ | ||
return this.concurrent; | ||
} | ||
|
||
public void setGroupName(String gName){ | ||
this.groupName = gName; | ||
} | ||
|
||
public String getGroupName(){ | ||
return this.groupName; | ||
} | ||
|
||
|
||
|
||
public void setTimeStamp(Clock hostTimeStamp){ | ||
this.timeStamp = hostTimeStamp; | ||
} | ||
|
||
public Clock getTimeStamp(){ | ||
return this.timeStamp; | ||
} | ||
|
||
public Hashtable <String, Integer> getAcknowledgement(){ | ||
return this.acknowledgement; | ||
} | ||
|
||
public void setAcknowledgement(Hashtable <String, Integer> Rpg){ | ||
for(String key : Rpg.keySet()){ | ||
this.acknowledgement.put(key, Rpg.get(key)); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Message["+ source +"->"+ dest +" seqNum:"+ seqNum +" duplicate:"+ duplicate +" kind:"+ kind | ||
+" data:"+ data +" \nTimeStamp:" + this.timeStamp + " \nAcknowledgement:" + this.acknowledgement + "]\n"; | ||
} | ||
} |
Oops, something went wrong.