// prints to console based on if the model name is found public void printAuto(String modelName) { _autoModel = _autoModelGroup.get(modelName); if (_autoModel != null) { // using toStringWChoices to show optionChoice is functional System.out.println(_autoModel.toStringWChoices(true)); System.out.print("Price with selected options(may be defaults):"); System.out.println(_autoModel.getTotalPrice()); } else System.out.print("Model name" + modelName + "not found"); }
public void updateOptionSetName(String modelName, String optionSetName, String newName) { int setIndex; _autoModel = _autoModelGroup.get(modelName); if (_autoModel != null) { setIndex = _autoModel.findOptionSetIndex(optionSetName); if (setIndex != -1) { _autoModel.updateOptionSetName(setIndex, newName); } } }
// optionName goes with optionset, optVal is the String property in an option. public void updateOptionPrice( String modelName, String optionName, String optVal, float newprice) { int setIndex; _autoModel = _autoModelGroup.get(modelName); if (_autoModel != null) { setIndex = _autoModel.findOptionSetIndex(optionName); if (setIndex != -1) { _autoModel.updateOptionPrice(setIndex, optVal, newprice); } } }
// optionName goes with optionset, optVal is the String property in an option. public void updateOptionValue( String modelName, String optionName, String oldOptVal, String newOptVal) { int setIndex; _autoModel = _autoModelGroup.get(modelName); if (_autoModel != null) { setIndex = _autoModel.findOptionSetIndex(optionName); if (setIndex != -1) { if (_autoModel.updateOptionName(setIndex, oldOptVal, newOptVal)) System.out.println(newOptVal + " set!"); } } }
public Model buildAuto(String fileName, String fileType) { FileIO builder = new FileIO(); _autoModel = new Model(); if (fileType.indexOf("prop") > -1) { try { _autoModel = builder.buildAutoModelFromProperties(fileName, _autoModel); } catch (AutoException ae) { System.out.print(ae.getErrMessage()); } } else { try { _autoModel = builder.buildAutoModelObject(fileName, _autoModel); } catch (AutoException ae) { System.out.print(ae.getErrMessage()); try { _autoModel = builder.buildAutoModelObject(fileName, _autoModel); } catch (AutoException e) { System.out.print("Could not resolve error " + ae.getErrMessage()); } } } if (_autoModel != null) { _autoModel.setDefaultOptionChoices(); addAuto(_autoModel); } return _autoModel; }
public boolean buildAuto(Properties autoProp) { FileIO builder = new FileIO(); _autoModel = new Model(); try { builder.parseProperties(autoProp, _autoModel); } catch (AutoException e) { System.err.println(e.getMessage()); if (e.getErrCode() == 102065) // missing properties, don't continue with this file. _autoModel = null; } if (_autoModel != null) { _autoModel.setDefaultOptionChoices(); addAuto(_autoModel); return this.isAutoHere(_autoModel.getModelName()); } else return false; }
public void parseLine(Model automodel, String line) { String[] splitLine = line.split(","); trimWhiteSpaceInArray(splitLine); try { if (splitLine[0].compareToIgnoreCase("model") == 0) { automodel.setModelName(splitLine[1]); } else if (splitLine[0].compareToIgnoreCase("model price") == 0) { automodel.setModelPrice(Double.parseDouble(splitLine[1])); } else if (splitLine[0].compareToIgnoreCase("optionsets") == 0 || splitLine[0].compareToIgnoreCase("option sets") == 0) { try { automodel.initOptionSets(Integer.parseInt(splitLine[1])); } catch (Exception e) { // number not there or not an integer automodel.initOptionSets(DEFAULT_GROUP_SZ); System.out.println("Error with count of Option sets" + e.getMessage()); } } else if (splitLine[0].compareToIgnoreCase("optionset") == 0) { try { automodel.addOptionSet(splitLine[1], Integer.parseInt(splitLine[2])); } catch (Exception e) { // number not there or not an integer automodel.addOptionSet(splitLine[1], DEFAULT_GROUP_SZ); System.out.println("Error with count of options" + e.getMessage()); } } else if (splitLine[0].compareToIgnoreCase("option") == 0) { automodel.addOptionToLastSet(splitLine[1], Double.parseDouble(splitLine[2])); } } catch (Exception e) { System.out.println("Error parsing Model file." + e.getMessage()); } }
// a separate path with waits, just in case I forget to remove sleep() for the next lab. public void waitUpdateOptionValue( String modelName, String optionName, String oldOptVal, String newOptVal) { System.out.println( "Demonstrating Thread named " + Thread.currentThread().getName() + " and Setting " + oldOptVal + " to " + newOptVal); int setIndex; _autoModel = _autoModelGroup.get(modelName); if (_autoModel != null) { setIndex = _autoModel.findOptionSetIndex(optionName); if (setIndex != -1) { if (_autoModel.updateOptionName2(setIndex, oldOptVal, newOptVal)) { System.out.println(newOptVal + " set and updateOptionName2 exited."); } else { System.out.println(newOptVal + " NOT set but updateOptionName2 exited."); } } } System.out.println(Thread.currentThread().getName() + " done."); }
public void addAuto(Model autoModel) { if (!_autoModelGroup.containsKey(autoModel.getModelName())) { _autoModelGroup.put(autoModel.getModelName(), autoModel); } }
public void updateOptionChoice(String modelName, String optSetName, String optName) { _autoModel = _autoModelGroup.get(modelName); _autoModel.setOptionChoice(optSetName, optName); }