Skip to content

Commit

Permalink
doneBy in Equation is now ArrayList instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
groowyCZ committed Feb 24, 2019
1 parent c209b10 commit 1ffe543
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
33 changes: 24 additions & 9 deletions LaTeX/src/latex/Equation.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package latex;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

/**
Expand All @@ -11,25 +13,38 @@ public class Equation {
private String result;
private String comment;
private String category;
private String doneBy;
private ArrayList<String> doneBy;

private String listToString(ArrayList<String> list, String sep){
String str = "";
for (int i = 0; i < list.size() - 1; i++) {
str += list.get(i) + sep;
}str += list.get(list.size() - 1);
return str;
}

private ArrayList<String> stringToList(String str, String sep){
ArrayList<String> list = new ArrayList(Arrays.asList(str.split(sep)));
return list;
}

public Equation(){
this.equation = "";
this.result = "";
this.comment = "";
this.category = "";
this.doneBy = "";
this.doneBy = new ArrayList();
}

public Equation(String equation, String result, String comment, String category, String doneBy){
public Equation(String equation, String result, String comment, String category, ArrayList<String> doneBy){
this.equation = equation;
this.result = result;
this.comment = comment;
this.category = category;
this.doneBy = doneBy;
}

public Equation(HashMap<String, String> equationHashMap){
public Equation(HashMap<String, String> equationHashMap, String sep){

// FIELDS
String equation = equationHashMap.get("body");
Expand All @@ -41,19 +56,19 @@ public Equation(HashMap<String, String> equationHashMap){
String category = equationHashMap.get("category");
this.category = (category == null ? "" : category);
String doneBy = equationHashMap.get("done_by");
this.doneBy = (doneBy == null ? "" : doneBy);
this.doneBy = (doneBy == null ? new ArrayList() : stringToList(doneBy, sep));
}

/**
* @return the equationHashMap
*/
public HashMap<String, String> asHashMap() {
public HashMap<String, String> asHashMap(String sep) {
HashMap<String, String> equationHashMap = new HashMap();
equationHashMap.put("body", this.equation);
equationHashMap.put("result", this.result);
equationHashMap.put("comment", this.comment);
equationHashMap.put("category", this.category);
equationHashMap.put("done_by", this.doneBy);
equationHashMap.put("done_by", listToString(this.doneBy, sep));
return equationHashMap;
}

Expand Down Expand Up @@ -116,14 +131,14 @@ public void setCategory(String category) {
/**
* @return the doneBy
*/
public String getDoneBy() {
public ArrayList<String> getDoneBy() {
return this.doneBy;
}

/**
* @param doneBy the doneBy to set
*/
public void setDoneBy(String doneBy) {
public void setDoneBy(ArrayList<String> doneBy) {
this.doneBy = doneBy;
}
}
5 changes: 3 additions & 2 deletions LaTeX/src/latex/Latex.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
public class Latex {

static final String STRING_LIST_SEPARATOR = ", ";
static final char SEPARATOR = System.getProperty("user.dir").contains("/") ? '/' : '\\';
static String EQUATIONS_PATH = System.getProperty("user.dir") + Latex.SEPARATOR + "equations.xml";

Expand Down Expand Up @@ -70,7 +71,7 @@ public static void writeEquations(ArrayList<String> classes, ArrayList<String> c

// EQUATIONS
for (Equation tmp : equations) {
HashMap<String, String> equation = tmp.asHashMap();
HashMap<String, String> equation = tmp.asHashMap(STRING_LIST_SEPARATOR);
ArrayList<String> keys = new ArrayList(equation.keySet());
writer.writeStartElement("equation");
for (String key : keys) {
Expand Down Expand Up @@ -125,7 +126,7 @@ public static ArrayList<Equation> loadEquations() throws XMLStreamException, Fil
}
}

equations.add(new Equation(equationHashMap));
equations.add(new Equation(equationHashMap, STRING_LIST_SEPARATOR));
}
}
}
Expand Down
29 changes: 6 additions & 23 deletions LaTeX/src/windows/EquationStateEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package windows;

import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.table.DefaultTableModel;

/**
Expand All @@ -19,14 +18,12 @@ public class EquationStateEditor extends javax.swing.JDialog {
* Creates new form EquationStateEditor
*
* @param classes
* @param _doneBy
* @param doneBy
*/
public EquationStateEditor(ArrayList<String> classes, String _doneBy) {
public EquationStateEditor(ArrayList<String> classes, ArrayList<String> doneBy) {
super(new javax.swing.JFrame(), true);
initComponents();
Object[][] tableData = new Object[classes.size()][2];
ArrayList<String> doneBy = new ArrayList();
doneBy.addAll(Arrays.asList(_doneBy.split(", ")));
for (int i = 0; i < classes.size(); i++) {
tableData[i][0] = classes.get(i);
tableData[i][1] = doneBy.contains(classes.get(i));
Expand All @@ -52,17 +49,14 @@ public boolean isCellEditable(int rowIndex, int columnIndex) {
classTable.setModel(model);
}

public String getDoneBy() {
String doneBy = "";
public ArrayList<String> getDoneBy() {
ArrayList<String> doneBy = new ArrayList();
int size = classTable.getModel().getRowCount();
for (int i = 0; i < size - 1; i++) {
for (int i = 0; i < size; i++) {
if ((boolean) classTable.getModel().getValueAt(i, 1)) {
doneBy += classTable.getModel().getValueAt(i, 0) + ", ";
doneBy.add((String)classTable.getModel().getValueAt(i, 0));
}
}
if ((boolean) classTable.getModel().getValueAt(size - 1, 1)) {
doneBy += classTable.getModel().getValueAt(size - 1, 0);
}
return doneBy;
}

Expand Down Expand Up @@ -143,17 +137,6 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
this.setVisible(false);
this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

public static void main(String[] args) {
ArrayList<String> classes = new ArrayList();
classes.add("1.D");
classes.add("2.D");
classes.add("3.D");
EquationStateEditor editor = new EquationStateEditor(classes, "1.D, 3.D");
editor.setVisible(true);
System.out.println(editor.getDoneBy());
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTable classTable;
private javax.swing.JButton jButton1;
Expand Down

0 comments on commit 1ffe543

Please sign in to comment.