/
RTab.java
170 lines (145 loc) · 6.27 KB
/
RTab.java
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
package com.cpjd.roblu.models;
import android.support.annotation.NonNull;
import com.cpjd.roblu.models.metrics.RMetric;
import com.cpjd.roblu.utils.MatchType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.regex.Pattern;
import lombok.Data;
/**
* This class stores information about either PIT, Prediction, or Match data.
* It represents one physical instance of a form to represent a match tab, a predictions tab, or pit tab
*
* @version 2
* @since 3.5.0
* @author Will Davies
*/
@Data
public class RTab implements Serializable, Comparable<RTab> {
/**
* Changing this versionUID will render this class incompatible with older versions.
*/
public static final long serialVersionUID = 1L;
/**
* RTabs are identified by their title, no duplicate titles!
*/
private String title;
/**
* Stores metrics and data for each metric
*/
private ArrayList<RMetric> metrics;
/**
* FALSE for blue alliance, TRUE for red alliance
*/
private boolean redAlliance;
/**
* This is a helper variable for teams who use the Red Device, Blue Device, etc. scouting system.
* This variable can only be imported from the TBA.
* Values 1-3 represent red alliance, 4-6 represent Blue alliance position.
* However, use the redAlliance variable for display colors, because that's what the user can
* change and modify. This should ONLY be used for sorting the4 Red Device, Blue Device checkout order.
*/
private int alliancePosition;
/**
* Whether this match has been one, not applicable for PIT or PREDICTIONS
*/
private boolean won;
/**
* The time this match will occur (Unix time), not applicable for PIT or PREDICTIONS
*/
private long time;
/**
* Non-crucial data that stores a list of all edits made to this tab in the format <editor-name, timestamp>
*/
private LinkedHashMap<String, Long> edits;
/*
* These are variables to assist with sorting, it makes sorting way, way faster.
*/
private MatchType matchType;
private int matchOrder = 0;
private int subMatchOrder = 0;
private int teamOrder = 0;
/*
* Roblu Scouter ONLY helper variables
*/
/**
* Used for displaying some helpful information in the MyMatches view
* @see com.cpjd.roblu.ui.mymatches.MyMatches
*/
private ArrayList<RTeam> teammates, opponents;
/**
* The empty constructor is required for de-serialization
*/
@SuppressWarnings("unused")
public RTab() {}
/**
* Creates a RTab model, or a representation of a pit, predictions, or match tab
* @param teamNumber only required for sorting, 0 is an OKAY input here
* @param title unique title identifier
* @param metrics elements and their included data for this tab
* @param redAlliance false for blue alliance, true for red
* @param won whether this match is won
* @param time millisecond timestamp for when this match is scheduled for
*/
public RTab(int teamNumber, String title, ArrayList<RMetric> metrics, boolean redAlliance, boolean won, long time) {
this.metrics = metrics;
this.title = title;
this.redAlliance = redAlliance;
this.won = won;
this.time = time;
this.alliancePosition = -1; // default to not found
// Process MatchType
String matchName = "team# "+teamNumber+" "+title.toLowerCase().trim();
String[] tokens = matchName.split("\\s+");
matchType = MatchType.getByName(tokens[2]);
if(matchType.hasMatchOrder()) matchOrder = Integer.parseInt(tokens[3]);
if(matchType.hasSubmatches()) subMatchOrder = Integer.parseInt(tokens[5]);
teamOrder = Integer.parseInt(tokens[1]);
}
@Override
public int compareTo(@NonNull RTab tab) {
// Matches are different in some way
if(this.matchType == tab.getMatchType()) {
// Matches are exactly identical, sort by team number then
if(this.matchOrder == tab.getMatchOrder() && this.subMatchOrder == tab.getSubMatchOrder()) return (this.getTeamOrder() - tab.getTeamOrder());
if(this.matchOrder == tab.getMatchOrder()) return ((this.subMatchOrder) - (tab.getSubMatchOrder()));
else return ((this.matchOrder) - (tab.getMatchOrder()));
}
else return ((this.matchType.getMatchTypeOrder()) - (tab.getMatchType().getMatchTypeOrder()));
}
@Override
public boolean equals(Object other) {
return (other instanceof RTab) &&
(((RTab) other).getMatchType() == this.matchType) &&
(((RTab) other).getMatchOrder() == this.matchOrder);
}
public boolean getSimpleMatchString(String match) {
try {
String adj = (title.toLowerCase().replaceAll("\\s+", "").replaceAll("Quals", "q").replaceAll("Quarters", "qu")
.replaceAll("Semis", "s").replaceAll("Finals", "f").replaceAll("Match", "m")).replace("predictions", "p");
if(match.equals("pit") && adj.equals("pit")) return true;
if(match.equals("p") && adj.equals("p")) return true;
Pattern category = Pattern.compile("[a-zA-Z]+");
Pattern specific = Pattern.compile("[a-zA-Z]+\\d+");
Pattern specific2 = Pattern.compile("[a-zA-Z]+\\d+[a-zA-Z]+\\d+");
if(category.matcher(match).matches()) {
if(match.equals("qu") | match.equals("s")) match += "m";
return adj.replaceAll("\\d+", "").equalsIgnoreCase(match);
}
else if(specific.matcher(match).matches() || specific2.matcher(match).matches())
return adj.equalsIgnoreCase(match);
else { // range
int low = Integer.parseInt(match.substring(match.indexOf("(") + 1, match.indexOf("-")));
int high = Integer.parseInt(match.substring(match.indexOf("-") + 1, match.indexOf(")")));
if(low > high || (low < 0 || high < 0)) return false;
for(int i = low; i <= high; i++) {
if(match.replaceAll("\\(\\d+-\\d+\\)", String.valueOf(i)).equalsIgnoreCase(adj)) return true;
}
}
} catch(Exception e) {
e.printStackTrace();
}
return false;
}
}