-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDating.java
More file actions
306 lines (256 loc) · 7.41 KB
/
Dating.java
File metadata and controls
306 lines (256 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package speedmatch;
import java.util.HashMap;
import javax.swing.JOptionPane;
import java.awt.Desktop;
import java.io.*;
/**
*
* @author Jochen
*
*/
public class Dating implements java.io.Serializable{
private int max_part;
private int counter=1;
private int max_match;
private int gender1;
private int gender2;
private String eventname;
private HashMap<Integer, Participant> ptable;
private HashMap<Integer, NetParticipant> nptable;
private int disc_rounds;
private boolean netevent = false;
//Constructor Likes Matching
public Dating(int maxpart, int maxmatch, String name, int g1, int g2) {
this.eventname = name;
this.max_part = maxpart;
this.max_match = maxmatch;
this.ptable = new HashMap<>(maxpart);
this.gender1 = g1;
this.gender2 = g2;
}
//Constructor Discussion Matching
public Dating(int maxpart, int maxmatch, String name, int g1, int g2, int disc) {
this.eventname = name;
this.max_part = maxpart;
this.max_match = maxmatch;
this.nptable = new HashMap<>(maxpart);
this.gender1 = g1;
this.gender2 = g2;
this.disc_rounds= disc;
netevent = true;
}
//Adds Participant to Dating (if a free place is left)
public int addParticipant(String firstname, String lastname, int gender) throws MatchException{
if(counter <= max_part){
Participant p = new Participant(firstname, lastname, gender, counter, max_match);
this.ptable.put(this.counter, p);
this.counter++;
return this.counter-1;
}
throw new MatchException("You exceeded the maximum number of participants");
}
//Adds NetParticipant to Dating (if a free place is left)
public int addParticipant(int id, String firstname, String lastname, int gender,
String fa, String dik,String ereig, String feier, String rev) throws MatchException{
if(counter <= max_part){
NetParticipant p = new NetParticipant(firstname, lastname, gender, id, max_match, max_part, fa, dik, ereig, feier, rev);
this.nptable.put(this.counter, p);
this.counter++;
return this.counter-1;
}
throw new MatchException("You exceeded the maximum number of participants");
}
// Adds a single like to a participant
public void addLikes(int key, int like) throws MatchException{
this.ptable.get(key).addMatch(like);
}
//Add Methoden f�r NetParticipants?
// Same as above, but adds All likes at once
public void addLikes(int key, int[] likearr) throws MatchException{
if(netevent) {
if(nptable.containsKey(key)) {
this.nptable.get(key).addMatch(likearr);
}
else {
throw new MatchException("Invalid ID "+key);
}
}
else {
if(ptable.containsKey(key)) {
this.ptable.get(key).addMatch(likearr);
}
else {
throw new MatchException("Invalid ID: "+key);
}
}
}
//Creates scores for Participants
public void computeScores() {
int sc=50;
// reset discussion array
for (int j=1; j<counter; j++)
for (int i=0; i<this.max_part; i++) {
this.nptable.get(j).getDiscuss()[i][0]=-2;
this.nptable.get(j).getDiscuss()[i][1] = 0;
}
// i = Participant whose scores are added
for(int i=1; i<counter; i++) {
//j = Participant whose matching score to i is computed
for(int j=1; j<counter; j++) {
if(i!=j) { //no match with itself
if(this.nptable.get(i).getFach()!= this.nptable.get(j).getFach()) {
sc+=5;
}
else {sc-=10;}
if(this.nptable.get(i).getDiktator()== this.nptable.get(j).getDiktator()) {
sc+=10;
}
else {sc-=5;}
if(this.nptable.get(i).getEreignis()!= this.nptable.get(j).getEreignis()) {
sc+=5;
}
else {sc-=10 ;}
if(this.nptable.get(i).getFeierbuddy()== this.nptable.get(j).getFeierbuddy()) {
sc+=10;
}
else {sc-=5;}
if(this.nptable.get(i).getRevolution()== this.nptable.get(j).getRevolution()) {
sc+=10;
}
else {sc-=5;}
// Adds Discussion Partners with corresponding scores to Participant
this.nptable.get(i).addPartner(this.nptable.get(j).getID(), sc);
sc=50;
}
}
}
}
// Adds the most recently added Participant to a list of participants in
// a specified directory
public void addToFile(String path){
String filename = path+this.eventname +"_list.txt";
File participants= new File(filename);
String nl = Processing.getLineSep();
if (!participants.exists()){
try{
participants.createNewFile();
FileWriter fw= new FileWriter(participants);
BufferedWriter bw= new BufferedWriter(fw);
StringBuilder sb = new StringBuilder();
sb.append("Event Name: " + this.eventname +nl+nl+"Participant"+nl);
if(!netevent) {
sb.append(this.ptable.get(counter-1).toString());
}
else {
sb.append(this.nptable.get(counter-1).toString());
}
String p = sb.toString();
bw.write(p);
bw.flush();
bw.close();
}
catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "ERROR: File not Found", JOptionPane.ERROR_MESSAGE);
}
catch(IOException o){
JOptionPane.showMessageDialog(null, "Error: "+o.getMessage(),"ERROR", JOptionPane.ERROR_MESSAGE);
}
}
else{
FileReader fr;
try {
fr = new FileReader(participants);
BufferedReader br= new BufferedReader(fr);
StringBuilder sb= new StringBuilder();
String s;
while ((s = br.readLine())!= null){
sb.append(s+nl);
}
FileWriter fw= new FileWriter(participants);
BufferedWriter bw= new BufferedWriter(fw);
String p;
if(!netevent) {
p = this.ptable.get(counter-1).toString();
}
else {
p= this.nptable.get(counter-1).toString();
}
sb.append(p);
bw.write(sb.toString());
bw.close();
br.close();
fr.close();
fw.close();
}
catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null, "Error: "+ex.getMessage(), "ERROR: File not Found", JOptionPane.ERROR_MESSAGE);
}
catch(IOException o){
JOptionPane.showMessageDialog(null, "Error: "+o.getMessage(),"ERROR", JOptionPane.ERROR_MESSAGE);
}
}
}
// Same as above, but with default directory
public void addToFile() {
addToFile(Processing.getHomeDir());
}
//Clear hashtables (Caution: Nuclear option)
public void clearParticipants() {
this.counter = 1;
if(netevent) {
nptable.clear();
try {
String td = System.getProperty("java.io.tmpdir")+Processing.getPathSep();
File f = new File(td+eventname+"_list.txt");
if(f.exists()) {
if(f.canWrite()) {
f.delete();
}
}
}catch(Exception e) {
JOptionPane.showMessageDialog(null, "Error: "+e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
else {
ptable.clear();
}
}
// Get-Functions for private variables
public HashMap<Integer, Participant> getParticipants(){
return this.ptable;
}
public HashMap<Integer, NetParticipant> getNetParticipants(){
return this.nptable;
}
public int getCurrentParts(){
return this.counter-1;
}
public int getCounter() {
return this.counter;
}
public int getMaxMatch(){
return this.max_match;
}
public int getMaxPart(){
return this.max_part;
}
public String getName() {
return this.eventname;
}
public int[] getGender() {
int[] garr = new int[2];
garr[0] = this.gender1;
garr[1] = this.gender2;
return garr;
}
public int getDiscRounds() {
return this.disc_rounds;
}
public boolean getNet() {
return netevent;
}
public String toString(){
String nl = Processing.getLineSep();
return "Event Name: " + this.eventname +nl+nl+"Participant\t\t\tMatched with"+nl;
}
}