public void actionPerformed(ActionEvent event) { try { File_Open_Save_Dialog openDialog = new File_Open_Save_Dialog(0); try { FileInput input = new FileInput(openDialog.fileName); routesInfo = input.routeArrayList(input.routesToken); routesInfo = sortRouteArray(routesInfo); airportsInfo = input.airportArrayList(input.airportsToken); closuresInfo = input.closureArrayList(input.closuresToken); routesInfo = routeClosureStatus(routesInfo, closuresInfo); // If one section has an error (is null) set all sections to null and lock all routes and // airprots menu items if (airportsInfo == null) { routesInfo = null; closuresInfo = null; systemLocked = true; } else if (routesInfo == null) { airportsInfo = null; closuresInfo = null; systemLocked = true; } else if (closuresInfo == null) { airportsInfo = null; routesInfo = null; systemLocked = true; } else { systemLocked = false; } String[][] data = convertArrayListTo2DArray(routesInfo, 1); updateRoutesTable(data); String historyText = ("The file " + openDialog.fileName + " has been opened."); historyArea.append(historyText + "\n"); // remove all searches from route search table Object[][] emptyData = new Object[0][7]; Main.updateResultsTable(emptyData); Main.historyArea.setText(""); } catch (NullPointerException e) { if (openDialog.fileName != null) { String historyText = ("there are errors in " + openDialog.fileName); historyArea.append(historyText + "\n"); } } catch (FileNotFoundException e) { String historyText = ("The file " + openDialog.fileName + " does not exist."); historyArea.append(historyText + "\n"); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void actionPerformed(ActionEvent event) { FileInput data = null; try { data = new FileInput("input.txt"); } catch (Exception e) { } String[][] origRoutes = convertArrayListTo2DArray(data.routeArrayList(data.routesToken), 1); String[][] routesList = Main.convertArrayListTo2DArray(routesInfo, 1); changesCheck(origRoutes, routesList); }
@Test public void testRead() { try (FileInput instance = new FileInput(testsFileName)) { String str = "token1,token2,token3\n\napples, oranges, pears\none , two , three\na,b,c,d,e,f\nunos, dos,tres,,quatorze\n\nlast, complete, line,\n# comment1, comment2, comment3\n\n"; String contents = instance.read(); assertTrue(str.equals(contents)); } catch (IOException ex) { fail("Caught IOException in testReadNextLine()"); } }
@Test public void testReadNextLine() { try (FileInput instance = new FileInput(testsFileName)) { String line = instance.readNextLine(); assertTrue("token1,token2,token3".equals(line)); line = instance.readNextLine(); assertTrue("apples, oranges, pears".equals(line)); line = instance.readNextLine(); assertTrue("one , two , three".equals(line)); line = instance.readNextLine(); assertTrue("a,b,c,d,e,f".equals(line)); line = instance.readNextLine(); assertTrue("unos, dos,tres,,quatorze".equals(line)); line = instance.readNextLine(); assertTrue("last, complete, line,".equals(line)); line = instance.readNextLine(); assertNull(line); } catch (IOException ex) { fail("Caught IOException in testReadNextLine()"); } }
@Test public void testReadNextLineAsTokensUsingDefaultSeparator() { try (FileInput instance = new FileInput(testsFileName)) { List<String> line = instance.readLine(); assertTrue(Arrays.asList("token1", "token2", "token3").equals(line)); line = instance.readLine(); assertTrue(Arrays.asList("apples", "", "oranges", "", "pears").equals(line)); line = instance.readLine(); assertTrue(Arrays.asList("one", "", "", "two", "", "", "three").equals(line)); line = instance.readLine(); assertTrue(Arrays.asList("a", "b", "c", "d", "e", "f").equals(line)); line = instance.readLine(); assertTrue(Arrays.asList("unos", "", "dos", "tres", "", "quatorze").equals(line)); line = instance.readLine(); assertTrue(Arrays.asList("last", "", "complete", "", "line", "").equals(line)); line = instance.readLine(); assertTrue(line.isEmpty()); } catch (IOException ex) { fail("Caught IOException in testReadNextLine()"); } }
public void actionPerformed(ActionEvent event) { FileInput data = null; try { data = new FileInput("input.txt"); } catch (Exception e) { } String[][] origRoutes = convertArrayListTo2DArray(data.routeArrayList(data.routesToken), 1); String[][] routesList = convertArrayListTo2DArray(routesInfo, 1); String[] origAirports = convertAirportArrayListToArray(data.airportArrayList(data.airportsToken)); String[] airportsList = convertAirportArrayListToArray(airportsInfo); String[][] origClosures = convertArrayListTo2DArray(data.closureArrayList(data.closuresToken), 0); String[][] closuresList = convertArrayListTo2DArray(closuresInfo, 0); changesCheck(origRoutes, routesList, origAirports, airportsList, origClosures, closuresList); }
@Test public void testclose() { try (FileInput instance = new FileInput(testsFileName)) { instance.readLine(); instance.readLine(); instance.close(); try { instance.readLine(); fail( "Expected IOException to be thrown after using a method on a closed FileInput object."); } catch (IOException ex) { // we expect an IOException to be caught here because the FileInput object is closed when // the readLine // method is called. } } catch (IOException ex) { fail("Caught IOException in testClose()"); } }
private List<URI> getUris(FileInput fileInput, Predicate<URI> uriPredicate) throws IOException { List<URI> uris; if (preGlobUri != null) { uris = fileInput.listUris(preGlobUri, uriPredicate); } else if (uriPredicate.apply(fileUri)) { uris = ImmutableList.of(fileUri); } else { uris = ImmutableList.of(); } return uris; }
@Override public void run(TaskSource taskSource, Schema schema, FileInput input, PageOutput output) { try (final PageBuilder pageBuilder = new PageBuilder(Exec.getBufferAllocator(), schema, output)) { while (input.nextFile()) { Buffer buffer = input.poll(); if (buffer != null) { for (Column column : schema.getColumns()) { Type type = column.getType(); switch (type.getName()) { case "boolean": pageBuilder.setBoolean(column, true); break; case "long": pageBuilder.setLong(column, 2L); break; case "double": pageBuilder.setDouble(column, 3.0D); break; case "string": pageBuilder.setString(column, "45"); break; case "timestamp": pageBuilder.setTimestamp(column, Timestamp.ofEpochMilli(678L)); break; default: throw new IllegalStateException("Unknown type: " + type.getName()); } } pageBuilder.addRecord(); if (raiseException) { throw new RuntimeException("emulated exception"); } } } pageBuilder.finish(); } }
private void readLines( FileInput fileInput, CollectorContext collectorContext, URI uri, long startLine, int retry) throws IOException { InputStream inputStream = fileInput.getStream(uri); if (inputStream == null) { return; } String line; long linesRead = 0L; try (BufferedReader reader = createReader(inputStream)) { while ((line = reader.readLine()) != null) { if (killed) { throw new CancellationException(); } linesRead++; if (linesRead < startLine) { continue; } if (line.length() == 0) { // skip empty lines continue; } collectorContext.lineContext().rawSource(line.getBytes(StandardCharsets.UTF_8)); if (!downstream.setNextRow(row)) { break; } } } catch (SocketTimeoutException e) { if (retry > MAX_SOCKET_TIMEOUT_RETRIES) { LOGGER.info("Timeout during COPY FROM '{}' after {} retries", e, uri.toString(), retry); throw e; } else { readLines(fileInput, collectorContext, uri, linesRead + 1, retry + 1); } } catch (Exception e) { // it's nice to know which exact file/uri threw an error // when COPY FROM returns less rows than expected LOGGER.info("Error during COPY FROM '{}'", e, uri.toString()); throw e; } }
private Predicate<URI> generateUriPredicate(FileInput fileInput) { Predicate<URI> moduloPredicate; boolean sharedStorage = MoreObjects.firstNonNull(shared, fileInput.sharedStorageDefault()); if (sharedStorage) { moduloPredicate = new Predicate<URI>() { @Override public boolean apply(URI input) { int hash = input.hashCode(); if (hash == Integer.MIN_VALUE) { hash = 0; // Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE } return Math.abs(hash) % numReaders == readerNumber; } }; } else { moduloPredicate = MATCH_ALL_PREDICATE; } if (globPredicate != null) { return Predicates.and(moduloPredicate, globPredicate); } return moduloPredicate; }
@Override public void onAnalysisParamValueSelected(AnalysisParamValueSelectedEvent event) { final AnalysisParameter value = event.getValue(); if (!((Input.equals(value.getType()) || FileInput.equals(value.getType()) || FolderInput.equals(value.getType()) || FileFolderInput.equals(value.getType()) || MultiFileSelector.equals(value.getType())))) { return; } String infoType = value.getInfoType(); if (infoType.equalsIgnoreCase("ReferenceGenome") || infoType.equalsIgnoreCase("ReferenceSequence") || infoType.equalsIgnoreCase("ReferenceAnnotation")) { return; } final File hasPath = factory.file().as(); hasPath.setPath(value.getDisplayValue()); final FastMap<TYPE> typeFastMap = diskResourceUtil.asStringPathTypeMap(Lists.newArrayList(hasPath), TYPE.FILE); diskResourceServiceAsyncProvider.get( new AsyncCallback<DiskResourceServiceFacade>() { @Override public void onFailure(Throwable caught) { ErrorHandler.post(caught); } @Override public void onSuccess(DiskResourceServiceFacade service) { service.getStat( typeFastMap, new GetStatCallback(value, eventBus, announcer, appearance)); } }); }
/** * Synchronises a list of columns in one file with that of a second file. * * <p>Can also convert the names being used to synchronise into numbers, (third argument) the map * being output in <em>fileName1</em><tt>NameToIndex.dat</tt> files (unless specified by the 4th * argument). * * <p>That is it creates a list of paper ids common to both files, creates a map of these ids to * numbers (in alphabetical order) and finally outputs copies (with <tt>.sync.dat</tt> extensions * to input filenames unless specified by last two arguments) of both files. * * @param args command line arguments */ public static void main(String[] args) { System.out.println( "PaperSynchoniser Arguments: (input file 1) (input file 2) (convertToIndex y,t or n,f)(ouput file name of name to index list) (output file name 1) (output file name 2)"); // First arg chooses file with papers listed // String fileName1="input/ICteststemptinputBVNLS.dat"; // String fileName1="input/ICteststemppinputELS.dat"; // String fileName1="input/ICNS090729stemptinputBVNLS.dat"; // String fileName1="input/ICNS090224stemptinputBVNLS.dat"; // String fileName1="input/RAEmanSubGCCinputELS.dat"; String fileName1 = "input/RAEmanGCCinputELS.dat"; int ano = 0; if (args.length > ano) fileName1 = args[ano]; System.out.println("--- File defining first vertex set " + fileName1); // Second arg chooses second file which needs to be synchronised // String fileName2="input/ICtest_psecinputBVNLS.dat"; // String fileName2="input/ICNS090224npstemppew0020inputELS.dat";; // String fileName2="input/IC090521_psecinputBVNLS.dat"; // String fileName2="input/RAEmanAuthorDisciplineinputBVNLS.dat"; // String fileName2="input/RAEmanSubAuthorDisciplineinputBVNLS.dat"; String fileName2 = "input/RAEmanAuthorInstituteinputBVNLS.dat"; ano++; if (args.length > ano) fileName2 = args[ano]; System.out.println("--- File defining second vertex set " + fileName2); boolean convertToIndex = false; ano++; if (args.length > ano) convertToIndex = StringFilter.trueString(args[ano]); System.out.println("--- " + (convertToIndex ? "C" : "Not c") + "onverting names to strings"); // Output file for name to index int c = -1; c = fileName1.lastIndexOf('.'); if (c < 0) c = fileName1.length(); String fullNameToIndexFileName = fileName1.substring(0, c) + ".NameToIndex.dat"; // String fileName2="input/ICNS090224npstemppew0020inputELS.dat";; ano++; if (args.length > ano) fullNameToIndexFileName = args[ano]; System.out.println("--- Name to Index file " + fullNameToIndexFileName); // Output file for copy of synchronised of first file int c1 = fileName1.lastIndexOf('.'); if (c1 < 0) c = fileName1.length(); String fullOutputFileName1 = fileName1.substring(0, c1) + ".sync.dat"; // String fileName2="input/ICNS090224npstemppew0020inputELS.dat";; ano++; if (args.length > ano) fullOutputFileName1 = args[ano]; System.out.println("--- Output file 1 " + fullOutputFileName1); // Output file for copy of synchronised of second file int c2 = fileName2.lastIndexOf('.'); if (c2 < 0) c2 = fileName2.length(); String fullOutputFileName2 = fileName2.substring(0, c2) + ".sync.dat"; // String fileName2="input/ICNS090224npstemppew0020inputELS.dat";; ano++; if (args.length > ano) fullOutputFileName2 = args[ano]; System.out.println("--- Output file 2 " + fullOutputFileName2); FileInput fi = new FileInput((infoOn ? 0 : -2)); String cc = ""; TreeSet<Integer> vertexColumnSet1 = new TreeSet(); vertexColumnSet1.add(1); if (fileName1.endsWith("ELS.dat") || fileName1.endsWith("EL.dat")) vertexColumnSet1.add(2); boolean forceLowerCase = true; TreeSet<String> vertexLL1 = new TreeSet(); vertexLL1.addAll(fi.readStringColumnsFromFile(fileName1, cc, vertexColumnSet1, forceLowerCase)); TreeSet<Integer> vertexColumnSet2 = new TreeSet(); vertexColumnSet2.add(1); if (fileName2.endsWith("ELS.dat") || fileName2.endsWith("EL.dat")) vertexColumnSet2.add(2); forceLowerCase = true; TreeSet<String> vertexLL2 = new TreeSet(); vertexLL2.addAll(fi.readStringColumnsFromFile(fileName2, cc, vertexColumnSet2, forceLowerCase)); // make set of common vertices (intersection) TreeSet<String> vertexAll = new TreeSet(); vertexAll.addAll(vertexLL1); vertexAll.retainAll(vertexLL2); if (infoOn) System.out.println( "Found " + vertexAll.size() + " common vertices from " + vertexLL1.size() + " in file 1 and " + vertexLL2.size() + " in file 2"); // convert common vertices to numbers TreeMap<String, Integer> vertexNameToIndex = new TreeMap(); int index = 0; for (String name : vertexAll) vertexNameToIndex.put(name, index++); // for (String k: vertexNameToIndex.keySet()) System.out.println(k+" : // "+vertexNameToIndex.get(k)); String sep = "\t"; String[] headerLines = new String[1]; headerLines[0] = "#name" + sep + "index"; FileOutput.map(vertexNameToIndex, fullNameToIndexFileName, headerLines, sep, infoOn); synchroniseVertexList( vertexNameToIndex, fileName1, fullOutputFileName1, fileName2, cc, sep, vertexColumnSet1, convertToIndex, forceLowerCase, infoOn); synchroniseVertexList( vertexNameToIndex, fileName2, fullOutputFileName2, fileName1, cc, sep, vertexColumnSet2, convertToIndex, forceLowerCase, infoOn); }
public static void main(String[] args) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(GUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } // </editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater( new Runnable() { public void run() { new GUI().setVisible(true); } }); FileInput f = null; ArrayList<Airport> air; LinkedList<Route> r; try { f = new FileInput(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } air = f.getAirports(); r = f.getRoutes(); System.out.println(r.getFirst().toString()); System.out.println(air.get(0).toString()); /* //test=r.toArray(); String[] temp; for(int i=0;i<r.size();i++){ temp=r.get(i).toArray(); for(int k=0;k<temp.length;i++){ g.RouteTable.setValueAt(temp[k], i, k); } } */ }
/** * Utility method loads all of the workflow form definitions from yaml files contained in the * workflow directory. * * @return */ public static List<FormDefinition> loadWorkflowFormDefinitions() { // List<FormDefinition> formDefs = new ArrayList<>(); // // URL path = Play.application().classloader().getResource(WORKFLOWS_PATH); // try { // File dir = new File(path.toURI()); // // File[] workflows = dir.listFiles(new FilenameFilter() { // public boolean accept(File dir, String name) { // return name.toLowerCase().endsWith(".yaml"); // } // }); // // for (File file : workflows) { // formDefs.add(loadFormDefinition(file.getAbsolutePath())); // } // } catch (URISyntaxException e) { /* Should not occur */ } List<FormDefinition> formDefs = new ArrayList<>(); Collection<config.WorkflowConfig> workflows = ConfigManager.getInstance().getWorkflowConfigs(); for (config.WorkflowConfig workflow : workflows) { FormDefinition formDef = new FormDefinition(); formDef.name = workflow.getName(); formDef.title = workflow.getTitle(); formDef.yamlFile = workflow.getYaml(); formDef.documentation = workflow.getDocumentation(); formDef.instructions = workflow.getInstructions(); formDef.summary = workflow.getSummary(); for (ParameterConfig parameter : workflow.getParameters()) { if (parameter.isTyped()) { String type = parameter.getType(); switch (type) { case "text": TextField textField = new TextField(); textField.name = parameter.getName(); textField.label = parameter.getLabel(); textField.tooltip = parameter.getDescription(); formDef.addField(textField); break; case "select": SelectField selectField = new SelectField(); selectField.name = parameter.getName(); selectField.label = parameter.getLabel(); selectField.options = parameter.getOptions(); selectField.tooltip = parameter.getDescription(); formDef.addField(selectField); break; case "upload": FileInput fileInput = new FileInput(); fileInput.name = parameter.getName(); fileInput.label = parameter.getLabel(); fileInput.tooltip = parameter.getDescription(); formDef.addField(fileInput); break; } } } formDefs.add(formDef); } return formDefs; }
/** * Main program. Expects three arguments:<br> * <code> <feature_file.xml> <product_name> <person-days-available></code><br> * Any errors result in an error message and a usage message to stderr and termination with an * exit code of -1. Correct execution will result in an exit code of 0. */ public static void main(String[] argv) { // get data from test scaffolding // The real XML file reader is being worked on now. FileInput reader = new TestInput(); // check for correct number of arguments if (argv.length != 3) dieUsage("wrong number of arguments"); // check for non-null filename String filename = argv[0]; if (filename == null || filename.equals("")) dieUsage("empty filename specified"); // check for non-null osftware product String software = argv[1]; if (software == null || software.equals("")) dieUsage("empty software name specified"); // parse capacity, checking for errors String capacityStr = argv[2]; double capacity = 0.0; try { capacity = Double.parseDouble(capacityStr); } catch (NumberFormatException e) { dieUsage("Illegal capacity specified, '" + capacityStr + "'"); } if (capacity <= 0) dieUsage("Capacity specified, '" + capacityStr + "' must be be greater than 0"); // read the XML feature file. Returns the root "Company" object from the file. Company c = null; try { c = reader.readFile(filename); } catch (java.io.FileNotFoundException e) { dieUsage("File not found, '" + filename + "'"); } catch (java.io.IOException e) { dieUsage("IO error while opening file '" + filename + "'"); } // check that software product specified on the command line exists in the file Software s = c.getSoftware(software); if (s == null) dieUsage("Specified software product not found, '" + software + "'"); // plan a release given the capacity in person-days specified on the command line Release planned = s.planRelease(capacity); planned.setDesignator("in-plan"); // plan a second release given the extra capacity and subtract the features from // the above rleease, leaving just the excess. Release overflow = s.planRelease(capacity * JUST_MISSED_RATIO); overflow.subtract(planned); overflow.setDesignator("just-missed"); // write the report header, echoing the comamnd line Report.writeHeader( "File: " + filename + " Product: " + software + " Capacity: " + capacityStr); // write a summary chart for all the features, the in-plan features, and the just-missed // features final FeatureList[] featureListsToSummarize = {s, planned, overflow}; Report.writeSummaryTable(featureListsToSummarize); // write details for the in-plan features Report.writeFeatures("In-Plan Features for sizing " + capacityStr, planned); // write details for the just-missed features Report.writeFeatures( "Just-Missed Features under sizing " + capacity * JUST_MISSED_RATIO, overflow); // all went well System.exit(0); }
public JPanel Panels() throws IOException { Object[][] data = new Object[0][7]; // Create the initial Routes Table try { FileInput input = new FileInput("input.txt"); // read the input file // get the data from input.txt routesInfo = input.routeArrayList(input.routesToken); routesInfo = sortRouteArray(routesInfo); airportsInfo = input.airportArrayList(input.airportsToken); closuresInfo = input.closureArrayList(input.closuresToken); routesInfo = routeClosureStatus(routesInfo, closuresInfo); // If one section has an error (is null) set all sections to null and lock all routes and // airprots menu items if (airportsInfo == null) { routesInfo = null; closuresInfo = null; systemLocked = true; } else if (routesInfo == null) { airportsInfo = null; closuresInfo = null; systemLocked = true; } else if (closuresInfo == null) { airportsInfo = null; routesInfo = null; systemLocked = true; } data = convertArrayListTo2DArray(routesInfo, 1); } catch (FileNotFoundException e1) { // If input.txt is missing System.out.println("The file input.txt is missing."); } catch (NullPointerException e1) { // If there are any other errors in the file System.out.println("There are errors in the input.txt file"); } routePanel.add(CreateRouteTable(data, totalSize)); // add the table to the JPanel routePanel.setBorder(BorderFactory.createTitledBorder("Route Table")); // ------------------------------------------------end of route // table-------------------------------------------------------- histPanel.setPreferredSize(new Dimension(totalSize.width, totalSize.height / 5)); histPanel.setBorder(BorderFactory.createTitledBorder("History")); historyArea = new TextArea(); historyArea.setEditable(false); historyArea.setPreferredSize(new Dimension(totalSize.width * 7 / 10, totalSize.height / 7)); histPanel.add(historyArea); // ------------------------------------------------end of history // table-------------------------------------------------------- Object[][] emptyData = new Object[0][7]; resultsPanel.setBorder(BorderFactory.createTitledBorder("Search Results")); resultsPanel.add(CreateResultsTable(emptyData, totalSize)); // ------------------------------------------------end of results // table-------------------------------------------------------- mainPanel.add(routePanel, BorderLayout.WEST); mainPanel.add(histPanel, BorderLayout.SOUTH); mainPanel.add(resultsPanel, BorderLayout.EAST); return mainPanel; }
/** * Makes a copy of a vertex neighbour list file with only vertices in given list. Reads in a file * (typically an vertex neighbour list) and outputs a copy except for any lines whose first entry * is not in given vertex list. * * <p>Each line has entries separated by whitespace. Comment lines are always copied. * * @param vertexNameToIndex map from vertex name to an index * @param fullInputFileName full filename of input file to be copied. * @param fullOutputFileName full filename of output file * @param fullOtherInputFileName full filename of second input file needed for synchronisation * @param cc if, after any white space, first word starts with this string then line is treated as * a comment line. * @param sep sepation character, e.g. tab * @param vertexColumnList list of columns to be compared * @param convertToIndex convert the vertex names to an index as given by the map provided * @param forceLowerCase force all strings to be lower case * @param infoOn true if want more info printed out */ public static int synchroniseVertexList( Map<String, Integer> vertexNameToIndex, String fullInputFileName, String fullOutputFileName, String fullOtherInputFileName, String cc, String sep, Set<Integer> vertexColumnList, boolean convertToIndex, boolean forceLowerCase, boolean infoOn) { int maxColumn = -1; for (Integer vertexColumn : vertexColumnList) { if (vertexColumn < 1) throw new RuntimeException( "first column is numbered 1, column with vertices given as " + vertexColumn); maxColumn = Math.max(vertexColumn, maxColumn); } int res = 0; // error code. boolean dontTestForCommentLine = false; if (cc.length() == 0) dontTestForCommentLine = true; // set up input file TextReader data = FileInput.openFile(fullInputFileName); if (data == null) { System.err.println( "*** synchroniseVertexList input file " + fullInputFileName + " not opened"); return -1; } if (infoOn) { System.out.print("Starting to do vertex synchronisation on columns "); for (Integer vertexColumn : vertexColumnList) System.out.print(vertexColumn + ", "); System.out.println(" of file " + fullInputFileName); if (convertToIndex) System.out.println("Converting names to indices"); } // Make a copy of vertices and note when they have been found. TreeSet<String> vertexFoundLL = new TreeSet(); TreeSet<String> vertexNotFound = new TreeSet(); // vertices in vertexNameToIndex not in file // set up output file PrintStream PS; FileOutputStream fout; try { fout = new FileOutputStream(fullOutputFileName); PS = new PrintStream(fout); } catch (FileNotFoundException e) { throw new RuntimeException( "**** synchroniseVertexList output file " + fullOutputFileName + " not opened, " + e.getMessage()); // return -2; } int linenumber = 0; int verticesInput = 0; int verticesOutput = 0; String[] vertexFound = new String[vertexColumnList.size()]; try { // Read the data from the input file. String[] numbers = new String[1000]; int column = 0; // number of columns on each line String vertex; while (data.eof() == false) { // Read until end-of-file. linenumber++; column = 0; // Read until end-of-line. if (forceLowerCase) while (data.eoln() == false) numbers[column++] = data.getWord().toLowerCase(); else while (data.eoln() == false) numbers[column++] = data.getWord(); if (maxColumn > column) throw new RuntimeException( "on line " + linenumber + " found " + column + " columns (first is numbered 1) but synchronising on column " + maxColumn); try { // next tests for first word starting for comment line string but only if this is a // nontrivial string if (dontTestForCommentLine || !numbers[0].startsWith(cc)) { boolean lineOK = true; int vc = 0; for (Integer vertexColumn : vertexColumnList) { vertex = numbers[vertexColumn - 1]; verticesInput++; if (!vertexNameToIndex.containsKey(vertex)) { lineOK = false; } vertexFound[vc++] = vertex; } if (!lineOK) continue; // the while statement // try to use vertexFoundLL.addAll; verticesOutput+=vertexColumnList.length; for (vc = 0; vc < vertexFound.length; vc++) { verticesOutput++; vertexFoundLL.add(vertexFound[vc]); } // eo for vc } // eo if (dontTestForCommentLine ... // Now write this line out to output file. // This will happen if its a comment line or if all vertices in specified columns are in // the given vertex list int columnMinusOne = column - 1; // this will be the index of the last column if (convertToIndex) for (int c = 0; c < column; c++) { PS.print( ((vertexColumnList.contains(c)) ? vertexNameToIndex.get(numbers[c]) : numbers[c]) + (c == columnMinusOne ? "" : sep)); } else { for (int c = 0; c < column; c++) PS.print(numbers[c] + (c == columnMinusOne ? "" : sep)); } PS.println(); } // eo try catch (RuntimeException e) { throw new RuntimeException( "*** PROBLEM on line " + linenumber + " of input file, " + e.getMessage()); } } // eofile for (String name : vertexNameToIndex.keySet()) if (!vertexFoundLL.contains(name)) vertexNotFound.add(name); if (infoOn) { System.out.println( "Finished vertex synchronisation on first column of file " + fullInputFileName + " producing " + fullOutputFileName); System.out.println( " " + linenumber + " input lines found " + verticesInput + " lines with vertices, wrote " + verticesOutput + " lines with vertices in given list."); System.out.println( " Given " + vertexNameToIndex.size() + " distinct input vertices, " + vertexNotFound.size() + " were not used."); System.out.println(" Output " + vertexFoundLL.size() + " distinct output vertices."); } } // eo try catch (TextReader.Error e) { // Some problem reading the data from the input file. res = -3; throw new RuntimeException( "*** File Error in " + fullInputFileName + " or " + fullOutputFileName + ", " + e.getMessage()); } finally { // Finish by closing the files, // whatever else may have happened. try { data.close(); fout.close(); } catch (IOException e) { throw new RuntimeException( "*** File Error closing " + fullInputFileName + " or " + fullOutputFileName + ", " + e.getMessage()); } } // eo finally // write out information file String infoOutputFileName = fullOutputFileName + ".info.txt"; try { fout = new FileOutputStream(infoOutputFileName); PS = new PrintStream(fout); } catch (FileNotFoundException e) { res = -2; throw new RuntimeException( "**** synchroniseVertexList information file " + infoOutputFileName + " not opened, " + e.getMessage()); } PS.println( "Vertex synchronisation on first column of file " + fullInputFileName + "against file " + fullOtherInputFileName + " producing " + fullOutputFileName); PS.println( " " + linenumber + " input lines found " + verticesInput + " lines with vertices, wrote " + verticesOutput + " lines with vertices in given list."); PS.println( " Given " + vertexNameToIndex.size() + " distinct input vertices, " + vertexNotFound.size() + " were not used."); PS.println(" Output " + vertexFoundLL.size() + " distinct output vertices."); if (vertexNotFound.size() > 0) { PS.println("Vertices in input list not found in synchronised file"); PS.println("name" + sep + "index"); for (String name : vertexNotFound) PS.println(name + sep + vertexNameToIndex.get(name)); } try { } // eo try catch (RuntimeException e) { res = -4; throw new RuntimeException( "*** File Error in information output file " + infoOutputFileName + ", " + e.getMessage()); } finally { // Finish by closing the files, // whatever else may have happened. try { fout.close(); } catch (IOException e) { throw new RuntimeException( "*** File Error closing " + infoOutputFileName + ", " + e.getMessage()); } } return res; }