私は、Items と Stores の .txt ファイルと Stocks と呼ばれるブリッジ エンティティを読み取り、これら 3 つのファイルに基づいて情報を表示する .txt ファイルを出力する在庫管理システムを持っています。
こちらが一番下です。
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());
        }
    }
}
コマンドライン引数を使用して、さまざまな方法で引数の読み取りをソートできるようにしたいと考えています。
例えば:
java –jar Ims.jar by_value desc total
どうすればいいですか?