use of com.cpjd.roblu.models.metrics.RTextfield in project Roblu by wdavies973.
the class CheckoutEncoder method encodeCheckout.
/**
* This method will encode a checkout with as little overhead as possible (as opposed to JSON
* serialization). This method is used for QR serialization to minimize the data transfer, since
* compression isn't supported well by QR. This could be expanded for the whole project, but isn't really versatile enough yet.
* @return The encoded string
*/
public String encodeCheckout(String nameTag, RCheckout checkout) {
StringBuilder builder = new StringBuilder();
// Checkout components
builder.append(checkout.getID()).append("\n");
builder.append(nameTag).append("\n");
// Team meta
builder.append(checkout.getTeam().getID()).append("\n");
builder.append(checkout.getTeam().getLastEdit()).append("\n");
// Tabs!
for (RTab tab : checkout.getTeam().getTabs()) {
builder.append("TAB").append(tab.getTitle()).append("\n");
builder.append(tab.isWon()).append("\n");
// Edits
builder.append("EDITS");
if (tab.getEdits() != null) {
for (Object o : tab.getEdits().keySet()) {
builder.append(",");
if (o.toString().equals(""))
builder.append("Unknown");
else
builder.append(o.toString());
// EDITS,will:120391823,john,12039123
builder.append(",").append(tab.getEdits().get(o.toString()));
}
}
builder.append("\n");
// -RDivider and RCalculation don't need to be encoded since they don't contain any user information
for (RMetric metric : tab.getMetrics()) {
builder.append(getMetricType(metric)).append(DELIMITER).append(metric.getID()).append(DELIMITER).append(metric.getTitle()).append(DELIMITER).append(metric.isModified()).append(DELIMITER);
if (metric instanceof RBoolean)
builder.append(((RBoolean) metric).isValue());
else if (metric instanceof RCheckbox) {
if (((RCheckbox) metric).getValues() != null) {
for (Object o : ((RCheckbox) metric).getValues().keySet()) {
// :(title,value):(title,value):
builder.append("(").append(o.toString()).append(",").append(((RCheckbox) metric).getValues().get(o.toString())).append(")").append(DELIMITER);
}
}
} else if (metric instanceof RChooser) {
builder.append(((RChooser) metric).getSelectedIndex()).append(DELIMITER);
if (((RChooser) metric).getValues() != null) {
for (String s : ((RChooser) metric).getValues()) {
// :1:option:option:option:
builder.append(s).append(DELIMITER);
}
}
} else if (metric instanceof RCounter)
builder.append(((RCounter) metric).isVerboseInput()).append(DELIMITER).append(((RCounter) metric).getValue()).append(DELIMITER).append(((RCounter) metric).getIncrement());
else if (metric instanceof RSlider)
builder.append(((RSlider) metric).getValue()).append(DELIMITER).append(((RSlider) metric).getMin()).append(DELIMITER).append(((RSlider) metric).getMax());
else if (metric instanceof RStopwatch) {
builder.append(((RStopwatch) metric).getTime()).append(DELIMITER);
if (((RStopwatch) metric).getTimes() != null) {
for (Double t : ((RStopwatch) metric).getTimes()) {
// :curr:1:2:3:
builder.append(t).append(DELIMITER);
}
}
} else if (metric instanceof RTextfield)
builder.append(((RTextfield) metric).getText());
builder.append("\n");
}
}
return builder.toString();
}
use of com.cpjd.roblu.models.metrics.RTextfield in project Roblu by wdavies973.
the class Utils method createEmpty.
/**
* Creates an empty form for an event (not technically empty).
*
* Makes sure that nothing is null and that we have the required
* team name and team number fields
* @return creates an empty RForm
*/
public static RForm createEmpty() {
ArrayList<RMetric> pit = new ArrayList<>();
ArrayList<RMetric> matches = new ArrayList<>();
RTextfield name = new RTextfield(0, "Team name", false, true, "");
RTextfield number = new RTextfield(1, "Team number", true, true, "");
pit.add(name);
pit.add(number);
return new RForm(pit, matches);
}
Aggregations