ProjektGraph/visualizationElements/List.java
2024-07-02 21:13:30 +02:00

70 lines
1.3 KiB
Java

package visualizationElements;
import java.awt.*;
import java.util.Vector;
/**
* Represents the abstract data type List.
* @author MSchaefer
*
*/
public class List extends Table {
/**
* Creates a new List.
* @param values The values of the list.
*/
public List(Vector<?> values) {
super(null, values.size(), 1);
Object[][] tableArray = createTableArray(values);
super.setValues(tableArray);
}
/**
* Creates a new List.
* @param values The values of the list.
*/
public List(Object[] values) {
super(null, values.length, 1);
Object[][] tableArray = new Object[1][values.length];
int i = 0;
for(Object o : values){
tableArray[0][i] = o;
i++;
}
super.setValues(tableArray);
}
/* (non-Javadoc)
* @see visualizationElements.VisualizationElement#draw()
*/
@Override
public void draw(Graphics g) {
super.draw(g);
}
/**
* Creates the array to visualize as list out from the vector.
* @param values Vector to convert.
* @return Array with values to visualizes as list.
*/
private Object[][] createTableArray(Vector<?> values) {
String[][] tableArray = new String[1][values.size()];
for (int i = 0; i<values.size(); i++) {
tableArray[0][i] = values.get(i).toString();
}
return tableArray;
}
}