I have an inventory management system that reads in .txt files of Items and Stores and a bridge entity called Stocks and outputs a .txt file which displays the info based on those three files.
Here it is at the bottom.
public class Ims {
private static Logger LOG = Logger.getLogger(Ims.class);
public static void main(String[] args) throws Exception {
PropertyConfigurator.configure("log.properties");
LOG.debug("main()");
File itemsFile = new File("items.txt");
File storesFile = new File("stores.txt");
File stockFile = new File("stocks.txt");
if (!itemsFile.exists()) {
LOG.error("Required 'items.txt' is missing");
} else if (!storesFile.exists()) {
LOG.error("Required 'stores.txt' is missing");
}
new Ims(itemsFile, storesFile, stockFile);
}
public Ims(File itemsFile, File storesFile, File stockFile) {
LOG.debug("Ims()");
HashMap<String, Item> items = null;
HashMap<String, Store> stores = null;
List<Stock> stocks = null;
try {
items = InventoryReader.read(itemsFile);
stores = StoresReader.read(storesFile);
stocks = StockReader.read(stockFile);
} catch (ApplicationException e) {
LOG.error(e.getMessage());
return;
}
// Collections.sort(items, new CompareByPrice()); <-- this should sort it. How do I do this as a command line argument?
File inventory = new File("inventory.txt");
PrintStream out = null;
try {
out = new PrintStream(new FileOutputStream(inventory));
InventoryReport.write(items, stores, stocks, out);
} catch (FileNotFoundException e) {
LOG.error(e.getMessage());
}
}
}
I want to be able to sort the read in arguments a number of ways using command line arguments.
For example:
java –jar Ims.jar by_value desc total
How would I do this?