List of usage examples for java.util HashSet HashSet
public HashSet(int initialCapacity)
From source file:au.csiro.casda.sodalint.SodaLinter.java
/** * Command line handler for SodaLinter/* w w w .j av a2 s . c o m*/ * @param args The command line arguments * @throws Exception If an otherwise uncaught error occurs. */ public static void main(String[] args) throws Exception { SodaLinter linter = new SodaLinter(); String[] stages = null; final int defaultMaxRepeat = 9; final int defaultMaxLineLen = 1024; int maxRepeat = defaultMaxRepeat; int maxLineLen = defaultMaxLineLen; String sodaUrl = null; boolean error = false; for (String arg : args) { if (arg.startsWith("stages=")) { stages = arg.substring("stages=".length()).split(" "); } else if (arg.startsWith("maxrepeat=")) { String value = arg.substring("maxrepeat=".length()); if (StringUtils.isNumeric(value)) { maxRepeat = Integer.parseInt(value); } else { error = true; } } else if (arg.startsWith("truncate=")) { String value = arg.substring("truncate=".length()); if (StringUtils.isNumeric(value)) { maxLineLen = Integer.parseInt(value); } else { error = true; } } else { sodaUrl = arg.startsWith("sodaurl=") ? arg.substring("sodaurl=".length()) : arg; } } if (sodaUrl == null || error) { System.out.println( "Usage: java -jar sodalint-full.jar [stages=\"CPV|CAP|AVV|EXM|SVD|ERR|SYN|ASY[ ...]\"] " + "[maxrepeat=<int-value>] [truncate=<int-value>] [sodaurl=]<url-value>"); System.exit(1); } TextOutputReporter reporter = new TextOutputReporter(System.out, ReportType.values(), maxRepeat, false, maxLineLen); // URL serviceUrl = new URL("https://casda-dev-app.pawsey.org.au/casda_data_access/data/"); URL serviceUrl = new URL(sodaUrl); String[] defaultStages = new String[] { Stage.CAP_XML.getCode(), Stage.AVAIL_XML.getCode(), Stage.CAPABILITIES.getCode(), Stage.SYNC.getCode(), Stage.ASYNC.getCode(), Stage.SERVICE_DESC.getCode() }; Set<String> codes = new HashSet<>(Arrays.asList(stages != null ? stages : defaultStages)); Executable executable = linter.createExecutable(reporter, serviceUrl, codes, null); executable.execute(); }
From source file:com.genentech.chemistry.openEye.apps.SDFTopologicalIndexer.java
/** * @param args/*from ww w.j a v a2 s. c o m*/ */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); opt.setArgName("fn"); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } if (args.length == 0) { System.err.println("Specify at least one index type"); exitWithHelp(options); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); Set<String> selectedIndexes = new HashSet<String>(args.length); if (args.length == 1 && "all".equalsIgnoreCase(args[0])) selectedIndexes = AVAILIndexes; else selectedIndexes.addAll(Arrays.asList(args)); if (!AVAILIndexes.containsAll(selectedIndexes)) { selectedIndexes.removeAll(AVAILIndexes); StringBuilder err = new StringBuilder("Unknown Index types: "); for (String it : selectedIndexes) err.append(it).append(" "); System.err.println(err); exitWithHelp(options); } SDFTopologicalIndexer sdfIndexer = new SDFTopologicalIndexer(outFile, selectedIndexes); sdfIndexer.run(inFile); sdfIndexer.close(); }
From source file:de.morbz.osmpoispbf.Scanner.java
public static void main(String[] args) { System.out.println("OsmPoisPbf " + VERSION + " started"); // Get input file if (args.length < 1) { System.out.println("Error: Please provide an input file"); System.exit(-1);//from www .j a v a 2s .c o m } String inputFile = args[args.length - 1]; // Get output file String outputFile; int index = inputFile.indexOf('.'); if (index != -1) { outputFile = inputFile.substring(0, index); } else { outputFile = inputFile; } outputFile += ".csv"; // Setup CLI parameters options = new Options(); options.addOption("ff", "filterFile", true, "The file that is used to filter categories"); options.addOption("of", "outputFile", true, "The output CSV file to be written"); options.addOption("rt", "requiredTags", true, "Comma separated list of tags that are required [name]"); options.addOption("ut", "undesiredTags", true, "Comma separated list of tags=value combinations that should be filtered [key=value]"); options.addOption("ot", "outputTags", true, "Comma separated list of tags that are exported [name]"); options.addOption("ph", "printHeader", false, "If flag is set, the `outputTags` are printed as first line in the output file."); options.addOption("r", "relations", false, "Parse relations"); options.addOption("nw", "noWays", false, "Don't parse ways"); options.addOption("nn", "noNodes", false, "Don't parse nodes"); options.addOption("u", "allowUnclosedWays", false, "Allow ways that aren't closed"); options.addOption("d", "decimals", true, "Number of decimal places of coordinates [7]"); options.addOption("s", "separator", true, "Separator character for CSV [|]"); options.addOption("v", "verbose", false, "Print all found POIs"); options.addOption("h", "help", false, "Print this help"); // Parse parameters CommandLine line = null; try { line = (new DefaultParser()).parse(options, args); } catch (ParseException exp) { System.err.println(exp.getMessage()); printHelp(); System.exit(-1); } // Help if (line.hasOption("help")) { printHelp(); System.exit(0); } // Get filter file String filterFile = null; if (line.hasOption("filterFile")) { filterFile = line.getOptionValue("filterFile"); } // Get output file if (line.hasOption("outputFile")) { outputFile = line.getOptionValue("outputFile"); } // Check files if (inputFile.equals(outputFile)) { System.out.println("Error: Input and output files are the same"); System.exit(-1); } File file = new File(inputFile); if (!file.exists()) { System.out.println("Error: Input file doesn't exist"); System.exit(-1); } // Check OSM entity types boolean parseNodes = true; boolean parseWays = true; boolean parseRelations = false; if (line.hasOption("noNodes")) { parseNodes = false; } if (line.hasOption("noWays")) { parseWays = false; } if (line.hasOption("relations")) { parseRelations = true; } // Unclosed ways allowed? if (line.hasOption("allowUnclosedWays")) { onlyClosedWays = false; } // Get CSV separator char separator = '|'; if (line.hasOption("separator")) { String arg = line.getOptionValue("separator"); if (arg.length() != 1) { System.out.println("Error: The CSV separator has to be exactly 1 character"); System.exit(-1); } separator = arg.charAt(0); } Poi.setSeparator(separator); // Set decimals int decimals = 7; // OSM default if (line.hasOption("decimals")) { String arg = line.getOptionValue("decimals"); try { int dec = Integer.valueOf(arg); if (dec < 0) { System.out.println("Error: Decimals must not be less than 0"); System.exit(-1); } else { decimals = dec; } } catch (NumberFormatException ex) { System.out.println("Error: Decimals have to be a number"); System.exit(-1); } } Poi.setDecimals(decimals); // Verbose mode? if (line.hasOption("verbose")) { printPois = true; } // Required tags if (line.hasOption("requiredTags")) { String arg = line.getOptionValue("requiredTags"); requiredTags = arg.split(","); } // Undesired tags if (line.hasOption("undesiredTags")) { String arg = line.getOptionValue("undesiredTags"); undesiredTags = new HashMap<>(); for (String undesired : arg.split(",")) { String[] keyVal = undesired.split("="); if (keyVal.length != 2) { System.out.println("Error: Undesired Tags have to formated like tag=value"); System.exit(-1); } if (!undesiredTags.containsKey(keyVal[0])) { undesiredTags.put(keyVal[0], new HashSet<>(1)); } undesiredTags.get(keyVal[0]).add(keyVal[1]); } } // Output tags if (line.hasOption("outputTags")) { String arg = line.getOptionValue("outputTags"); outputTags = arg.split(","); } // Get filter rules FilterFileParser parser = new FilterFileParser(filterFile); filters = parser.parse(); if (filters == null) { System.exit(-1); } // Setup CSV output try { writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF8")); } catch (IOException e) { System.out.println("Error: Output file error"); System.exit(-1); } // Print Header if (line.hasOption("printHeader")) { String header = "category" + separator + "osm_id" + separator + "lat" + separator + "lon"; for (int i = 0; i < outputTags.length; i++) { header += separator + outputTags[i]; } try { writer.write(header + "\n"); } catch (IOException e) { System.out.println("Error: Output file write error"); System.exit(-1); } } // Setup OSMonaut EntityFilter filter = new EntityFilter(parseNodes, parseWays, parseRelations); Osmonaut naut = new Osmonaut(inputFile, filter, false); // Start watch StopWatch stopWatch = new StopWatch(); stopWatch.start(); // Start OSMonaut String finalSeparator = String.valueOf(separator); naut.scan(new IOsmonautReceiver() { boolean entityNeeded; @Override public boolean needsEntity(EntityType type, Tags tags) { // Are there any tags? if (tags.size() == 0) { return false; } // Check required tags for (String tag : requiredTags) { if (!tags.hasKey(tag)) { return false; } } entityNeeded = getCategory(tags, filters) != null; if (undesiredTags != null && entityNeeded) { for (String key : undesiredTags.keySet()) { if (tags.hasKey(key)) { for (String val : undesiredTags.get(key)) { if (tags.hasKeyValue(key, val)) { return false; } } } } } return entityNeeded; } @Override public void foundEntity(Entity entity) { // Check if way is closed if (onlyClosedWays && entity.getEntityType() == EntityType.WAY) { if (!((Way) entity).isClosed()) { return; } } // Get category Tags tags = entity.getTags(); String cat = getCategory(tags, filters); if (cat == null) { return; } // Get center LatLon center = entity.getCenter(); if (center == null) { return; } // Make OSM-ID String type = ""; switch (entity.getEntityType()) { case NODE: type = "node"; break; case WAY: type = "way"; break; case RELATION: type = "relation"; break; } String id = String.valueOf(entity.getId()); // Make output tags String[] values = new String[outputTags.length]; for (int i = 0; i < outputTags.length; i++) { String key = outputTags[i]; if (tags.hasKey(key)) { values[i] = tags.get(key).replaceAll(finalSeparator, "").replaceAll("\"", ""); } } // Make POI poisFound++; Poi poi = new Poi(values, cat, center, type, id); // Output if (printPois && System.currentTimeMillis() > lastMillis + 40) { printPoisFound(); lastMillis = System.currentTimeMillis(); } // Write to file try { writer.write(poi.toCsv() + "\n"); } catch (IOException e) { System.out.println("Error: Output file write error"); System.exit(-1); } } }); // Close writer try { writer.close(); } catch (IOException e) { System.out.println("Error: Output file close error"); System.exit(-1); } // Output results stopWatch.stop(); printPoisFound(); System.out.println(); System.out.println("Elapsed time in milliseconds: " + stopWatch.getElapsedTime()); // Quit System.exit(0); }
From source file:com.acapulcoapp.alloggiatiweb.FileReader.java
public static void main(String[] args) throws UnknownHostException, IOException { // TODO code application logic here SpringApplication app = new SpringApplication(AcapulcoappApp.class); SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args); addDefaultProfile(app, source);//from w w w. j a v a2 s . com ConfigurableApplicationContext context = app.run(args); initBeans(context); Map<LocalDate, List<List<String>>> map = new TreeMap<>(); List<File> files = new ArrayList<>(FileUtils.listFiles(new File("/Users/chiccomask/Downloads/ALLOGGIATI"), new String[] { "txt" }, true)); Collections.reverse(files); int count = 0; for (File file : files) { // List<String> allLines = FileUtils.readLines(file, "windows-1252"); List<String> allLines = FileUtils.readLines(file, "UTF-8"); for (int i = 0; i < allLines.size();) { count++; List<String> record = new ArrayList<>(); String line = allLines.get(i); String type = TIPO_ALLOGGIO.parse(line); switch (type) { case "16": record.add(line); i++; break; case "17": { record.add(line); boolean out = false; while (!out) { i++; if (i < allLines.size()) { String subline = allLines.get(i); String subtype = TIPO_ALLOGGIO.parse(subline); if (!subtype.equals("19")) { out = true; } else { record.add(subline); } } else { out = true; } } break; } case "18": { record.add(line); boolean out = false; while (!out) { i++; if (i < allLines.size()) { String subline = allLines.get(i); String subtype = TIPO_ALLOGGIO.parse(subline); if (!subtype.equals("20")) { out = true; } else { record.add(subline); } } else { out = true; } } break; } default: break; } LocalDate arrived = LocalDate.parse(DATA_ARRIVO.parse(line), DateTimeFormatter.ofPattern(DATE_PATTERN)); if (!map.containsKey(arrived)) { map.put(arrived, new ArrayList<>()); } map.get(arrived).add(record); } } for (LocalDate date : map.keySet()) { System.out.println(); System.out.println("process day " + date); for (List<String> record : map.get(date)) { System.out.println(); System.out.println("process record "); for (String line : record) { System.out.println(line); } CheckinRecord checkinRecord = new CheckinRecord(); //non lo setto per adesso String firstLine = record.get(0); String typeStr = TIPO_ALLOGGIO.parse(firstLine); CheckinType cht = checkinTypeRepository.find(typeStr); checkinRecord.setCheckinType(cht); int days = Integer.parseInt(PERMANENZA.parse(firstLine)); checkinRecord.setDays(days); checkinRecord.setArrived(date); boolean isMain = true; List<Person> others = new ArrayList<>(); for (String line : record) { Person p = extractPerson(line); if (p.getDistrictOfBirth() == null) { System.out.println("district of birth not found " + p); } List<Person> duplicates = personRepository.findDuplicates(p.getSurname(), p.getName(), p.getDateOfBirth()); if (duplicates.isEmpty()) { System.out.println("add new person " + p.getId() + " " + p); personRepository.saveAndFlush(p); } else if (duplicates.size() == 1) { Person found = duplicates.get(0); if (p.getIdentityDocument() != null) { //we sorted by date so we suppose //the file version is newer so we update the entity p.setId(found.getId()); System.out.println("update person " + p.getId() + " " + p); personRepository.saveAndFlush(p); } else if (found.getIdentityDocument() != null) { //on db there are more data so I use them. p = found; System.out.println("use already saved person " + p.getId() + " " + p); } else { p.setId(found.getId()); System.out.println("update person " + p.getId() + " " + p); personRepository.saveAndFlush(p); } } else { throw new RuntimeException("More duplicated for " + p.getName()); } if (isMain) { checkinRecord.setMainPerson(p); isMain = false; } else { others.add(p); } } checkinRecord.setOtherPeople(new HashSet<>(others)); if (checkinRecordRepository.alreadyExists(checkinRecord.getMainPerson(), date) != null) { System.out.println("already exists " + date + " p " + checkinRecord.getMainPerson()); } else { System.out.println("save record "); checkinRecordRepository.saveAndFlush(checkinRecord); } } } // // if (type.equals("16")) { // List<String> record = new ArrayList<>(); // record.add(line); // keepOpen = false; // } // // map.get(arrived).add(record); // map.values().forEach((list) -> { // // for (String line : list) { // // Person p = null; // // try { // // p = extractPerson(line); // // List<Person> duplicates = personRepository.findDuplicates(p.getSurname(), p.getName(), p.getDateOfBirth()); // // if (duplicates.isEmpty()) { // personRepository.saveAndFlush(p); // // } else if (duplicates.size() > 1) { // System.out.println(); // System.out.println("MULIPLE DUPLICATED"); // // for (Person dd : duplicates) { // System.out.println(dd); // } // System.out.println("* " + p); // throw new RuntimeException(); // } else { // //// if (!duplicates.get(0).getDistrictOfBirth().equals(p.getDistrictOfBirth())) { //// int index = 0; //// //// System.out.println(); //// System.out.println("DUPLICATED"); //// //// for (Person dd : duplicates) { //// System.out.println(dd); //// index++; //// } //// System.out.println("* " + p); //// System.out.println(file.getAbsolutePath() + " " + p); //// //// System.out.println(); //// System.out.println(); //// } //// duplicates.remove(0); //// personRepository.deleteInBatch(duplicates); //// System.out.println(); //// System.out.println("Seleziona scelta"); //// Scanner s = new Scanner(System.in); //// int selected; //// try { //// selected = s.nextInt(); //// } catch (InputMismatchException e) { //// selected = 0; //// } //// //// if (duplicates.size() <= selected) { //// personRepository.deleteInBatch(duplicates); //// personRepository.saveAndFlush(p); //// } else { //// duplicates.remove(selected); //// personRepository.deleteInBatch(duplicates); //// } // } // // } catch (Exception e) { // // System.out.println(); //// System.out.println("ERROR READING lineCount=" + allLines.indexOf(line) + " line=" + line); //// System.out.println(file.getAbsolutePath()); // System.out.println(p); // e.printStackTrace(); // System.out.println(); // } // } // }); context.registerShutdownHook(); System.exit(0); }
From source file:Main.java
public static <T> Set<T> toSet(T element) { Set<T> set = new HashSet<T>(1); set.add(element); return set; }
From source file:Main.java
public static <T> Set<T> asSet(T... as) { Set<T> set = new HashSet<T>(as.length); for (T a : as) { set.add(a);//w w w . j av a2 s . co m } return set; }
From source file:Main.java
public static <T> Set<T> asSet(T... args) { Set<T> newSet = new HashSet<T>(args.length); for (T arg : args) { newSet.add(arg);//from w ww . j a v a 2 s . co m } return newSet; }
From source file:Main.java
public static List removeDuplicate(List list) { HashSet h = new HashSet(list); list.clear(); list.addAll(h); return list; }
From source file:Main.java
public static <V> Set<V> newHashSet(int expectedSize) { return new HashSet<V>(expectedSizeToCapacity(expectedSize)); }
From source file:Main.java
public static <T> Set<T> hashSet(T... a) { return new HashSet<T>(Arrays.asList(a)); }