Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit af41306

Browse files
fix: updateTime() off-by-one, BasicStroke constants, copyfile append, Random seed
- updateTime(): slider values 32-61 incorrectly produced April 31 (day never decremented to April range due to double month check). Rewrote with clean if/else branches for March/April/May. - BasicStroke constructor used JOIN_BEVEL (2) for the cap parameter and JOIN_MITER (0) for join. While the numeric values happened to map to CAP_SQUARE and JOIN_MITER, the intent was clearly CAP_BUTT + JOIN_BEVEL. Fixed to use correct constants. - copyfile() opened FileOutputStream with append=true, which would corrupt exported files if the target somehow existed. Changed to overwrite mode (append=false). - positionCluster() used Calendar.SECOND as Random seed, giving only 60 possible layouts and identical results within the same second. Replaced with System.nanoTime() for proper entropy. - Removed unused Calendar/GregorianCalendar imports.
1 parent 444fb82 commit af41306

1 file changed

Lines changed: 23 additions & 30 deletions

File tree

Gvisual/src/gvisual/Main.java

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
import java.io.InputStream;
3636
import java.io.OutputStream;
3737
import java.util.ArrayList;
38-
import java.util.Calendar;
3938
import java.util.Collection;
40-
import java.util.GregorianCalendar;
4139
import java.util.HashMap;
4240
import java.util.HashSet;
4341
import java.util.List;
@@ -310,9 +308,7 @@ public void positionCluster(Vector<String> vertices, int y, int x) {
310308
int curY = y * 200 + 100;
311309
int signX = 0; //0 is +ve
312310
int signY = 1; // 1 is -ve
313-
Calendar calendar = new GregorianCalendar();
314-
int second = calendar.get(Calendar.SECOND);
315-
Random generator = new Random(second);
311+
Random generator = new Random(System.nanoTime());
316312

317313

318314
for (String v : vertices) {
@@ -357,32 +353,29 @@ public void back_positionCluster(Vector<String> vertices, int y, int x) {
357353
}
358354

359355
/**
360-
* updates the timestamp of the currently selected graph
356+
* updates the timestamp of the currently selected graph.
357+
*
358+
* The timeline slider value (1..92) maps to calendar dates
359+
* March 1 – May 31, 2011. March has 31 days, April has 30,
360+
* May has 31.
361361
*/
362362
public void updateTime() {
363-
month = "03";
364-
date = null;
365-
int day = timeline.getValue();
366-
while (true) {
367-
if ((day == 31 && month.equals("03")) || day < 31) {
368-
date = Integer.toString(day);
369-
if (day < 10) {
370-
date = "0" + date;
371-
}
372-
break;
373-
} else {
374-
if (month.equals("03")) {
375-
day = day - 31;
376-
} else {
377-
day = day - 30;
378-
}
379-
if (month.equals("03")) {
380-
month = "04";
381-
} else {
382-
month = "05";
383-
}
384-
}
363+
int day = timeline.getValue(); // 1..92
364+
365+
if (day <= 31) {
366+
// March: days 1–31
367+
month = "03";
368+
} else if (day <= 61) {
369+
// April: days 32–61 → April 1–30
370+
month = "04";
371+
day = day - 31;
372+
} else {
373+
// May: days 62–92 → May 1–31
374+
month = "05";
375+
day = day - 61;
385376
}
377+
378+
date = (day < 10) ? ("0" + day) : Integer.toString(day);
386379
timeStamp = "2011-" + month + "-" + date;
387380
}
388381

@@ -701,7 +694,7 @@ public Stroke transform(edge i) {
701694
}
702695
float dash[] = {1.0f};
703696
float width = i.getWeight() / 40 + 1.0f;
704-
return new BasicStroke(width, BasicStroke.JOIN_BEVEL, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f);
697+
return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, dash, 0.0f);
705698
}
706699
};
707700
vv.getRenderContext().setEdgeStrokeTransformer(edgeWeight);
@@ -2194,7 +2187,7 @@ public void actionPerformed(ActionEvent e) {
21942187
private void copyfile(File srFile, File dtFile) throws FileNotFoundException, IOException {
21952188

21962189
try (InputStream in = new FileInputStream(srFile);
2197-
OutputStream out = new FileOutputStream(dtFile, true)) {
2190+
OutputStream out = new FileOutputStream(dtFile, false)) {
21982191

21992192
byte[] buf = new byte[8192];
22002193
int len;

0 commit comments

Comments
 (0)