📄 errorlogger.java
字号:
} /** * Factory method to log an error message. * @param message the string to display. * @param poly the polygon to display * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, PolyBase poly, Cell cell, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); Point2D [] points = poly.getPoints(); for(int i=0; i<points.length; i++) { int prev = i-1; if (i == 0) prev = points.length-1; h.add(ErrorHighlight.newInstance(cell, points[prev], points[i])); } logAnError(message, cell, sortKey, h); } /** * Factory method to log an error message. * @param message the string to display. * @param geomList a list of nodes or arcs to display (may be null). * @param exportList a list of Exports to display (may be null). * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, List<Geometric> geomList, List<Export> exportList, Cell cell, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); if (geomList != null) { for(Geometric geom : geomList) h.add(ErrorHighlight.newInstance(null, geom)); } if (exportList != null) { for(Export e : exportList) h.add(new ErrorHighExport(null, e)); } logAnError(message, cell, sortKey, h); } /** * Factory method to log an error message. * @param message the string to display. * @param geomList a list of nodes or arcs to display (may be null). * @param exportList a list of Exports to display (may be null). * @param lineList a list of lines (pairs of points) to display (may be null). * @param pointList a list of points to display (may be null). * @param polyList a list of polygons to display (may be null). * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logError(String message, List<Geometric> geomList, List<Export> exportList, List<EPoint> lineList, List<EPoint> pointList, List<PolyBase> polyList, Cell cell, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); if (geomList != null) { for(Geometric geom : geomList) h.add(ErrorHighlight.newInstance(null, geom)); } if (exportList != null) { for(Export e : exportList) h.add(new ErrorHighExport(null, e)); } if (lineList != null) { for(int i=0; i<lineList.size(); i += 2) h.add(new ErrorHighLine(cell, lineList.get(i), lineList.get(i+1), false)); } if (pointList != null) { for(EPoint pt : pointList) h.add(new ErrorHighPoint(cell, pt)); } if (polyList != null) { for(PolyBase poly : polyList) { Point2D [] points = poly.getPoints(); for(int i=0; i<points.length; i++) { int prev = i-1; if (i == 0) prev = points.length-1; h.add(new ErrorHighLine(cell, new EPoint(points[prev].getX(), points[prev].getY()), new EPoint(points[i].getX(), points[i].getY()), true)); } } } logAnError(message, cell, sortKey, h); } /** * Factory method to log a warning message. * @param message the string to display. * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ private synchronized MessageLog logAWarning(String message, Cell cell, int sortKey, List<ErrorHighlight> highlights) { if (terminated && !persistent) { System.out.println("WARNING: "+errorSystem+" already terminated, should not log new warning"); } // if too many errors, don't save it if (errorLimit > 0 && getNumWarnings() >= errorLimit) { if (!limitExceeded) { System.out.println("WARNING: more than " + errorLimit + " warnings found, ignoring the rest"); limitExceeded = true; } return null; } // create a new ErrorLog object WarningLog el = new WarningLog(message, cell, sortKey, highlights);// // store information about the error// el.highlights = new ArrayList<ErrorHighlight>(); // add the ErrorLog into the global list allWarnings.add(el);// if (persistent) Job.getUserInterface().wantToRedoErrorTree(); return el; } /** * Factory method to log a warning message. * @param message the string to display. * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logWarning(String message, Cell cell, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); logAWarning(message, cell, sortKey, h); } /** * Factory method to log a warning message. * @param message the string to display. * @param geom a node or arc to display. * @param cell the cell in which this message applies. * @param context the VarContext of the Cell. * @param sortKey the sorting order of this message. */ public synchronized void logWarning(String message, Geometric geom, Cell cell, VarContext context, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); h.add(ErrorHighlight.newInstance(context, geom)); logAWarning(message, cell, sortKey, h); } /** * Factory method to log a warning message. * @param message the string to display. * @param pp an Exports to display. * @param cell the cell in which this message applies. * @param context the VarContext of the Cell. * @param sortKey the sorting order of this message. */ public synchronized void logWarning(String message, Export pp, Cell cell, VarContext context, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); h.add(new ErrorHighExport(context, pp)); logAWarning(message, cell, sortKey, h); } /** * Factory method to log a warning message. * @param message the string to display. * @param geomList a list of nodes or arcs to display (may be null). * @param exportList a list of Exports to display (may be null). * @param lineList a list of lines (pairs of points) to display (may be null). * @param pointList a list of points to display (may be null). * @param polyList a list of polygons to display (may be null). * @param cell the cell in which this message applies. * @param sortKey the sorting order of this message. */ public synchronized void logWarning(String message, List<Geometric> geomList, List<Export> exportList, List<EPoint> lineList, List<EPoint> pointList, List<PolyBase> polyList, Cell cell, int sortKey) { List<ErrorHighlight> h = new ArrayList<ErrorHighlight>(); if (geomList != null) { for(Geometric geom : geomList) h.add(ErrorHighlight.newInstance(null, geom)); } if (exportList != null) { for(Export e : exportList) h.add(new ErrorHighExport(null, e)); } if (lineList != null) { for(int i=0; i<lineList.size(); i += 2) h.add(new ErrorHighLine(cell, lineList.get(i), lineList.get(i+1), false)); } if (pointList != null) { for(EPoint pt : pointList) h.add(new ErrorHighPoint(cell, pt)); } if (polyList != null) { for(PolyBase poly : polyList) { Point2D [] points = poly.getPoints(); for(int i=0; i<points.length; i++) { int prev = i-1; if (i == 0) prev = points.length-1; h.add(new ErrorHighLine(cell, new EPoint(points[prev].getX(), points[prev].getY()), new EPoint(points[i].getX(), points[i].getY()), false)); } } } logAWarning(message, cell, sortKey, h); } public synchronized int getNumMessages(Cell cell, boolean searchInError) { int numErrors = 0; if (searchInError) { for (int i=0; i<allErrors.size(); i++) { MessageLog el = allErrors.get(i); if (el.logCellId == cell.getId()) numErrors++; } } else { for (int i=0; i<allWarnings.size(); i++) { MessageLog el = allWarnings.get(i); if (el.logCellId == cell.getId()) numErrors++; } } return numErrors; } /** * Method to determine if existing report was not looged already * as error or warning */ public synchronized boolean findMessage(Cell cell, Geometric geom1, Cell cell2, Geometric geom2, boolean searchInError) { if (searchInError) { for (int i = 0; i < allErrors.size(); i++) { MessageLog el = allErrors.get(i); if (el.findGeometries(geom1, cell, geom2, cell2)) return (true); } } else { for (int i = 0; i < allWarnings.size(); i++) { MessageLog el = allWarnings.get(i); if (el.findGeometries(geom1, cell, geom2, cell2)) return (true); } } return (false); } /** * Method to remove all errors and warnings */ public synchronized void clearAllLogs() { allErrors.clear(); allWarnings.clear(); } /** * Method to retrieve all MessageLogs associated with a given Cell * @param cell the Cell to examine. * @return all MessageLogs associated with the Cell. */ public synchronized ArrayList<MessageLog> getAllLogs(Cell cell) { CellId cellId = cell.getId(); ArrayList<MessageLog> msgLogs = new ArrayList<MessageLog>(); // Searching errors for (MessageLog log : allErrors) { if (log.logCellId == cellId) msgLogs.add(log); } // Searching warnings for (WarningLog log : allWarnings) { if (log.logCellId == cellId) msgLogs.add(log); } return msgLogs; } /** * Removes all errors and warnings associated with Cell cell. * @param cell the cell for which errors and warnings will be removed * @return true if any log was removed. */ public synchronized boolean clearLogs(Cell cell) { CellId cellId = cell.getId(); ArrayList<MessageLog> errLogs = new ArrayList<MessageLog>(); // Errors boolean removed = false; for (MessageLog log : allErrors) { if (log.logCellId != cellId) errLogs.add(log); else removed = true; } allErrors = errLogs; ArrayList<WarningLog> warndLogs = new ArrayList<WarningLog>(); // Warnings for (WarningLog log : allWarnings) { if (log.logCellId != cellId) warndLogs.add(log); else removed = true; } allWarnings = warndLogs; return removed; } public void exportErrorLogger(String filePath) { PrintStream buffWriter = null; try { buffWriter = new PrintStream(new FileOutputStream(filePath)); } catch (Exception e) { e.printStackTrace(); System.out.println("Error opening " + filePath); return; // error opening the file } // Creating header buffWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); buffWriter.println(); buffWriter.println("<!DOCTYPE ErrorLogger"); buffWriter.println(" ["); buffWriter.println(" <!ELEMENT ErrorLogger (GroupLog|MessageLog|WarningLog)*>"); buffWriter.println(" <!ELEMENT GroupLog (MessageLog|WarningLog)*>"); buffWriter.println(" <!ELEMENT MessageLog (ERRORTYPEGEOM|ERRORTYPETHICKLINE|ERRORTYPELINE)* >"); buffWriter.println(" <!ELEMENT WarningLog ANY >"); buffWriter.println(" <!ELEMENT ERRORTYPEGEOM ANY>"); buffWriter.println(" <!ELEMENT ERRORTYPELINE ANY>"); buffWriter.println(" <!ELEMENT ERRORTYPETHICKLINE ANY>"); buffWriter.println("<!ATTLIST ErrorLogger"); buffWriter.println(" errorSystem CDATA #REQUIRED"); buffWriter.println(" >"); buffWriter.println(" <!ATTLIST GroupLog"); buffWriter.println(" message CDATA #REQUIRED"); buffWriter.println(" >"); buffWriter.println(" <!ATTLIST MessageLog"); buffWriter.println(" message CDATA #REQUIRED"); buffWriter.println(" cellName CDATA #REQUIRED"); buffWriter.println(" >"); buffWriter.println(" <!ATTLIST WarningLog"); buffWriter.println(" message CDATA #REQUIRED"); buffWriter.println(" cellName CDATA #IMPLIED"); // only warning logs can have no cells buffWriter.println(" >"); buffWriter.println(" <!ATTLIST ERRORTYPEGEOM"); buffWriter.println(" geomName CDATA #REQUIRED"); buffWriter.println(" cellName CDATA #REQUIRED"); buffWriter.println(" >"); buffWriter.println(" <!ATTLIST ERRORTYPETHICKLINE"); buffWriter.println(" p1 CDATA #REQUIRED"); buffWriter.println(" p2 CDATA #REQUIRED"); buffWriter.println(" cellName CDATA #REQUIRED"); buffWriter.println(" >"); buffWriter.println(" <!ATTLIST ERRORTYPELINE"); buffWriter.println(" p1 CDATA #REQUIRED"); buffWriter.println(" p2 CDATA #REQUIRED"); buffWriter.println(" cellName CDATA #REQUIRED"); buffWriter.println(" >"); buffWriter.println(" ]>"); buffWriter.println(); String className = this.getClass().getSimpleName(); buffWriter.println("<" + className + " errorSystem=\"" + errorSystem + "\">");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -