aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2025-04-29 09:34:35 +0200
committerJonas Smedegaard <dr@jones.dk>2025-04-29 09:34:35 +0200
commit95d3e8a088f033da51cabe34bcdbba3061760b5e (patch)
treeb484427c919d47809f4f39fa072a365cafeb23be /src
parentf0c7a1872b667858155ca30349b80b9ff240fb1d (diff)
wrap long lines
Diffstat (limited to 'src')
-rw-r--r--src/com.example.portfolio2/com/example/portfolio2/Controller.java48
-rw-r--r--src/com.example.portfolio2/com/example/portfolio2/Database.java30
-rw-r--r--src/com.example.portfolio2/com/example/portfolio2/MyDB.java12
-rw-r--r--src/com.example.portfolio2/com/example/portfolio2/Window.java81
-rw-r--r--src/com.example.portfolio3/com/example/portfolio3/AbstractGraph.java4
-rw-r--r--src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java11
-rw-r--r--src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java10
-rw-r--r--src/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java4
-rw-r--r--src/com.example.portfolio3/com/example/portfolio3/GraphAlgorithms.java91
-rw-r--r--src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java27
-rw-r--r--src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java32
-rw-r--r--src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java3
12 files changed, 263 insertions, 90 deletions
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Controller.java b/src/com.example.portfolio2/com/example/portfolio2/Controller.java
index 036236f..a0c23db 100644
--- a/src/com.example.portfolio2/com/example/portfolio2/Controller.java
+++ b/src/com.example.portfolio2/com/example/portfolio2/Controller.java
@@ -39,7 +39,11 @@ class Controller {
/// @param combo involved activity box
/// @param select selected item
/// @param area whole text area
- void onComboSelected(final ComboBox<String> combo, final ComboBox<String> select, final TextArea area) {
+ void onComboSelected(
+ final ComboBox<String> combo,
+ final ComboBox<String> select,
+ final TextArea area
+ ) {
// clear the activity selection box
select.getItems().clear();
@@ -48,7 +52,8 @@ class Controller {
area.clear();
// fill activity box from data in store
- select.getItems().addAll(store.selectProgram(combo.getValue()));
+ select.getItems().addAll(
+ store.selectProgram(combo.getValue()));
}
/// callback when activity box is selected
@@ -56,14 +61,19 @@ class Controller {
/// @param combo involved activity box
/// @param select selected item
/// @param area whole text area
- void onActivitySelected(final ComboBox<String> combo, final ComboBox<String> select, final TextArea area) {
+ void onActivitySelected(
+ final ComboBox<String> combo,
+ final ComboBox<String> select,
+ final TextArea area
+ ) {
// pass the value chosen in the box
addActivity(select.getValue(), area);
// update text area based on category choice
//
- // users can choose from the ComboBox, string (activity) and the area would update.
+ // Users can choose from the ComboBox,
+ // and string (activity) and the area will then update.
updateArea(combo, area);
}
@@ -72,13 +82,21 @@ class Controller {
/// @param subject1 involved 1st column subject module box
/// @param subject2 involved 2nd column subject module box
/// @param subjectModules list of selected subject modules
- void onSubjectModuleSelected(final ComboBox<String> subject1, final ComboBox<String> subject2, final List<String> subjectModules) {
+ void onSubjectModuleSelected(
+ final ComboBox<String> subject1,
+ final ComboBox<String> subject2,
+ final List<String> subjectModules
+ ) {
- // Beautiful loop we've created to remove option chosen in one subject module box from the other
+ // remove chosen option from opposite subject module box
for (String sub: subjectModules) {
if (sub.equals(subject1.getValue())) {
- subject2.getItems().remove(subject1.getValue());
- } else if (!sub.equals(subject1.getValue()) && !subject2.getItems().contains(sub)) {
+ subject2.getItems().remove(
+ subject1.getValue());
+ } else if (
+ !sub.equals(subject1.getValue())
+ && !subject2.getItems().contains(sub)
+ ) {
subject2.getItems().add(sub);
}
}
@@ -98,9 +116,12 @@ class Controller {
///
/// @param combo involved activity box
/// @param textArea whole text area
- void updateArea(final ComboBox<String> combo, final TextArea textArea) {
+ void updateArea(
+ final ComboBox<String> combo, final TextArea textArea
+ ) {
textArea.clear();
- for (String s: store.getParticipation(combo.getValue())) {
+ for (String s: store.getParticipation(combo.getValue())
+ ) {
textArea.appendText(s + "\n");
}
}
@@ -108,8 +129,11 @@ class Controller {
/// update label with current ECTS of program type
/// @param ectslabel text display area for ECTS points
/// @param comboBox involved activity box
- void updateEcts(final Label ectslabel, final ComboBox<String> comboBox) {
- ectslabel.setText("ECTS: " + store.getSumEcts(comboBox.getValue()));
+ void updateEcts(
+ final Label ectslabel, final ComboBox<String> comboBox
+ ) {
+ ectslabel.setText("ECTS: "
+ + store.getSumEcts(comboBox.getValue()));
}
void fillElective(final ComboBox<String> electiveBox) {
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Database.java b/src/com.example.portfolio2/com/example/portfolio2/Database.java
index a6a144a..6edcfed 100644
--- a/src/com.example.portfolio2/com/example/portfolio2/Database.java
+++ b/src/com.example.portfolio2/com/example/portfolio2/Database.java
@@ -32,7 +32,10 @@ class Database {
if (name == null) {
return -1;
}
- ArrayList<String> result = db.query("select indeks from activity a where name is '" + name + "';", "indeks");
+ ArrayList<String> result = db.query(
+ "select indeks from activity a"
+ + " where name is '" + name + "';",
+ "indeks");
return Integer.parseInt(result.getFirst());
}
@@ -41,7 +44,8 @@ class Database {
///
/// @param activityIndex index of activity
void addParticipation(final int activityIndex) {
- db.cmd("insert into participation values(123, " + activityIndex + ");");
+ db.cmd("insert into participation values(123, "
+ + activityIndex + ");");
}
/// list currently participating activities
@@ -49,7 +53,11 @@ class Database {
/// @param program programme name
/// @return names of participating activities
ArrayList<String> getParticipation(final String program) {
- return db.query("select name from participation p inner join activity a on p.indeks = a.indeks where program is '" + program + "';", "name");
+ return db.query(
+ "select name from participation p"
+ + " inner join activity a on p.indeks = a.indeks"
+ + " where program is '" + program + "';",
+ "name");
}
/// purge participation database
@@ -62,7 +70,10 @@ class Database {
/// @param program programme name
/// @return names of contained activities
ArrayList<String> selectProgram(final String program) {
- return db.query("select name from activity where program is '" + program + "';", "name");
+ return db.query(
+ "select name from activity"
+ + " where program is '" + program + "';",
+ "name");
}
/// sum of ECTS points under the given category
@@ -73,7 +84,16 @@ class Database {
if (program == null) {
return "0";
}
- ArrayList<String> result = db.query("select sum(activity.ects) as total_ects,student.name from student left outer join participation on student.studid = participation.studid inner join activity on participation.indeks = activity.indeks where program is '" + program + "' group by student.studid ;", "total_ects");
+ ArrayList<String> result = db.query(
+ "select sum(activity.ects)"
+ + " as total_ects,student.name"
+ + " from student left outer join participation"
+ + " on student.studid = participation.studid"
+ + " inner join activity"
+ + " on participation.indeks = activity.indeks"
+ + " where program is '" + program + "'"
+ + " group by student.studid ;",
+ "total_ects");
if (result.isEmpty()) {
return "0";
}
diff --git a/src/com.example.portfolio2/com/example/portfolio2/MyDB.java b/src/com.example.portfolio2/com/example/portfolio2/MyDB.java
index 942f0b9..1827034 100644
--- a/src/com.example.portfolio2/com/example/portfolio2/MyDB.java
+++ b/src/com.example.portfolio2/com/example/portfolio2/MyDB.java
@@ -79,7 +79,9 @@ public class MyDB {
/// @param query foo
/// @param fld foo
/// @return foo
- public final ArrayList<String> query(final String query, final String fld) {
+ public final ArrayList<String> query(
+ final String query, final String fld
+ ) {
ArrayList<String> res = new ArrayList<>();
if (conn == null) {
open();
@@ -97,7 +99,9 @@ public class MyDB {
res.add(name);
}
} catch (SQLException e) {
- System.out.println("Error in statement " + query + " " + fld);
+ System.out.println(
+ "Error in statement "
+ + query + " " + fld);
throw new RuntimeException(e);
}
try {
@@ -105,7 +109,9 @@ public class MyDB {
stmt.close();
}
} catch (SQLException e) {
- System.out.println("Error in statement " + query + " " + fld);
+ System.out.println(
+ "Error in statement "
+ + query + " " + fld);
throw new RuntimeException(e);
}
return res;
diff --git a/src/com.example.portfolio2/com/example/portfolio2/Window.java b/src/com.example.portfolio2/com/example/portfolio2/Window.java
index 9f35e59..68a2c17 100644
--- a/src/com.example.portfolio2/com/example/portfolio2/Window.java
+++ b/src/com.example.portfolio2/com/example/portfolio2/Window.java
@@ -40,7 +40,9 @@ public final class Window extends Application {
/// Label styling
private static final String LABEL_STYLE =
- "-fx-font-weight: bold;-fx-font-size: 18;-fx-padding: 10";
+ "-fx-font-weight: bold;"
+ + "-fx-font-size: 18;"
+ + "-fx-padding: 10";
/// Storage model
private Database store = new Database();
@@ -62,44 +64,76 @@ public final class Window extends Application {
);
// define list of subject modules
- List<String> subjectModules = List.of("Computer Science", "Informatik", "Astrology");
+ List<String> subjectModules = List.of(
+ "Computer Science", "Informatik", "Astrology");
// define button functionality for each activity column
for (ActivityColumn col : columns) {
col.nameLabel.setStyle(LABEL_STYLE);
col.ectsLabel.setStyle(LABEL_STYLE);
- col.categoryCombo.setPrefSize(LIST_WIDTH, LIST_HEIGHT);
- col.activitySelect.setPrefSize(LIST_WIDTH, LIST_HEIGHT);
+ col.categoryCombo.setPrefSize(
+ LIST_WIDTH, LIST_HEIGHT);
+ col.activitySelect.setPrefSize(
+ LIST_WIDTH, LIST_HEIGHT);
col.area.setPrefWidth(LIST_WIDTH);
// all boxes share same activity logic
col.activitySelect.setOnAction(event -> {
- con.onActivitySelected(col.categoryCombo, col.activitySelect, col.area);
- con.updateEcts(col.ectsLabel, col.categoryCombo);
+ con.onActivitySelected(
+ col.categoryCombo,
+ col.activitySelect,
+ col.area);
+ con.updateEcts(
+ col.ectsLabel,
+ col.categoryCombo);
});
// handle each category box
switch (col.name) {
case "Program" -> {
- col.categoryCombo.getItems().addAll("HumTek", "NatBach");
+ col.categoryCombo.getItems().addAll(
+ "HumTek", "NatBach");
col.categoryCombo.setOnAction(event -> {
- con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
+ con.onComboSelected(
+ col.categoryCombo,
+ col.activitySelect,
+ col.area);
});
}
// TODO: use the list for filling the box
case "Subject 1" -> {
- col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
+ col.categoryCombo.getItems().addAll(
+ "Computer Science",
+ "Informatik",
+ "Astrology");
col.categoryCombo.setOnAction(event -> {
- con.onSubjectModuleSelected(col.categoryCombo, columns.get(2).categoryCombo, subjectModules);
- con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
+ con.onSubjectModuleSelected(
+ col.categoryCombo,
+ columns.get(2)
+ .categoryCombo,
+ subjectModules);
+ con.onComboSelected(
+ col.categoryCombo,
+ col.activitySelect,
+ col.area);
});
}
case "Subject 2" -> {
- col.categoryCombo.getItems().addAll("Computer Science", "Informatik", "Astrology");
+ col.categoryCombo.getItems().addAll(
+ "Computer Science",
+ "Informatik",
+ "Astrology");
// TODO: figure out a better way...
col.categoryCombo.setOnAction(event -> {
- con.onSubjectModuleSelected(col.categoryCombo, columns.get(1).categoryCombo, subjectModules);
- con.onComboSelected(col.categoryCombo, col.activitySelect, col.area);
+ con.onSubjectModuleSelected(
+ col.categoryCombo,
+ columns.get(1)
+ .categoryCombo,
+ subjectModules);
+ con.onComboSelected(
+ col.categoryCombo,
+ col.activitySelect,
+ col.area);
});
}
case "Elective" -> {
@@ -113,9 +147,15 @@ public final class Window extends Application {
}
// define HBox and scene for columns
- HBox root = new HBox(columns.get(0).asVBox(), columns.get(1).asVBox(), columns.get(2).asVBox(), columns.get(3).asVBox());
- Scene scene = new Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT);
- stage.setTitle("Course Selector RUC: Ultimate Deluxe Edition");
+ HBox root = new HBox(
+ columns.get(0).asVBox(),
+ columns.get(1).asVBox(),
+ columns.get(2).asVBox(),
+ columns.get(3).asVBox());
+ Scene scene = new Scene(
+ root, WINDOW_WIDTH, WINDOW_HEIGHT);
+ stage.setTitle(
+ "Course Selector RUC: Ultimate Deluxe Edition");
stage.setScene(scene);
stage.show();
}
@@ -164,7 +204,12 @@ public final class Window extends Application {
///
/// @return column of activities as VBox
VBox asVBox() {
- return new VBox(nameLabel, categoryCombo, activitySelect, area, ectsLabel);
+ return new VBox(
+ nameLabel,
+ categoryCombo,
+ activitySelect,
+ area,
+ ectsLabel);
}
}
}
diff --git a/src/com.example.portfolio3/com/example/portfolio3/AbstractGraph.java b/src/com.example.portfolio3/com/example/portfolio3/AbstractGraph.java
index 514ac1e..9d356e8 100644
--- a/src/com.example.portfolio3/com/example/portfolio3/AbstractGraph.java
+++ b/src/com.example.portfolio3/com/example/portfolio3/AbstractGraph.java
@@ -33,7 +33,9 @@ public abstract class AbstractGraph implements Graph {
}
/// foo
- public final void insertEdge(final String v, final String u, final int w) {
+ public final void insertEdge(
+ final String v, final String u, final int w
+ ) {
insertEdge(vertex(v), vertex(u), w);
}
diff --git a/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java b/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java
index 8484d58..d9a5d19 100644
--- a/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java
+++ b/src/com.example.portfolio3/com/example/portfolio3/AdjListGraph.java
@@ -8,7 +8,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-/// Adjecency List Graph - A map from vertices to set of outedges from the vertex
+/// Adjecency List Graph - A map from vertices
+/// to set of outedges from the vertex
public class AdjListGraph extends AbstractGraph {
/// foo
@@ -18,7 +19,9 @@ public class AdjListGraph extends AbstractGraph {
private Map<Vertex, Set<Edge>> outEdge = new HashMap<>();
/// foo
- public final void insertEdge(final Vertex v1, final Vertex v2, final int w) {
+ public final void insertEdge(
+ final Vertex v1, final Vertex v2, final int w
+ ) {
Edge e = new Edge(v1, v2, w);
if (!outEdge.containsKey(e.from())) {
outEdge.put(e.from(), new HashSet<Edge>());
@@ -46,7 +49,9 @@ public class AdjListGraph extends AbstractGraph {
}
/// foo
- public final Integer getWeight(final Vertex v1, final Vertex v2) {
+ public final Integer getWeight(
+ final Vertex v1, final Vertex v2
+ ) {
// linear in number of outedges from vertices
if (!outEdge.containsKey(v1)) {
diff --git a/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java b/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java
index 8c2c139..d5749a9 100644
--- a/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java
+++ b/src/com.example.portfolio3/com/example/portfolio3/AdjMapGraph.java
@@ -8,7 +8,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-/// Adjecency Map Graph - A map from vertices to map of target vertex to edge
+/// Adjecency Map Graph - A map from vertices
+/// to map of target vertex to edge
class AdjMapGraph extends AbstractGraph {
/// foo
@@ -18,10 +19,13 @@ class AdjMapGraph extends AbstractGraph {
private Map<Vertex, Map<Vertex, Edge>> outEdge = new HashMap<>();
/// foo
- public void insertEdge(final Vertex v1, final Vertex v2, final int w) {
+ public void insertEdge(
+ final Vertex v1, final Vertex v2, final int w
+ ) {
Edge e = new Edge(v1, v2, w);
if (!outEdge.containsKey(e.from())) {
- outEdge.put(e.from(), new HashMap<Vertex, Edge>());
+ outEdge.put(e.from(),
+ new HashMap<Vertex, Edge>());
}
outEdge.get(e.from()).put(e.to(), e);
}
diff --git a/src/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java b/src/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java
index 2f3b036..4fe3930 100644
--- a/src/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java
+++ b/src/com.example.portfolio3/com/example/portfolio3/EdgeGraph.java
@@ -17,7 +17,9 @@ class EdgeGraph extends AbstractGraph {
Set<Edge> edges = new HashSet<>();
/// foo
- public void insertEdge(final Vertex v1, final Vertex v2, final int w) {
+ public void insertEdge(
+ final Vertex v1, final Vertex v2, final int w
+ ) {
edges.add(new Edge(v1, v2, w));
}
diff --git a/src/com.example.portfolio3/com/example/portfolio3/GraphAlgorithms.java b/src/com.example.portfolio3/com/example/portfolio3/GraphAlgorithms.java
index 4d8a8c2..61ef6c2 100644
--- a/src/com.example.portfolio3/com/example/portfolio3/GraphAlgorithms.java
+++ b/src/com.example.portfolio3/com/example/portfolio3/GraphAlgorithms.java
@@ -21,7 +21,7 @@ public class GraphAlgorithms {
/// foo
GraphAlgorithms() { }
- /// Calculates the length of a path or any other collection of edes
+ /// calculate the length of a path or another collection of edges
///
/// does not require the edges to form a path
///
@@ -39,7 +39,8 @@ public class GraphAlgorithms {
/// @return boolean
public static boolean isPath(final List<Edge> edges) {
for (int i = 1; i < edges.size(); i++) {
- if (edges.get(i - 1).to() != edges.get(i).from()) {
+ if (edges.get(i - 1).to() != edges.get(i).from()
+ ) {
return false;
}
}
@@ -54,10 +55,13 @@ public class GraphAlgorithms {
/// @param g foo
/// @param path foo
/// @return Integer
- public static Integer pathLength(final Graph g, final List<Vertex> path) {
+ public static Integer pathLength(
+ final Graph g, final List<Vertex> path
+ ) {
int length = 0;
for (int i = 1; i < path.size(); i++) {
- Integer w = g.getWeight(path.get(i - 1), path.get(i));
+ Integer w = g.getWeight(
+ path.get(i - 1), path.get(i));
if (w == null) {
return null;
}
@@ -84,7 +88,8 @@ public class GraphAlgorithms {
return w1 - w2;
}
if (e1.from() != e2.from()) {
- return e1.from().name().compareTo(e2.from().name());
+ return e1.from().name().compareTo(
+ e2.from().name());
}
return e1.to().name().compareTo(e2.to().name());
@@ -99,7 +104,8 @@ public class GraphAlgorithms {
/// @return int
static int cmpEdgeFrom(final Edge e1, final Edge e2) {
if (e1.from() != e2.from()) {
- return e1.from().name().compareTo(e2.from().name());
+ return e1.from().name().compareTo(
+ e2.from().name());
}
int w1 = e1.weight(), w2 = e2.weight();
if (w1 != w2) {
@@ -118,10 +124,12 @@ public class GraphAlgorithms {
/// @return int
static int cmpEdgeTo(final Edge e1, final Edge e2) {
if (e1.to() != e2.to()) {
- return e1.to().name().compareTo(e2.to().name());
+ return e1.to().name().compareTo(
+ e2.to().name());
}
if (e1.from() != e2.from()) {
- return e1.from().name().compareTo(e2.from().name());
+ return e1.from().name().compareTo(
+ e2.from().name());
}
int w1 = e1.weight(), w2 = e2.weight();
@@ -165,9 +173,12 @@ public class GraphAlgorithms {
///
/// @param vertices foo
/// @return List<Vertex>
- public static List<Vertex> sortVertex(final Collection<Vertex> vertices) {
+ public static List<Vertex> sortVertex(
+ final Collection<Vertex> vertices
+ ) {
ArrayList<Vertex> list = new ArrayList<>(vertices);
- Collections.sort(list, (Vertex v1, Vertex v2) -> v1.name().compareTo(v2.name()));
+ Collections.sort(list, (Vertex v1, Vertex v2) ->
+ v1.name().compareTo(v2.name()));
return list;
}
@@ -182,7 +193,9 @@ public class GraphAlgorithms {
/// @param g foo
/// @param v foo
/// @return Set<Vertex>
- public static Set<Vertex> visitBreadthFirst(final Graph g, final Vertex v) {
+ public static Set<Vertex> visitBreadthFirst(
+ final Graph g, final Vertex v
+ ) {
HashSet<Vertex> thisLevel = new HashSet<>();
HashSet<Vertex> nextLevel = new HashSet<>();
HashSet<Vertex> visited = new HashSet<>();
@@ -219,7 +232,9 @@ public class GraphAlgorithms {
/// @param g foo
/// @param v foo
/// @return Set<Vertex>
- public static Set<Vertex> visitDepthFirst(final Graph g, final Vertex v) {
+ public static Set<Vertex> visitDepthFirst(
+ final Graph g, final Vertex v
+ ) {
HashSet<Vertex> visit = new HashSet<>();
visitDepthFirst(g, v, visit);
@@ -231,7 +246,9 @@ public class GraphAlgorithms {
/// @param g foo
/// @param v foo
/// @param visited foo
- private static void visitDepthFirst(final Graph g, final Vertex v, final Set<Vertex> visited) {
+ private static void visitDepthFirst(
+ final Graph g, final Vertex v, final Set<Vertex> visited
+ ) {
if (visited.contains(v)) {
return;
}
@@ -265,7 +282,9 @@ public class GraphAlgorithms {
if (frontier.contains(e.to())) {
continue;
}
- if (nearest == null || nearest.weight() > e.weight()) {
+ if (nearest == null
+ || nearest.weight() > e.weight()
+ ) {
nearest = e;
}
}
@@ -287,7 +306,9 @@ public class GraphAlgorithms {
/// @param g foo
/// @param start foo
/// @return Set<Edge>
- public static Set<Edge> dijkstra(final Graph g, final Vertex start) {
+ public static Set<Edge> dijkstra(
+ final Graph g, final Vertex start
+ ) {
// create table for done, prev and weight from start
int maxint = Integer.MAX_VALUE;
@@ -314,15 +335,19 @@ public class GraphAlgorithms {
if (done.contains(w2)) {
continue;
}
- if ((weight.get(w1) + e.weight()) < neardist) {
+ if ((weight.get(w1)
+ + e.weight())
+ < neardist
+ ) {
nearest = e.to();
- neardist = weight.get(w1) + e.weight();
+ neardist = weight.get(w1)
+ + e.weight();
done2near = e;
}
}
}
- // System.out.println("find nearest "+done2near);
+ //System.out.println("find nearest "+done2near);
// if no more, then we are done
if (nearest == null) {
break;
@@ -357,17 +382,27 @@ public class GraphAlgorithms {
/// @param file foo
public static void readGraph(final Graph g, final String file) {
try {
- BufferedReader in = new BufferedReader(new FileReader(file));
- for (String line = in.readLine(); line != null; line = in.readLine()) {
+ BufferedReader in = new BufferedReader(
+ new FileReader(file));
+ for (String line = in.readLine();
+ line != null;
+ line = in.readLine()
+ ) {
if (line.length() == 0) {
continue;
}
String[] arr = line.split(",");
if (arr.length != 3) {
- throw new RuntimeException("CSV file format error: " + line);
+ throw new RuntimeException(
+ "CSV file format error: "
+ + line);
}
- g.insertEdge(arr[0].trim(), arr[1].trim(), Integer.parseInt(arr[2].trim()));
- g.insertEdge(arr[1].trim(), arr[0].trim(), Integer.parseInt(arr[2].trim()));
+ g.insertEdge(arr[0].trim(),
+ arr[1].trim(),
+ Integer.parseInt(arr[2].trim()));
+ g.insertEdge(arr[1].trim(),
+ arr[0].trim(),
+ Integer.parseInt(arr[2].trim()));
}
in.close();
} catch (IOException e) {
@@ -391,9 +426,12 @@ public class GraphAlgorithms {
///
/// @param list foo
/// @param f foo
- public static void storeStrings(final List<String> list, final String f) {
+ public static void storeStrings(
+ final List<String> list, final String f
+ ) {
try {
- PrintWriter out = new PrintWriter(new FileWriter(f));
+ PrintWriter out = new PrintWriter(
+ new FileWriter(f));
for (String s: list) {
out.println(s);
}
@@ -410,7 +448,8 @@ public class GraphAlgorithms {
public static ArrayList<String> loadStrings(final String f) {
ArrayList<String> list = new ArrayList<>();
try {
- BufferedReader in = new BufferedReader(new FileReader(f));
+ BufferedReader in = new BufferedReader(
+ new FileReader(f));
while (true) {
String s = in.readLine();
if (s == null) {
diff --git a/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java b/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java
index 41d5880..bd80c00 100644
--- a/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java
+++ b/src/com.example.portfolio3/com/example/portfolio3/MatrixGraph.java
@@ -14,7 +14,8 @@ public class MatrixGraph extends AbstractGraph {
private Integer[][] matrix = null; // made in constructor
/// foo
- // We must be able to map vertices to index in matrix and back again
+ // We must be able to map vertices
+ // to index in matrix and back again
private Vertex[] index2vertex; // made in constructor
/// foo
@@ -42,7 +43,8 @@ public class MatrixGraph extends AbstractGraph {
}
int index = vertex2index.size();
if (index >= index2vertex.length) {
- throw new RuntimeException("Too many vertices in graph");
+ throw new RuntimeException(
+ "Too many vertices in graph");
}
vertex2index.put(v, index);
index2vertex[index] = v;
@@ -51,7 +53,9 @@ public class MatrixGraph extends AbstractGraph {
}
/// foo
- public final void insertEdge(final Vertex v1, final Vertex v2, final int w) {
+ public final void insertEdge(
+ final Vertex v1, final Vertex v2, final int w
+ ) {
matrix[getIndex(v1)][getIndex(v2)] = w;
}
@@ -60,11 +64,16 @@ public class MatrixGraph extends AbstractGraph {
HashSet<Edge> edges = new HashSet<>();
for (int i = 0; i < numVertex; i++) {
for (int j = 0; j < numVertex; j++) {
- Integer weight = matrix[i][j]; // may be null
+
+ // may be null
+ Integer weight = matrix[i][j];
if (weight == null) {
continue;
}
- edges.add(new Edge(index2vertex[i], index2vertex[j], weight));
+ edges.add(new Edge(
+ index2vertex[i],
+ index2vertex[j],
+ weight));
}
}
@@ -87,9 +96,11 @@ public class MatrixGraph extends AbstractGraph {
}
/// foo
- public final Integer getWeight(final Vertex v1, final Vertex v2) {
+ public final Integer getWeight(
+ final Vertex v1, final Vertex v2
+ ) {
- // constant time operation
- return matrix[vertex2index.get(v1)][vertex2index.get(v2)];
+ // constant time operation
+ return matrix[vertex2index.get(v1)][vertex2index.get(v2)];
}
}
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
index 0f5503e..627f5f7 100644
--- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
+++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Graph.java
@@ -68,8 +68,11 @@ public final class Graph {
"\n\n%d disjoint choice sets collected:\n",
s.size());
for (Set<Vertex> verticeSet: s) {
- System.out.print("set(" + verticeSet.size() + "):");
- for (Vertex v: GraphAlgorithms.sortVertex(verticeSet)) {
+ System.out.print(
+ "set(" + verticeSet.size() + "):");
+ for (Vertex v:
+ GraphAlgorithms.sortVertex(verticeSet)
+ ) {
System.out.print(" " + v.toString());
}
System.out.println();
@@ -141,7 +144,9 @@ public final class Graph {
///
/// @param g Graph to inspect
/// @return list of disjoint sets
- public static ArrayList<Set<Vertex>> disjoint(final AbstractGraph g) {
+ public static ArrayList<Set<Vertex>> disjoint(
+ final AbstractGraph g
+ ) {
// get all subject modules
//
@@ -157,7 +162,9 @@ public final class Graph {
/// @param g Graph to inspect
/// @param vip Ordered list of subject modules to prioritize
/// @return List of sets of disjoint choices
- public static ArrayList<Set<Vertex>> disjoint(final AbstractGraph g, final List<Vertex> vip) {
+ public static ArrayList<Set<Vertex>> disjoint(
+ final AbstractGraph g, final List<Vertex> vip
+ ) {
ArrayList<Set<Vertex>> sets = new ArrayList<>();
// track done subject modules as extendable set
@@ -204,7 +211,9 @@ public final class Graph {
/// @param sets list of disjoint choices
/// @param g choices as weights in graph
/// @return groups of disjoint choices as a graph
- public static AbstractGraph moduleGroups(final ArrayList<Set<Vertex>> sets, final AbstractGraph g) {
+ public static AbstractGraph moduleGroups(
+ final ArrayList<Set<Vertex>> sets, final AbstractGraph g
+ ) {
AbstractGraph h = new AdjListGraph();
for (Set<Vertex> s: sets) {
for (Set<Vertex> t: sets) {
@@ -213,15 +222,18 @@ public final class Graph {
}
int sum = 0;
for (Vertex v: s) {
- // get num of students with this combination of modules.
+
+ // students with this choice
for (Vertex w: t) {
- Integer weight = g.getWeight(v, w);
+ Integer weight =
+ g.getWeight(v, w);
if (weight != null) {
sum += weight;
}
}
}
- h.insertEdge(s.toString(), t.toString(), sum);
+ h.insertEdge(
+ s.toString(), t.toString(), sum);
}
}
@@ -245,7 +257,9 @@ public final class Graph {
/// @param g groups of disjoint choices as a graph
/// @param v seed vertex within graph
/// @return amount of students in consecutive slots
- public static int solution(final AbstractGraph g, final Vertex v) {
+ public static int solution(
+ final AbstractGraph g, final Vertex v
+ ) {
return GraphAlgorithms.pathLength(
GraphAlgorithms.dijkstra(g, v));
}
diff --git a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java
index 1749e00..3b3d8f9 100644
--- a/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java
+++ b/src/dk.biks.bachelorizer/dk/biks/bachelorizer/Window.java
@@ -86,7 +86,8 @@ public final class Window extends Application {
area);
// compose stage
- Scene scene = new Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT);
+ Scene scene = new Scene(
+ root, WINDOW_WIDTH, WINDOW_HEIGHT);
stage.setTitle("JavaFX Demo");
stage.setScene(scene);
stage.show();