private Context createContext(Lines lines) { // Primeira linha tem que ser context Line firstLine = lines.get(0); if (!firstLine.getLineType().equals(LineType.CONTEXT)) { throw new TxtException(PRIMEIRA_LINHA_DEVE_SER_CONTEXT); } ContextConverter converter = new ContextConverter(); Context context = converter.asObject(null, firstLine); // Demais linhas for (Line line : lines.getLines()) { if (line.getLineType().equals(LineType.CONSTANT)) { addConst(context, line); } else if (line.getLineType().equals(LineType.VARIABLE)) { addVar(context, line); } else if (line.getLineType().equals(LineType.DOMAIN)) { addDomain(context, line); } else if (line.getLineType().equals(LineType.METADATA)) { addMetadata(context, line); } else if (line.getLineType().equals(LineType.SCOPE)) { addScope(context, line); } else if (line.getLineType().equals(LineType.MESSAGE)) { addMessage(context, line); } else if (line.getLineType().equals(LineType.RULE)) { addRule(context, line); } else if (line.getLineType().equals(LineType.PROCESS)) { addProcess(context, line); } } // context.freeze(); // a partir de agora o Context é readonly!! return context; }
public Context load(String fileName, String encoding) { if (encoding == null) { encoding = "UTF-8"; } InputStream is = asStream(fileName); BufferedReader reader = null; Lines lines = new Lines(); try { reader = new BufferedReader(new InputStreamReader(is, encoding)); String lineStr; Line line; int lineNumber = 0; // A primeira linha válida tem que ser CONTEXT while ((lineStr = reader.readLine()) != null) { lines.add(lineStr); } return createContext(lines); } catch (IOException e) { throw new TxtException("Erro ao ler arquivo " + fileName, e); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } }
public List<String> getVariables(String filePath, int lineNumber) { Lines lines = files.get(filePath); if (lines == null) { return null; } Variables variables = lines.get(lineNumber); return variables; }
@Override // from interface IRectangle public boolean intersectsLine(double x1, double y1, double x2, double y2) { return Lines.lineIntersectsRect(x1, y1, x2, y2, x(), y(), width(), height()); }