Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1.     public static void main(String[] args) throws IOException, ClassNotFoundException {
  2.         if(args.length < 1) {
  3.             System.err.println("Használat:");
  4.             System.err.println("  java " + Ex1CreateIndex.class.getName() + " <index-file> <szavak>");
  5.             System.exit(-1);
  6.         }
  7.        
  8.         File indexFile = new File(args[0]);
  9.         Ex1CreateIndex idx = new Ex1CreateIndex(indexFile);
  10.        
  11.         Set<File> files = new HashSet<File>();
  12.        
  13.         for(int i = 0; i< args.length;i++) {
  14.             if(i == 0)
  15.                 continue;
  16.             String word = args[i];
  17.             Map<File, Integer> a = idx.getOccurences(word);
  18.             if(i == 1) {
  19.                 files.addAll(a.keySet());
  20.             } else {
  21.                 Set<File> ofiles = a.keySet();
  22.                 Set<File> delete = new HashSet<>();
  23.                
  24.                 for(File f : ofiles) {
  25.                     boolean found = false;
  26.                     for(File file2 : ofiles) {
  27.                         if(f.getAbsolutePath().equals(file2.getAbsolutePath())) {
  28.                             found = true;
  29.                             break;
  30.                         }
  31.                     }
  32.                     if(!found) {
  33.                         delete.add(f);
  34.                     }
  35.                 }
  36.                 files.removeAll(delete);
  37.             }
  38.             for(File file : files) {
  39.                 System.out.println(file.getAbsoluteFile());
  40.             }
  41.         }
  42.        
  43.         System.out.println("-----");
  44.        
  45.         for(int i = 0; i< args.length;i++) {
  46.             if(i == 0)
  47.                 continue;
  48.             String word = args[i];
  49.             Map<File, Integer> a = idx.getOccurences(word);
  50.             System.out.println(word + ": " + a.keySet());
  51.         }
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement