Exemple #1
0
 /** Main processing method for the RunProcess object */
 @Override
 public void run() {
   status = "running";
   try {
     // this.log("Command Start: "+command,3);
     // this.log("RunProcessInfo > " + this.toString(), 5);
     if (log.isDebugEnabled()) {
       log.debug("Parsing > " + this.dataParser.getFileName() + " ");
     }
     ReplaceVar replaceVar =
         new ReplaceVar(dataParser.getFileName(), dataParser.getNewFileName(), false);
     // First: append
     replaceVar.append(dataParser.getDataAppend());
     if (log.isDebugEnabled()) {
       log.debug("Append. > " + dataParser.getFileName() + "");
     }
     // Second: replace
     replaceVar.setSetting(dataParser.getDataReplace());
     if (log.isDebugEnabled()) {
       log.debug("Replace. > " + dataParser.getFileName() + "");
     }
     replaceVar.flush(); // This sould be handle in the component. REVIEW. TODO
     if (log.isDebugEnabled()) {
       log.debug("Finished Parsing > " + dataParser.getFileName() + "");
     }
     Thread.sleep(delay);
   } catch (Exception ex) {
     if (log.isErrorEnabled()) {
       log.error("Problem parsing > " + ex.getMessage() + "", ex);
     }
   }
   finish();
   try {
     if (dataParser.shouldDetach()) {
       detach();
     }
     if (dataParser.shouldTerminate()) {
       terminate();
     }
     if (log.isDebugEnabled()) {
       log.debug("Terminating > " + dataParser.getFileName() + "");
     }
   } catch (Exception e) {
     if (log.isErrorEnabled()) {
       log.error("Error during termination:" + e.getMessage() + "", e);
     }
   }
 }
Exemple #2
0
  /**
   * Loads the level collection stored in the passed file.
   *
   * @param collectionFilePath path and name of the collection to load
   * @return the <code>LevelCollection</code> created from the read in data
   * @throws IOException the collection file couldn't be read
   */
  public final LevelCollection getLevelCollectionFromFile(String collectionFilePath)
      throws IOException {

    // ArrayList, for storing the read data.
    List<String> inputData = new ArrayList<String>(1000);

    // Create BufferedReader for the input file.
    BufferedReader levelFile = Utilities.getBufferedReader(collectionFilePath);

    // The file hasn't been found => return null.
    if (levelFile == null) {
      throw new FileNotFoundException(Texts.getText("message.fileMissing", collectionFilePath));
    }

    // Read in line by line of the input data.
    String levelDataRow;
    try {
      while ((levelDataRow = levelFile.readLine()) != null) {
        inputData.add(levelDataRow);
      }
    } finally {
      levelFile.close();
    }

    // Parse the read data and return the collection created from that data.
    // The level collection to be returned.
    LevelCollection levelCollection = dataParser.extractData(inputData, collectionFilePath);

    // Return the collection.
    return levelCollection;
  }
Exemple #3
0
  /** Terminate */
  public void terminate() {
    if ((sfObj != null) && (sfObj instanceof PrimImpl)) {
      try {
        termR =
            TerminationRecord.normal(
                "ParserFile terminated (" + dataParser.getFileName() + ").", null);
        // Proper termination of a component!
        Runnable terminator =
            new Runnable() {
              public void run() {
                if (log.isDebugEnabled()) {
                  log.debug("ReplaceVar terminated.");
                }
                ((PrimImpl) sfObj).sfTerminate(termR);
              }
            };
        new Thread(terminator).start();

      } catch (Exception ex) {
        if (log.isErrorEnabled()) {
          log.error("Problem during termination > " + ex.getMessage() + "", ex);
        }
      }
      // this.log("ReplaceVar terminated.",2);
    } else {
      if (log.isDebugEnabled()) {
        log.debug("ReplaceVar: Wrong component to terminate.");
      }
    }
  }
Exemple #4
0
 public void assignPrerequisites() {
   for (int i = 0; i < 5; ++i) {
     if (recipe.startsWith("00")) {
       break;
     }
     String lookup = recipe.substring(0, 6);
     String recipePartId = lookup.substring(0, 4);
     int recipePartQuantity = Integer.valueOf(lookup.substring(5, 6));
     recipe = recipe.substring(6);
     Resource r = DataParser.findResource(recipePartId);
     if (r != null) {
       temporaryRecipe.add(new RecipePart(r, recipePartQuantity));
     } else {
       System.out.println(
           craftingResource.name()
               + " "
               + recipePartId
               + "Recipe part not found. Recipe will fail.");
     }
   }
 }
Exemple #5
0
  /**
   * Imports data from the passed Transferable-object and tries to extract level data from it.
   *
   * <p>This method is only used by the application.
   *
   * @param transferable the transferable object tried to extract level data from
   * @return the <code>LevelCollection</code> created from the read in data
   */
  public final LevelCollection getLevelCollectionFromStringDataFlavor(Transferable transferable) {

    // Level data from the clipboard.
    List<String> levelData = new ArrayList<String>();

    // Check if the stringFlavor is supported. If not, return an empty level collection.
    if (transferable == null
        || transferable.isDataFlavorSupported(DataFlavor.stringFlavor) == false) {
      return new LevelCollection.Builder().build();
    }

    try {
      String transferString = ((String) transferable.getTransferData(DataFlavor.stringFlavor));
      transferString = transferString.replaceAll("\\r\\n|\\r", "\n"); // Ensure there is only \n
      String[] levelDataString = transferString.split("\n");

      // The method "extractLevelData" needs the data to be in List (or any subtype).
      levelData.addAll(Arrays.asList(levelDataString));
    } catch (UnsupportedFlavorException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    //		if(Settings.isDebugModeActivated) {
    //			try {
    //				levelDataAsArrayList = FormatConverter.getXSBList(levelDataAsArrayList);
    //			} catch (ParseException e) {
    //				e.printStackTrace();
    //			}
    //		}

    // Extract the level data from the clipboard data and return the LevelCollection created from
    // that data.
    return dataParser.extractData(levelData, null);
  }
 public static void main(String[] args) throws Exception {
   SupermarketDataset dataset =
       DataParser.parseDataSetFile("/Users/smolcoder/study/ml/code/labs/data/supermarket.arff");
   AprioriAlgorithm apriori = new AprioriAlgorithm(dataset, 3, 30);
   apriori.buildAssociationRules();
 }
Exemple #7
0
 public void convertRecipe() {
   temporaryRecipe.forEach((p) -> craftingResource.addPrerequisite(p.resource(), p.quantity()));
   if (craftingResource.rarity().equals(DataParser.craftingRarities().get(0))) {
     craftingResource.unlock();
   }
 }
  /**
   * Entry point for program.
   *
   * @param args the user can provide a filename.txt to read/store banking info.
   */
  public static void main(String[] args) {
    theBank = null;
    try {
      try {
        in = new Scanner(System.in);

        // To be used for reading from and writing to file
        DataParser bankParser = new DataParser();

        String filename = null;
        String bankName = null;
        // Retrieve the filename from args if there is one supplied
        if (args.length > 0) {
          filename = args[0];
          // Reads in bank data from file
          bankParser.readData(filename);
          bankName = bankParser.getBankName();
          LinkedList<BankAccount> accounts = bankParser.getAccounts();
          LinkedList<BankCustomer> customers = bankParser.getCustomers();

          theBank = new Bank(bankName, accounts, customers);
        } else {
          // Asks user for bank name and filename
          System.out.println("Welcome! I'm a bank, but I forgot my name.");
          System.out.print("What's my name?: ");
          bankName = in.nextLine();

          boolean isValidFilename = false;
          while (!isValidFilename) {
            System.out.print(
                "Please provide a filename to store all banking data (filename.txt): ");
            filename = in.nextLine();

            // Checks that filename has extension txt
            String validFilename =
                ".+[.]txt"; // filename must contain at least 1 of any character followed by .txt
            if (filename.matches(validFilename)) {
              isValidFilename = true;
            }
          }
          theBank = new Bank(bankName);
        }

        System.out.println("\n\nWelcome to " + theBank.getName() + "!");

        // Displays a menu of available actions and asks user to choose an action
        boolean done = false;
        while (!done) {
          done = menu();
        }

        System.out.println("Have a splendid day!");

        // Write all banking data to file
        bankParser.writeData(
            filename,
            theBank.getName(),
            theBank.getTotalBalance(),
            theBank.getAllAccounts(),
            theBank.getAllCustomers());

      } finally {
        if (in != null) {
          in.close();
        }
      }
    } catch (FileNotFoundException e) {
      System.out.println("\nThe bank data file was not found.");
    } catch (BadDataException e) {
      System.out.println("\nThe data provided in the file is corrupt.");
    }
  }