@@ -836,6 +836,45 @@ public void removeRowsNotInTargets() {
836836 });
837837
838838 }
839+
840+ public void removeInvalidRows () {
841+
842+ SwingUtilities .invokeLater (() -> {
843+ for (int i = lineEntries .size () - 1 ; i >= 0 ; i --) {// 降序删除才能正确删除每个元素
844+ try {
845+ LineEntry entry = lineEntries .get (i );
846+ if (entry == null ) {
847+ continue ;
848+ }
849+ int status = entry .getStatuscode ();
850+ /**
851+ * -1 No DNS Record,or just DNS Record
852+ * 0 No Response
853+ * 400 Bad Request
854+ * 502 Bad Gateway
855+ * 503 Service Unavailable
856+ * 504 Gateway Time-out
857+ * 521 Web Server Is Down
858+ * 522 Connection Timed Out
859+ *
860+ */
861+ if (status == -1 || status == 0 || status == 400 || status >= 502 ) {
862+ String url = entry .getUrl ();
863+ lineEntries .remove (i );
864+ titleDao .deleteTitleByUrl (url );// 写入数据库
865+ stdout .println ("!!! " + url + " deleted, due to status : " + status );
866+ int index = i ;
867+
868+ fireTableRowsDeleted (index , index );
869+ }
870+
871+ } catch (Exception e ) {
872+ e .printStackTrace (stderr );
873+ }
874+ }
875+ });
876+
877+ }
839878
840879 /**
841880 * 暂时只是标记重复项目,然后用户可以手动标记,不直接执行删除操作
@@ -1063,39 +1102,40 @@ public void addNewLineEntryWithTime(LineEntry lineEntry) {
10631102 String key = lineEntry .getUrl () + "#" + System .nanoTime ();
10641103 lineEntry .setUrl (key );
10651104 lineEntries .put (key , lineEntry );
1066-
1105+
10671106 // compute index from size - 1: this avoids reliance on indexOfKey correctness
1068- int index ;
1069- try {
1070- index = lineEntries .size () - 1 ;
1071- if (index < 0 ) {
1072- index = 0 ;
1073- }
1074- } catch (Exception e ) {
1075- index = lineEntries .indexOfKey (key ); // fallback
1076- }
1077-
1107+ int index ;
1108+ try {
1109+ index = lineEntries .size () - 1 ;
1110+ if (index < 0 ) {
1111+ index = 0 ;
1112+ }
1113+ } catch (Exception e ) {
1114+ index = lineEntries .indexOfKey (key ); // fallback
1115+ }
1116+
10781117// System.out.println("rowCount=" + getRowCount() + ", lineEntries.size=" + lineEntries.size());
10791118// System.out.println("index=" + index + ", size=" + lineEntries.size());
1080-
1119+
10811120 /**
1082- * java.lang.ArrayIndexOutOfBoundsException: Index 1847 out of bounds for length 1847
1083- * at java.desktop/javax.swing.DefaultRowSorter.setModelToViewFromViewToModel(DefaultRowSorter.java:745)
1121+ * java.lang.ArrayIndexOutOfBoundsException: Index 1847 out of bounds for length
1122+ * 1847 at
1123+ * java.desktop/javax.swing.DefaultRowSorter.setModelToViewFromViewToModel(DefaultRowSorter.java:745)
10841124 */
1085- //方案1:
1125+ // 方案1:
10861126// LineTable table = guiMain.getTitlePanel().getTitleTable();
10871127// RowSorter<? extends TableModel> sorter = table.getRowSorter();
10881128// table.setRowSorter(null); // temporarily disable sorter
10891129//
10901130// fireTableRowsInserted(index, index);// 有毫秒级时间戳,只会是新增
10911131//
10921132// table.setRowSorter(sorter); // enable again
1093-
1094- //方案2:
1133+
1134+ // 方案2:
10951135 fireTableDataChanged ();
1096-
1136+
10971137 new Thread (() -> titleDao .addOrUpdateTitle (lineEntry )).start ();// 写入数据库
1098- System .out .println (key + " added" );
1138+ System .out .println (key + " added" );
10991139 });
11001140
11011141 }
0 commit comments